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

raeburn raeburn at source.lon-capa.org
Mon Nov 4 15:50:58 EST 2019


raeburn		Mon Nov  4 20:50:58 2019 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/homework	structuretags.pm 
  Log:
  - For 2.11
    Backport 1.566, 1.567.
  
  
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.512.2.20 loncom/homework/structuretags.pm:1.512.2.21
--- loncom/homework/structuretags.pm:1.512.2.20	Mon Nov  4 18:01:04 2019
+++ loncom/homework/structuretags.pm	Mon Nov  4 20:50:57 2019
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.512.2.20 2019/11/04 18:01:04 raeburn Exp $
+# $Id: structuretags.pm,v 1.512.2.21 2019/11/04 20:50:57 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -655,10 +655,17 @@
         if (ref($probpartlist) eq 'ARRAY') {
             if ((@{$probpartlist} == 1) && ($probpartlist->[0] ne $Apache::inputtags::part)) {
                 $partfortries = $probpartlist->[0];
+                if (&Apache::lonnet::EXT("resource.$partfortries.questiontype") eq 'randomizetry') {
+                    $partfortries = $probpartlist->[0];
+                } else {
+                    $partfortries = '';
+                }
             }
         }
-        $numtries = $Apache::lonhomework::history{"resource.$partfortries.tries"};
-        $reqtries = &Apache::lonnet::EXT("resource.$partfortries.randomizeontries");
+        if ($partfortries ne '') {
+            $numtries = $Apache::lonhomework::history{"resource.$partfortries.tries"};
+            $reqtries = &Apache::lonnet::EXT("resource.$partfortries.randomizeontries");
+        }
     }
     if (($env{'request.state'} eq "construct") 
         || ($symb eq '')
@@ -1417,6 +1424,7 @@
     @Apache::structuretags::whilebody=();
     @Apache::structuretags::whileline=();
     $Apache::lonhomework::scantronmode=0;
+    $Apache::lonhomework::randomizetrypart=0;
     undef($Apache::lonhomework::name);
     undef($Apache::lonhomework::default_type);
     undef($Apache::lonhomework::type);
@@ -1440,6 +1448,7 @@
     undef($Apache::lonhomework::default_type);
     undef($Apache::lonhomework::type);
     undef($Apache::lonhomework::scantronmode);
+    undef($Apache::inputtags::randomizetrypart);
     undef($Apache::lonhomework::ignore_response_errors);
     undef(@Apache::functionplotresponse::callscripts);
     &Apache::lonhomework::reset_show_problem_status();
@@ -1622,9 +1631,15 @@
         if (($env{'request.state'} ne "construct") &&
             ($Apache::lonhomework::type eq 'randomizetry') &&
             ($status eq 'CAN_ANSWER')) {
-            my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
-            my $problemstatus = &get_problem_status($Apache::inputtags::part);
-            $form_tag_start.=&randomizetry_problem_header($problemstatus,$reqtries);
+            my @parts;
+            if (ref($probpartlist) eq 'ARRAY') {
+                @parts = @{$probpartlist};
+            }
+            unless (@parts) {
+                my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
+                my $problemstatus = &get_problem_status($Apache::inputtags::part);
+                $form_tag_start.=&randomizetry_problem_header($problemstatus,$reqtries,$symb);
+            }
         }
 
 	my $expression='$external::datestatus="'.$status.'";';
@@ -1945,7 +1960,24 @@
 	    }
 	}
         if ($target eq 'web') {
-           $result.=&Apache::functionplotresponse::init_script();
+            $result.=&Apache::functionplotresponse::init_script();
+            if ($Apache::lonhomework::default_type eq 'randomizetry') {
+                my ($symb) = &Apache::lonnet::whichuser();
+                if ((($env{'request.state'} eq 'construct') || ($symb eq '')) &&
+                    ($status eq 'CAN_ANSWER')) {
+                    unless (@Apache::inputtags::partlist > 1) {
+                        $result.= <<"ENDJS";
+<script type="text/javascript">
+// <![CDATA[
+    \$(document).ready(function() {
+         \$('#LC_randomizetry_header').css('display','block');
+    });
+// ]]>
+</script>
+ENDJS
+                    }
+                }
+            }
         }
 	if ($target eq 'grade') {
 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
@@ -2744,20 +2776,14 @@
 		} elsif ($target eq 'web') {
                     if ($status eq 'CAN_ANSWER') {
                         my $problemstatus = &get_problem_status($Apache::inputtags::part); 
-                        my $probrandomize = &Apache::lonnet::EXT("resource.$Apache::inputtags::partlist[0].type");
-                        my $probrandtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::partlist[0].randomizeontries");
                         my $num = scalar(@Apache::inputtags::partlist)-1;
-                        if ($probrandomize eq 'randomizetry') {
-                            if (&Apache::lonnet::EXT("resource.$Apache::inputtags::part.type") ne 'randomizetry') {
-                                $result .= &randomizetry_part_header($problemstatus,'none',$num);
-                            } else {
-                                my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
-                                if ($probrandtries ne $reqtries) {
-                                    $result .= &randomizetry_part_header($problemstatus,$reqtries,$num);
-                                }
-                            }
-                        } elsif (&Apache::lonnet::EXT("resource.$Apache::inputtags::part.type") eq 'randomizetry') {
-                            my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
+                        if ((($Apache::lonhomework::default_type eq 'randomizetry') ||
+                             ($Apache::lonhomework::randomizetrypart)) &&
+                            ($Apache::lonhomework::type ne 'randomizetry')) {
+                            $result .= &randomizetry_part_header($problemstatus,'none',$num);
+                        } elsif ($Apache::lonhomework::type eq 'randomizetry') {
+                            $Apache::lonhomework::randomizetrypart = 1;
+                            my $reqtries = &Apache::lonnet::EXT("resource.$id.randomizeontries");
                             $result .= &randomizetry_part_header($problemstatus,$reqtries,$num);
                         }
                     }
@@ -3077,7 +3103,7 @@
 }
 
 sub randomizetry_problem_header {
-    my ($problemstatus,$reqtries) = @_;
+    my ($problemstatus,$reqtries,$symb) = @_;
     my ($header,$text);
     if ($reqtries > 1) {
         $header = &mt('New Problem Variation After Every [quant,_1,Try,Tries]',$reqtries);
@@ -3097,8 +3123,13 @@
             $text = &mt('A new variation will be generated after each try until correct or tries limit is reached.');
         }
     }
-    return '<span class="LC_info"><h3>'.$header.'</h3></span>'.
-           '<span class="LC_info">'.$text.'</span><hr />';
+    if (($env{'request.state'} eq "construct") || ($symb eq '')) {
+        return '<div class="LC_info" id="LC_randomizetry_header" style="display:none">'.
+               '<h3>'.$header.'</h3><span class="LC_info">'.$text.'</span><hr /></div>';
+    } else {
+        return '<h3 class="LC_info">'.$header.'</h3>'.
+               '<span class="LC_info">'.$text.'</span><hr />';
+    }
 }
 
 sub randomizetry_part_header {




More information about the LON-CAPA-cvs mailing list