[LON-CAPA-cvs] cvs: loncom /homework grades.pm
banghart
lon-capa-cvs@mail.lon-capa.org
Fri, 27 Jan 2006 23:53:15 -0000
banghart Fri Jan 27 18:53:15 2006 EDT
Modified files:
/loncom/homework grades.pm
Log:
Continue refactoring version_portfiles. New sub get_next_version.
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.306 loncom/homework/grades.pm:1.307
--- loncom/homework/grades.pm:1.306 Thu Jan 26 20:52:25 2006
+++ loncom/homework/grades.pm Fri Jan 27 18:53:11 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.306 2006/01/27 01:52:25 banghart Exp $
+# $Id: grades.pm,v 1.307 2006/01/27 23:53:11 banghart Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2418,22 +2418,7 @@
my ($answer_name,$answer_ver,$answer_ext) =
&file_name_version_ext($answer_file);
my @dir_list = &Apache::lonnet::dirlist($directory,$domain,$stu_name,$portfolio_root);
- foreach my $row (@dir_list) {
- my ($file) = split(/\&/,$row,2);
- my ($file_name,$file_version,$file_ext) =
- &file_name_version_ext($file);
- if (($file_name eq $answer_name) &&
- ($file_ext eq $answer_ext)) {
- # gets here if filename and extension match, regardless of version
- if ($file_version ne '') {
- # a versioned file is found so save it for later
- if ($file_version > $version) {
- $version = $file_version;
- }
- }
- }
- }
- $version++;
+ $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
if ($new_answer ne 'problem getting file') {
push(@v_portfiles, $directory.$new_answer);
@@ -2449,6 +2434,28 @@
return 'ok';
}
+sub get_next_version {
+ my ($answer_name, $answer_ext, $dir_list);
+ my $version;
+ foreach my $row (@$dir_list) {
+ my ($file) = split(/\&/,$row,2);
+ my ($file_name,$file_version,$file_ext) =
+ &file_name_version_ext($file);
+ if (($file_name eq $answer_name) &&
+ ($file_ext eq $answer_ext)) {
+ # gets here if filename and extension match, regardless of version
+ if ($file_version ne '') {
+ # a versioned file is found so save it for later
+ if ($file_version > $version) {
+ $version = $file_version;
+ }
+ }
+ }
+ }
+ $version ++;
+ return($version);
+}
+
sub version_selected_portfile {
my ($domain,$stu_name,$directory,$file_name,$version) = @_;
my ($answer_name,$answer_ver,$answer_ext) =