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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 19 May 2005 21:22:45 -0000


This is a MIME encoded message

--albertel1116537765
Content-Type: text/plain

albertel		Thu May 19 17:22:45 2005 EDT

  Modified files:              
    /loncom/homework	bridgetask.pm 
  Log:
  - 'versioning' the stored data
  
  
--albertel1116537765
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20050519172245.txt"

Index: loncom/homework/bridgetask.pm
diff -u loncom/homework/bridgetask.pm:1.24 loncom/homework/bridgetask.pm:1.25
--- loncom/homework/bridgetask.pm:1.24	Fri May 13 11:34:50 2005
+++ loncom/homework/bridgetask.pm	Thu May 19 17:22:44 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: bridgetask.pm,v 1.24 2005/05/13 15:34:50 albertel Exp $
+# $Id: bridgetask.pm,v 1.25 2005/05/19 21:22:44 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -83,8 +83,25 @@
     return 0;
 }
 
+sub get_version {
+    if ($env{'form.previousversion'} && 
+	defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.status'})) {
+	return $env{'form.previousversion'};
+    }
+    return $Apache::lonhomework::history{'resource.version'};
+}
+
 sub add_previous_version_button {
+    my ($status)=@_;
     my $result;
+    if ($Apache::lonhomework::history{'resource.version'} eq '0') {
+	return '';
+    }
+    my $version=&get_version();
+    if ($version ne $Apache::lonhomework::history{'resource.version'}) {
+	return '';
+    }
+
     $result.=&mt(' Show a previously done version: [_1]','<select name="previousversion">
 <option>Pick one</option>
 </select>');
@@ -100,7 +117,10 @@
 }
 
 sub add_request_another_attempt_button {
-    
+    my $result;
+    $result.=' <input type="submit" name="requestattempt" value="'.
+	&mt("Request another attempt").'" />';
+    return $result;
 }
 
 sub start_Task {
@@ -118,7 +138,6 @@
 	&Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
     
     if ($target eq 'web') {
-	$body_tag_start.=&add_previous_version_button();
 	if ($Apache::lonhomework::modifygrades) {
 	    $body_tag_start.='<form name="gradesubmission" method="POST" action="';
 	    my $uri=$env{'request.uri'};
@@ -128,7 +147,7 @@
     }
     if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
 	$target eq 'tex') {
-	my $version=$Apache::lonhomework::history{'resource.version'};
+	my $version=&get_version();
 	($status,$accessmsg,my $slot_name,$slot) = 
 	    &Apache::lonhomework::check_task_access('0');
 	push(@Apache::inputtags::status,$status);
@@ -137,6 +156,7 @@
 	$expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.solved"}.'";';
 	&Apache::run::run($expression,$safeeval);
 	&Apache::lonxml::debug("Got $status");
+	$body_tag_start.=&add_previous_version_button($status);
 	if (( $status eq 'CLOSED' ) ||
 	    ( $status eq 'BANNED') ||
 	    ( $status eq 'UNAVAILABLE') ||
@@ -195,11 +215,12 @@
 			'" value="'.$env{"form.grade_$field"}.'" />'."\n";
 		}
 	    }
-	    if ($Apache::lonhomework::history{'resource.status'} eq 'fail') {
+	    my $version=&get_version();
+	    if ($Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
 		$result.='<h1><font color="red">'.&mt('Did not pass').'</font></h1>';
-		$result.=&request_another_attempt_button();
+		$result.=&add_request_another_attempt_button();
 	    }
-	    if ($Apache::lonhomework::history{'resource.status'} eq 'pass') {
+	    if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass') {
 		$result.='<h1><font color="green">'.&mt('Passed').'</font></h1>';
 	    }
 	}
@@ -240,7 +261,7 @@
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my $result='';
     my $status=$Apache::inputtags::status['-1'];
-    my $version=$Apache::lonhomework::history{'resource.version'};
+    my $version=&get_version();
     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
 	$target eq 'tex') {
 	if (
@@ -288,7 +309,7 @@
 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
 	    foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
 		my $status=
-		    $Apache::lonhomework::results{"resource.$dim_id.status"};
+		    $Apache::lonhomework::results{"resource.$version.$dim_id.status"};
 		my $mandatory=
 		    ($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
 		if ($status eq 'pass') {
@@ -308,20 +329,34 @@
 	    $Apache::lonhomework::results{'resource.grader'}=
 		$env{'user.name'}.'@'.$env{'user.domain'};
 	    if ($review) {
-		$Apache::lonhomework::results{'resource.status'}='review';
+		$Apache::lonhomework::results{"resource.$version.status"}='review';
 		&move_to_review_queue();
 	    } elsif ($ungraded) {
-		$Apache::lonhomework::results{'resource.status'}='ungraded';
+		$Apache::lonhomework::results{"resource.$version.status"}='ungraded';
 		&check_queue_unlock();
 	    } elsif ($mandatory_failed) {
-		$Apache::lonhomework::results{'resource.status'}='fail';
-		$Apache::lonhomework::results{"resource.$version.award"}='EXACT_ANS';
+		$Apache::lonhomework::results{"resource.$version.status"}='fail';
+		$Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
+		$Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
+		$Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
 		&remove_from_queue();
 	    } else {
-		$Apache::lonhomework::results{'resource.status'}='pass';
-		$Apache::lonhomework::results{"resource.$version.award"}='INCORRECT';
+		$Apache::lonhomework::results{"resource.$version.status"}='pass';
+		$Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
+		$Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
+		$Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
 		&remove_from_queue();
 	    }
+	    $Apache::lonhomework::results{'resource.status'}=
+		$Apache::lonhomework::results{'resource.$version.status'};
+	    if (defined($Apache::lonhomework::results{'resource.$version.awarded'})) {
+		$Apache::lonhomework::results{'resource.0.award'}=
+		    $Apache::lonhomework::results{'resource.$version.award'};
+		$Apache::lonhomework::results{'resource.0.awarded'}=
+		    $Apache::lonhomework::results{'resource.$version.awarded'};
+		$Apache::lonhomework::results{'resource.0.solved'}=
+		    $Apache::lonhomework::results{'resource.$version.solved'};
+	    }
 	    &Apache::structuretags::finalize_storage();
 	}
     } elsif ($target eq 'webgrade') {
@@ -598,15 +633,16 @@
     sub end_Dimension {
 	my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 	my $result;
-	my $dim_id=&get_id($parstack,$safeeval);
+	my $dim=&get_id($parstack,$safeeval);
 	my $instance=&get_instance();
+	my $version=&get_version();
 	if ($target eq 'web') {
 	    $result=$dimension{'intro'}.$dimension{$instance.'.text'};
-	    if ($Apache::lonhomework::history{'resource.status'} eq 'pass' ||
-		$Apache::lonhomework::history{'resource.status'} eq 'fail') {
+	    if ($Apache::lonhomework::history{'resource.$version.status'} eq 'pass' ||
+		$Apache::lonhomework::history{'resource.$version.status'} eq 'fail') {
 		foreach my $id (@{$dimension{$instance.'.criterias'}}) {
-		    my $status=$Apache::lonhomework::history{"resource.$dim_id.$instance.$id.status"};
-		    my $comment=$Apache::lonhomework::history{"resource.$dim_id.$instance.$id.comment"};
+		    my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
+		    my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"};
 		    $result.='<table border="1"><tr><td>';
 		    if ($status eq 'fail') {
 			$result.='<font color="red">'.&mt('Did not pass').'</font>';
@@ -616,18 +652,17 @@
 			&Apache::lonxml::error("Student viewing a graded bridgetask was show a status of $status");
 		    }
 		    $result.='</td></tr><tr><td>';
-		    if ($Apache::lonhomework::history{"resource.$dim_id.$instance.$id.comment"}) {
-			$result.=&mt('Comment from grader: ').$Apache::lonhomework::history{"resource.$dim_id.$instance.$id.comment"}.'</td></tr><tr><td>';
+		    if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) {
+			$result.=&mt('Comment from grader: ').$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}.'</td></tr><tr><td>';
 		    }
 		    $result.=$dimension{$instance.'.criteria.'.$id}.
 			'</td></tr></table>';
 		}
 	    }
 	} elsif ($target eq 'webgrade') {
-	    my $version=$Apache::lonhomework::history{'resource.version'};
 	    foreach my $id (@{$dimension{$instance.'.criterias'}}) {
 		my $link='criteria_'.$instance.'_'.$id;
-		my $status=$Apache::lonhomework::history{"resource.$dim_id.$instance.$id.status"};
+		my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
 		$result.='<tr><td width="100%" valign="top">'.
 		    '<a name="'.$link.'" />'.
 		    '<a name="next_'.$last_link.'" />'.
@@ -635,7 +670,7 @@
 		    #$dimension{$instance.'.criteria.'.$id}.
 		    '</td>'.
 		    '<td><nobr>Additional Comment for Student</nobr> <br />'.
-		    '<textarea style="width:100%" rows="8" width="25" wrap="hard" name="HWVAL_comment_'.$link.'">'.&HTML::Entities::encode($Apache::lonhomework::history{"resource.$dim_id.$instance.$id.comment"}).'</textarea>'.
+		    '<textarea style="width:100%" rows="8" width="25" wrap="hard" name="HWVAL_comment_'.$link.'">'.&HTML::Entities::encode($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}).'</textarea>'.
 		    '</td>'.
 		    '<td>'.
 		    '<nobr><label><input type="radio" name="HWVAL_'.$link.'" value="ungraded" '.($status eq 'ungraded' || !$status ? 'checked="checked"':'').'/>Ungraded</label></nobr><br />'.
@@ -668,8 +703,8 @@
 	    my $ungraded=0;
 	    my $review=0;
 	    foreach my $id (@{$dimension{$instance.'.criterias'}}) {
-		my $status=$Apache::lonhomework::results{"resource.$dim_id.$instance.$id.status"}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id};
-		$Apache::lonhomework::results{"resource.$dim_id.$instance.$id.comment"}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id};
+		my $status=$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.status"}=$env{'form.HWVAL_criteria_'.$instance.'_'.$id};
+		$Apache::lonhomework::results{"resource.$version.$dim.$instance.$id.comment"}=$env{'form.HWVAL_comment_criteria_'.$instance.'_'.$id};
 		my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
 		if ($status eq 'pass') {
 		    if (!$mandatory) { $optional_passed++; }
@@ -688,16 +723,16 @@
 	    }
 	    &Apache::lonxml::debug("all instance ".join(':',@{$dimension{$instance.'.criterias'}})." results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
 	    if ($review) {
-		$Apache::lonhomework::results{"resource.$dim_id.status"}=
+		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
 		    'review';
 	    } elsif ($ungraded) {
-		$Apache::lonhomework::results{"resource.$dim_id.status"}=
+		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
 		    'ungraded';
 	    } elsif ($mandatory_failed) {
-		$Apache::lonhomework::results{"resource.$dim_id.status"}=
+		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
 		    'fail';
 	    } else {
-		$Apache::lonhomework::results{"resource.$dim_id.status"}=
+		$Apache::lonhomework::results{"resource.$version.$dim.status"}=
 		    'pass';
 	    }
 	}

--albertel1116537765--