--- loncom/homework/grades.pm 2007/08/21 18:48:18 1.431
+++ loncom/homework/grades.pm 2007/08/24 00:32:00 1.434
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.431 2007/08/21 18:48:18 banghart Exp $
+# $Id: grades.pm,v 1.434 2007/08/24 00:32:00 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -45,7 +45,7 @@ use LONCAPA;
use POSIX qw(floor);
-my %perm=();
+my %perm;
# ----- These first few routines are general use routines.----
#
@@ -194,22 +194,54 @@ sub showResourceInfo {
return $result,$responseType,$hdgrade,$partlist,$handgrade;
}
+sub reset_caches {
+ &reset_analyze_cache();
+ &reset_perm();
+}
-sub get_order {
- my ($partid,$respid,$symb,$uname,$udom)=@_;
- my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
- $url=&Apache::lonnet::clutter($url);
- my $subresult=&Apache::lonnet::ssi($url,
- ('grade_target' => 'analyze'),
- ('grade_domain' => $udom),
- ('grade_symb' => $symb),
- ('grade_courseid' =>
- $env{'request.course.id'}),
- ('grade_username' => $uname));
- (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
- my %analyze=&Apache::lonnet::str2hash($subresult);
- return ($analyze{"$partid.$respid.shown"});
+{
+ my %analyze_cache;
+
+ sub reset_analyze_cache {
+ undef(%analyze_cache);
+ }
+
+ sub get_analyze {
+ my ($symb,$uname,$udom)=@_;
+ my $key = "$symb\0$uname\0$udom";
+ return $analyze_cache{$key} if (exists($analyze_cache{$key}));
+
+ my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
+ $url=&Apache::lonnet::clutter($url);
+ my $subresult=&Apache::lonnet::ssi($url,
+ ('grade_target' => 'analyze'),
+ ('grade_domain' => $udom),
+ ('grade_symb' => $symb),
+ ('grade_courseid' =>
+ $env{'request.course.id'}),
+ ('grade_username' => $uname));
+ (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
+ my %analyze=&Apache::lonnet::str2hash($subresult);
+ return $analyze_cache{$key} = \%analyze;
+ }
+
+ sub get_order {
+ my ($partid,$respid,$symb,$uname,$udom)=@_;
+ my $analyze = &get_analyze($symb,$uname,$udom);
+ return $analyze->{"$partid.$respid.shown"};
+ }
+
+ sub get_radiobutton_correct_foil {
+ my ($partid,$respid,$symb,$uname,$udom)=@_;
+ my $analyze = &get_analyze($symb,$uname,$udom);
+ foreach my $foil (@{&get_order($partid,$respid,$symb,$uname,$udom)}) {
+ if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
+ return $foil;
+ }
+ }
+ }
}
+
#--- Clean response type for display
#--- Currently filters option/rank/radiobutton/match/essay/Task
# response types only.
@@ -258,11 +290,11 @@ sub cleanRecord {
} elsif ($response eq 'radiobutton') {
my %answer=&Apache::lonnet::str2hash($answer);
my ($toprow,$bottomrow);
- my $correct=($order->[0])+1;
- for (my $i=1;$i<=$#$order;$i++) {
- my $foil=$order->[$i];
+ my $correct =
+ &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom);
+ foreach my $foil (@$order) {
if (exists($answer{$foil})) {
- if ($i == $correct) {
+ if ($foil eq $correct) {
$toprow.='
true | ';
} else {
$toprow.='true | ';
@@ -723,7 +755,6 @@ LISTJAVASCRIPT
my $saveStatus = $env{'form.Status'} eq '' ? 'Active' : $env{'form.Status'};
$env{'form.Status'} = $saveStatus;
-
$gradeTable.=''."\n".
''."\n".
''."\n".
@@ -734,8 +765,7 @@ LISTJAVASCRIPT
''.
''.
''.
-
- ''."\n".
+ &build_section_inputs().
''."\n".
'
'."\n".
'
'."\n".
@@ -1661,6 +1691,19 @@ sub download_all_link {
return
}
+sub build_section_inputs {
+ my $section_inputs;
+ if ($env{'form.section'} eq '') {
+ $section_inputs .= ''."\n";
+ } else {
+ my @sections = &Apache::loncommon::get_env_multiple('form.section');
+ foreach my $section (@sections) {
+ $section_inputs .= ''."\n";
+ }
+ }
+ return $section_inputs;
+}
+
# --------------------------- show submissions of a student, option to grade
sub submission {
my ($request,$counter,$total) = @_;
@@ -1741,7 +1784,6 @@ sub submission {
$env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
}
my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
-
$request->print(''."\n";
if (scalar(%$fullname) eq 0) {
my $colspan=3+scalar(@parts);
- $result='There are no students in section "'.$env{'form.section'}.
- '" with enrollment status "'.$env{'form.Status'}.'" to modify or grade.';
+ my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
+ $result=''.
+ &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade',
+ $section_display, $env{'form.Status'}).
+ '';
}
$result.=&show_grading_menu_form($symb);
return $result;
@@ -3163,9 +3208,10 @@ sub editgrades {
my ($request) = @_;
my $symb=&get_symb($request);
- my $title='Current Grade Status
';
- $title.='Current Resource: '.$env{'form.probTitle'}.'
'."\n";
- $title.='Section: '.$env{'form.section'}.'
'."\n";
+ my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
+ my $title=''.&mt('Current Grade Status').'
';
+ $title.=''.&mt('Current Resource: [_1]',$env{'form.probTitle'}).'
'."\n";
+ $title.=''.&mt('Section: [_1]',$section_display).'
'."\n";
my $result= ''."\n";
$result.= ''.
@@ -3866,9 +3912,9 @@ LISTJAVASCRIPT
''."\n".
''."\n".
''."\n";
-
- $result.=''."\n".
- ''."\n".
+
+ $result.=&build_section_inputs();
+ $result.=''."\n".
''."\n".
''."\n".
''." \n";
@@ -7501,7 +7547,7 @@ ENDHEADER
sub handler {
my $request=$_[0];
- &reset_perm();
+ &reset_caches();
if ($env{'browser.mathml'}) {
&Apache::loncommon::content_type($request,'text/xml');
} else {
@@ -7545,10 +7591,6 @@ sub handler {
}
} else {
&init_perm();
-# &Apache::lonnet::logthis("command is $command");
-# foreach my $key (keys %perm) {
-# &Apache::lonnet::logthis("a key is $key");
-# }
if ($command eq 'submission' && $perm{'vgr'}) {
($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
} elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
@@ -7618,6 +7660,7 @@ sub handler {
}
}
$request->print(&Apache::loncommon::end_page());
+ &reset_caches();
return '';
}
|