--- loncom/homework/grades.pm 2005/02/28 21:18:08 1.249
+++ loncom/homework/grades.pm 2005/04/02 02:22:10 1.253
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.249 2005/02/28 21:18:08 albertel Exp $
+# $Id: grades.pm,v 1.253 2005/04/02 02:22:10 banghart Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -96,7 +96,7 @@ sub get_symb_and_url {
sub nameUserString {
my ($type,$fullname,$uname,$udom) = @_;
if ($type eq 'header') {
- return ' Fullname (Username) Section/Group';
+ return ' Fullname (Username)';
} else {
return ' '.$fullname.' ('.$uname.
($ENV{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')';
@@ -678,7 +678,7 @@ LISTJAVASCRIPT
my $loop = 0;
while ($loop < 2) {
$gradeTable.='
No. | Select | '.
- ''.&nameUserString('header').' | ';
+ ''.&nameUserString('header').' Section/Group | ';
if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
foreach (sort(@$partlist)) {
my $display_part=&get_display_part((split(/_/))[0],$url,$symb);
@@ -2113,6 +2113,7 @@ sub saveHandGrade {
$ENV{'request.course.id'});
if (!&canmodify($usec)) { return('not_allowed'); }
my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
+ my @parts_graded;
my %newrecord = ();
my ($pts,$wgt) = ('','');
foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
@@ -2147,6 +2148,8 @@ sub saveHandGrade {
if ($partial eq $record{'resource.'.$_.'.awarded'}) {
#do not update score for part if not changed.
next;
+ } else {
+ push @parts_graded, $_;
}
if ($record{'resource.'.$_.'.awarded'} ne $partial) {
$newrecord{'resource.'.$_.'.awarded'} = $partial;
@@ -2170,12 +2173,58 @@ sub saveHandGrade {
}
}
if (scalar(keys(%newrecord)) > 0) {
+ &version_portfiles(\%record, \@parts_graded, $ENV{'request.course.id'}, $symb, $domain, $stuname);
&Apache::lonnet::cstore(\%newrecord,$symb,
$ENV{'request.course.id'},$domain,$stuname);
}
return '',$pts,$wgt;
}
+# ----------- Handles creating versions for portfolio files as answers
+sub version_portfiles {
+ my ($record, $parts_graded, $courseid, $symb, $domain, $stuname) = @_;
+ my $parts = join '|', @$parts_graded;
+ 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 my $row (@dir_list) {
+ @file_names = split (/\&/,$row,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[-1] eq $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});
+ }
+ }
+
+
+}
+
#--------------------------------------------------------------------------------------
#
#-------------------------- Next few routines handles grading by section or whole class