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

raeburn raeburn@source.lon-capa.org
Sun, 19 Dec 2010 00:48:50 -0000


raeburn		Sun Dec 19 00:48:50 2010 EDT

  Modified files:              
    /loncom/homework	rankresponse.pm 
  Log:
  - New Question Type - randomizetry
    - Only display rankings from last try when displaying options for new try,
      if rndseed for last try is the same as for current try. 
  
  
Index: loncom/homework/rankresponse.pm
diff -u loncom/homework/rankresponse.pm:1.63 loncom/homework/rankresponse.pm:1.64
--- loncom/homework/rankresponse.pm:1.63	Mon Aug  2 10:52:54 2010
+++ loncom/homework/rankresponse.pm	Sun Dec 19 00:48:50 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # rank style response
 #
-# $Id: rankresponse.pm,v 1.63 2010/08/02 10:52:54 foxr Exp $
+# $Id: rankresponse.pm,v 1.64 2010/12/19 00:48:50 raeburn Exp $
 # Copyright Michigan State University Board of Trustees
 #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
@@ -96,7 +96,7 @@
     my $result;
     %Apache::response::foilgroup=();
     $Apache::rankresponse::conceptgroup=0;
-    &Apache::response::pushrandomnumber();
+    &Apache::response::pushrandomnumber(undef,$target);
     return $result;
 }
 
@@ -280,6 +280,11 @@
     } else {
 	$Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=$gradestr;
     }
+    if ($Apache::lonhomework::type eq 'randomizetry') {
+        if ($Apache::lonhomework::type eq 'randomizetry') {
+            $Apache::lonhomework::results{"resource.$part.$id.foilorder"} = &Apache::lonnet::array2str(@whichfoils);
+        }
+    }
     $Apache::lonhomework::results{"resource.$part.$id.submission"}=
 	$responsestr;
     $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
@@ -326,8 +331,16 @@
 	my $temp=1;
 	my $id=$Apache::inputtags::response[-1];
 	my $part=$Apache::inputtags::part;
-	my $lastresponse;
-        unless ((($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') || ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) && (defined($env{'form.grade_symb'}))) {
+        my ($lastresponse,$newvariation);
+        if ((($Apache::lonhomework::history{"resource.$part.type"} eq 'randomizetry') ||
+             ($Apache::lonhomework::type eq 'randomizetry')) &&
+        ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
+            if ($env{'form.'.$part.'.rndseed'} ne
+                $Apache::lonhomework::history{"resource.$part.rndseed"}) {
+                $newvariation = 1;
+            }
+        }
+        unless (((($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') || ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) && (defined($env{'form.grade_symb'}))) || $newvariation) {
             $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
         }
 	my %lastresponse=&Apache::lonnet::str2hash($lastresponse); 
@@ -350,7 +363,7 @@
 	    foreach $option (@whichopt) {
 		if ($option eq $lastopt) {
 		    if ($target ne 'tex' ) {
-                        $optionlist.="<option selected=\"on\">$option</option>\n";
+                        $optionlist.="<option selected=\"selected\">$option</option>\n";
                     } elsif ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes') {
                         $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option); 
                     }
@@ -403,9 +416,14 @@
 	}
     }
     if ($target eq 'web') {
+        my $questiontype;
+        if ($Apache::lonhomework::type eq 'randomizetry') {
+            $questiontype = $Apache::lonhomework::type;
+        }
 	&Apache::response::setup_prior_tries_hash(\&format_prior_answer,
 						  [\@whichfoils,
-						   'submissiongrading']);
+						   'submissiongrading'],
+                                                  $questiontype);
     }
     if ($target ne 'tex') {$result.="<br />";} else {$result.=' \vskip 0 mm ';}
     return $result;