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

raeburn raeburn at source.lon-capa.org
Fri Dec 17 10:22:13 EST 2021


raeburn		Fri Dec 17 15:22:13 2021 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/homework	grades.pm 
  Log:
  - For 2.11
    Backport 1.785, 1.786
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.596.2.12.2.57 loncom/homework/grades.pm:1.596.2.12.2.58
--- loncom/homework/grades.pm:1.596.2.12.2.57	Mon Jan 25 14:25:55 2021
+++ loncom/homework/grades.pm	Fri Dec 17 15:22:13 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.596.2.12.2.57 2021/01/25 14:25:55 raeburn Exp $
+# $Id: grades.pm,v 1.596.2.12.2.58 2021/12/17 15:22:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3131,13 +3131,31 @@
     my $ntstu  = $env{'form.NTSTU'};
     my $cdom   = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $cnum   = $env{'course.'.$env{'request.course.id'}.'.num'};
+    my ($res_error,%queueable);
+    my ($partlist,$handgrade,$responseType,$numresp,$numessay) = &response_type($symb,\$res_error);
+    if ($res_error) {
+        $request->print(&navmap_errormsg());
+        return;
+    } else {
+        foreach my $part (@{$partlist}) {
+            if (ref($responseType->{$part}) eq 'HASH') {
+                foreach my $id (keys(%{$responseType->{$part}})) {
+                    if (($responseType->{$part}->{$id} eq 'essay') ||
+                        (lc($handgrade->{$part.'_'.$id}) eq 'yes')) {
+                        $queueable{$part} = 1;
+                        last;
+                    }
+                }
+            }
+        }
+    }
 
     if ($button eq 'Save & Next') {
 	my $ctr = 0;
 	while ($ctr < $ngrade) {
 	    my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
 	    my ($errorflag,$pts,$wgt,$numhidden) = 
-                &saveHandGrade($request,$symb,$uname,$udom,$ctr);
+                &saveHandGrade($request,$symb,$uname,$udom,$ctr,undef,undef,\%queueable);
 	    if ($errorflag eq 'no_score') {
 		$ctr++;
 		next;
@@ -3192,7 +3210,7 @@
 		    foreach my $collaborator (@collaborators) {
 			my ($errorflag,$pts,$wgt) = 
 			    &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
-					   $env{'form.unamedom'.$ctr},$part);
+					   $env{'form.unamedom'.$ctr},$part,\%queueable);
 			if ($errorflag eq 'not_allowed') {
 			    $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
 			    next;
@@ -3214,13 +3232,6 @@
 	}
     }
 
-    my $res_error;
-    my ($partlist,$handgrade,$responseType,$numresp,$numessay) = &response_type($symb,\$res_error);
-    if ($res_error) {
-        $request->print(&navmap_errormsg());
-        return;
-    }
-
     my %keyhash = ();
     if ($numessay) {
 	# Keywords sorted in alphabatical order
@@ -3372,7 +3383,7 @@
 
 #---- Save the score and award for each student, if changed
 sub saveHandGrade {
-    my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
+    my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part,$queueable) = @_;
     my @version_parts;
     my $usec = &Apache::lonnet::getsection($domain,$stuname,
 					   $env{'request.course.id'});
@@ -3484,7 +3495,7 @@
 	&Apache::lonnet::cstore(\%newrecord,$symb,
 				$env{'request.course.id'},$domain,$stuname);
 	&check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
-				     $cdom,$cnum,$domain,$stuname);
+				     $cdom,$cnum,$domain,$stuname,$queueable);
     }
     if ($aggregateflag) {
         &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
@@ -3524,7 +3535,7 @@
 }
 
 sub check_and_remove_from_queue {
-    my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
+    my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname,$queueable) = @_;
     my @ungraded_parts;
     foreach my $part (@{$parts}) {
 	if (    $record->{   'resource.'.$part.'.awarded'} eq ''
@@ -3532,7 +3543,9 @@
 	     && $newrecord->{'resource.'.$part.'.awarded'} eq ''
 	     && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
 		) {
-	    push(@ungraded_parts, $part);
+            if ($queueable->{$part}) {
+	        push(@ungraded_parts, $part);
+            }
 	}
     }
     if ( !@ungraded_parts ) {
@@ -4474,6 +4487,7 @@
 	&Apache::loncommon::end_data_table_header_row();
     my @noupdate;
     my ($updateCtr,$noupdateCtr) = (1,1);
+    my ($got_types,%queueable);
     for ($i=0; $i<$env{'form.total'}; $i++) {
 	my $user = $env{'form.ctr'.$i};
 	my ($uname,$udom)=split(/:/,$user);
@@ -4573,12 +4587,32 @@
 					     $udom,$uname);
 		my $all_graded = 1;
 		my $none_graded = 1;
+                unless ($got_types) {
+                    my $error;
+                    my ($plist,$handgrd,$resptype) = &response_type($symb,\$error);
+                    unless ($error) {
+                        foreach my $part (@parts) {
+                            if (ref($resptype->{$part}) eq 'HASH') {
+                                foreach my $id (keys(%{$resptype->{$part}})) {
+                                    if (($resptype->{$part}->{$id} eq 'essay') ||
+                                        (lc($handgrd->{$part.'_'.$id}) eq 'yes')) {
+                                        $queueable{$part} = 1;
+                                        last;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    $got_types = 1;
+                }
 		foreach my $part (@parts) {
-		    if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
-			$all_graded = 0;
-		    } else {
-			$none_graded = 0;
-		    }
+                    if ($queueable{$part}) {
+		        if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
+			    $all_graded = 0;
+		        } else {
+			    $none_graded = 0;
+		        }
+                    }
 		}
 
 		if ($all_graded || $none_graded) {
@@ -5644,7 +5678,20 @@
 	    foreach my $partid (@{$parts}) {
 		my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
 		my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
-
+                my @types = $curRes->responseType($part);
+                if (grep(/^essay$/, at types)) {
+                    $queueable{$partid} = 1;
+                } else {
+                    my @ids = $curRes->responseIds($part);
+                    for (my $i=0; $i < scalar(@ids); $i++) {
+                        my $hndgrd = &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
+                                                          '.handgrade',$symb);
+                        if (lc($hndgrd) eq 'yes') {
+                            $queueable{$partid} = 1;
+                            last;
+                        }
+                    }
+                }
 		my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ? 
 		    $env{'form.WGT'.$question.'_'.$partid} : 1;
 		my $partial = $newpts/$wgt;
@@ -5710,7 +5757,7 @@
 						   $env{'request.course.id'},
 						   $udom,$uname);
 		&check_and_remove_from_queue($parts,\%record,undef,$symbx,
-					     $cdom,$cnum,$udom,$uname);
+					     $cdom,$cnum,$udom,$uname,\%queueable);
 	    }
 	    
             if ($aggregateflag) {
@@ -10861,7 +10908,9 @@
         $args{'only_body'} = 1;
         $r->print(&Apache::loncommon::start_page("Student's Version",$head_extra,\%args));
     } else {
-        unshift(@$crumbs,{href=>&href_symb_cmd($symb,'gradingmenu'),text=>"Grading"});
+        if ($env{'request.course.id'}) {
+            unshift(@$crumbs,{href=>&href_symb_cmd($symb,'gradingmenu'),text=>"Grading"});
+        }
         $args{'bread_crumbs'} = $crumbs;
         $r->print(&Apache::loncommon::start_page('Grading',$head_extra,\%args));
     }




More information about the LON-CAPA-cvs mailing list