[LON-CAPA-cvs] cvs: loncom /homework grades.pm

banghart lon-capa-cvs@mail.lon-capa.org
Fri, 01 Apr 2005 23:56:54 -0000


banghart		Fri Apr  1 18:56:54 2005 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  	Logic for creating version number, and building file name.
  	Remains to create the file.
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.251 loncom/homework/grades.pm:1.252
--- loncom/homework/grades.pm:1.251	Wed Mar 30 16:11:44 2005
+++ loncom/homework/grades.pm	Fri Apr  1 18:56:52 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.251 2005/03/30 21:11:44 banghart Exp $
+# $Id: grades.pm,v 1.252 2005/04/01 23:56:52 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2184,8 +2184,39 @@
 sub version_portfiles {
     my ($record, $parts_graded, $courseid, $symb, $domain, $stuname) = @_;
     my $parts = join '|', @$parts_graded;
-    foreach my $key (sort keys %$record) {
+    my $portfolio_root = &Apache::loncommon::propath($domain,
+						 $stuname).
+						'/userfiles/portfolio';
+    foreach my $key (keys %$record) {
         if ($key =~ /^resource\.($parts)\./ && $key =~ /\.portfiles$/) {
+            my @portfiles = split /,/,$$record{$key};
+            foreach my $file (@portfiles) {
+                $file =~ /^(.*?)([^\/]*$)/;
+                my $directory = $1;
+                my $version = 0;
+                my $answer_file = $2;
+                my @answer_file_parts = split /\./, $answer_file;
+                my @dir_list = &Apache::lonnet::dirlist($directory,$domain,$stuname,$portfolio_root);
+                my @file_names;
+                my @file_name_parts;
+                foreach ( @dir_list) {
+                    @file_names = split /\&/,$_,2;
+                    @file_name_parts = split /\./, $file_names[0];
+                    # ($file_name_parts[scalar @file_name_parts] eq $answer_file_parts[scalar @answer_file_parts])
+                    if (($file_name_parts[0] eq $answer_file_parts[0]) && 
+                        ($file_name_parts[(scalar @file_name_parts)-1] eq $answer_file_parts[(scalar @answer_file_parts)-1])) {
+                        # gets here if filename and extension match, regardless of version
+                        if (scalar @file_name_parts == 3) { # a versioned file is found
+                            # so save it for later
+                            if ($file_name_parts[1] > $version) {$version = $file_name_parts[1]};
+                        }
+                    }
+                }
+                $version += 1;
+                &Apache::lonnet::logthis('answer file is '.$answer_file.
+                        ' becomes '.$answer_file_parts[0].'.'.$version.'.'.$answer_file_parts[(scalar @answer_file_parts)-1]);
+                &Apache::lonnet::logthis('from dir list is '.$file_names[0].' has '.@file_name_parts.' parts');
+            }
             &Apache::lonnet::logthis('found key portfiles '.$key);
             &Apache::lonnet::logthis('found value portfiles '.$$record{$key});
         }