[LON-CAPA-cvs] cvs: loncom(randomize) /interface londocs.pm rat lonuserstate.pm

albertel lon-capa-cvs-allow@mail.lon-capa.org
Thu, 28 Jun 2007 23:26:47 -0000


This is a MIME encoded message

--albertel1183073207
Content-Type: text/plain

albertel		Thu Jun 28 19:26:47 2007 EDT

  Modified files:              (Branch: randomize)
    /rat	lonuserstate.pm 
    /loncom/interface	londocs.pm 
  Log:
  - random ordering now works of parameter settings
  - londocs has a check box for flipping random order on and off
  
  (Currently all users are affected, probably need to disable for adv users)
  
  
--albertel1183073207
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20070628192647.txt"

Index: rat/lonuserstate.pm
diff -u rat/lonuserstate.pm:1.118.2.1 rat/lonuserstate.pm:1.118.2.2
--- rat/lonuserstate.pm:1.118.2.1	Fri Jun  8 15:33:06 2007
+++ rat/lonuserstate.pm	Thu Jun 28 19:26:38 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Construct and maintain state and binary representation of course for user
 #
-# $Id: lonuserstate.pm,v 1.118.2.1 2007/06/08 19:33:06 albertel Exp $
+# $Id: lonuserstate.pm,v 1.118.2.2 2007/06/28 23:26:38 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -56,6 +56,7 @@
 my $retfurl; # first URL
 my %randompick; # randomly picked resources
 my %randompickseed; # optional seed for randomly picking resources
+my %randomorder; # maps to order contents randomly
 my %encurl; # URLs in this folder are supposed to be encrypted
 my %hiddenurl; # this URL (or complete folder) is supposed to be hidden
 
@@ -106,7 +107,7 @@
 # --------------------------------------------------------- Loads map from disk
 
 sub loadmap { 
-    my $uri=shift;
+    my ($uri,$parent_rid)=@_;
     if ($hash{'map_pc_'.$uri}) { 
 	$errtext.=&mt('<br />Multiple use of sequence/page <tt>[_1]</tt>! The course will not function properly.',$uri);
 	return; 
@@ -138,6 +139,16 @@
 
     my $parser = HTML::TokeParser->new(\$instr);
     $parser->attr_encoded(1);
+    # first get all parameters
+    while (my $token = $parser->get_token) {
+	next if ($token->[0] ne 'S');
+	if ($token->[1] eq 'param') {
+	    &parse_param($token,$lpc);
+	} 
+    }
+    #reset parser
+    $parser = HTML::TokeParser->new(\$instr);
+    $parser->attr_encoded(1);
 
     my $linkpc=0;
 
@@ -145,7 +156,8 @@
 
     $hash{'map_type_'.$lpc}=$1;
 
-    my $randomize=1;
+    my $randomize = ($randomorder{$parent_rid} =~ /^yes$/i);
+
     my @map_ids;
     while (my $token = $parser->get_token) {
 	next if ($token->[0] ne 'S');
@@ -158,12 +170,16 @@
 		       $token->[2]->{'condition'});
 	} elsif ($token->[1] eq 'condition' && !$randomize) {
 	    &parse_condition($token,$lpc);
-	} elsif ($token->[1] eq 'param') {
-	    &parse_param($token,$lpc);
-	} 
+	}
     }
 
     if ($randomize) {
+	my $seed = (split(/\./,$parent_rid))[1];
+	if ($randompickseed{$parent_rid}) {
+	    $seed = $randompickseed{$parent_rid};
+	}
+	my $rndseed=&Apache::lonnet::rndseed($seed);
+	&Apache::lonnet::setup_random_from_rndseed($rndseed);
 	my @map_ids=&Math::Random::random_permutation(@map_ids);
 	my $from = shift(@map_ids);
 	my $from_rid = $lpc.'.'.$from;
@@ -265,7 +281,7 @@
     if (($turi=~/\.sequence$/) ||
 	($turi=~/\.page$/)) {
 	$hash{'is_map_'.$rid}=1;
-	&loadmap($turi);
+	&loadmap($turi,$rid);
     } 
     return $token->[2]->{'id'};
 }
@@ -342,7 +358,11 @@
 	$randompick{$referid}=$token->[2]->{'value'};
     }
     if ($token->[2]->{'name'}=~/^parameter_(0_)*randompickseed$/) {
-	$randompick{$referid}=$token->[2]->{'value'};
+	$randompickseed{$referid}=$token->[2]->{'value'};
+    }
+    if ($token->[2]->{'name'}=~/^parameter_(0_)*randomorder$/) {
+	$randomorder{$referid}=$token->[2]->{'value'};
+	&Apache::lonnet::logthis("roing $referid ".$randomorder{$referid});
     }
     if ($token->[2]->{'name'}=~/^parameter_(0_)*encrypturl$/) {
 	if ($token->[2]->{'value'}=~/^yes$/i) {
@@ -621,7 +641,7 @@
 	$hash{'title_0.0'}=&Apache::lonnet::metadata($uri,'title');
 	$hash{'ids_'.$furi}='0.0';
 	$hash{'is_map_0.0'}=1;
-	loadmap($uri);
+	loadmap($uri,'0.0');
 	if (defined($hash{'map_start_'.$uri})) {
 	    &Apache::lonnet::appenv("request.course.id"  => $short,
 				    "request.course.fn"  => $fn,
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.278 loncom/interface/londocs.pm:1.278.2.1
--- loncom/interface/londocs.pm:1.278	Sat Jun 16 13:42:24 2007
+++ loncom/interface/londocs.pm	Thu Jun 28 19:26:46 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.278 2007/06/16 17:42:24 albertel Exp $
+# $Id: londocs.pm,v 1.278.2.1 2007/06/28 23:26:46 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -967,6 +967,7 @@
     my $randompick=-1;
     my $isencrypted=0;
     my $ishidden=0;
+    my $is_random_order=0;
     while (@folders) {
 	my $folder=shift(@folders);
 	my $foldername=shift(@folders);
@@ -976,7 +977,7 @@
 	    &escape($folderpath);
             my $name=&unescape($foldername);
 # randompick number, hidden, encrypted is appended with ":"s to the foldername	
-            $name=~s/\:(\d*)\:(\w*)\:(\w*)$//;
+            $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//;
             if ($1 ne '') { 
                $randompick=$1;
             } else {
@@ -984,6 +985,7 @@
             }
             if ($2) { $ishidden=1; }
             if ($3) { $isencrypted=1; }
+            if ($4 ne '') { $is_random_order = 1; }
 	    &Apache::lonhtmlcommon::add_breadcrumb(
 		      {'href'=>$url.$cpinfo,
 		       'title'=>$name,
@@ -995,7 +997,7 @@
     }
     $plain=~s/\&gt\;\s*$//;
     return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
-					       'LC_docs_path'),$randompick,$ishidden,$isencrypted,$plain);
+					       'LC_docs_path'),$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
 }
 
 sub log_docs {
@@ -1086,6 +1088,7 @@
     my %lt=('hiddenresource' => 'Resources hidden',
 	    'encrypturl'     => 'URL hidden',
 	    'randompick'     => 'Randomly pick',
+	    'randomorder'    => 'Randomly ordered',
 	    'set'            => 'set to',
 	    'del'            => 'deleted');
     $r->print(&Apache::loncommon::display_filter().
@@ -1168,7 +1171,7 @@
 	$r->print('</ul>');
 	if ($docslog{$id}{'logentry'}{'parameter_res'}) {
 	    $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
-	    foreach my $parameter ('randompick','hiddenresource','encrypturl') {
+	    foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
 		if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
 		    $r->print('<li>'.
 			      &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
@@ -1210,7 +1213,7 @@
 	$env{'form.markedcopy_title'}=$title;
 	$env{'form.markedcopy_url'}=$url;
     }
-    my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain)=&breadcrumbs($folder);
+    my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order)=&breadcrumbs($folder);
     $r->print($breadcrumbtrail);
     if ($fatal) {
 	   $r->print('<p><font color="red">'.$errtext.'</font></p>');
@@ -1251,6 +1254,15 @@
 			&remember_parms($idx,'encrypturl','del');
 		    }
 		}
+		if ($env{'form.changeparms'} eq 'randomorder') {
+		    if ($env{'form.randorder_'.$idx}) {
+			&LONCAPA::map::storeparameter($idx,'parameter_randomorder','yes','string_yesno');
+			&remember_parms($idx,'randomorder','set',$env{'form.randorder_'.$idx});
+		    } else {
+			&LONCAPA::map::delparameter($idx,'parameter_randomorder');
+			&remember_parms($idx,'randomorder','del');
+		    }
+		}
 # store the changed version
 		($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
 		if ($fatal) {
@@ -1435,16 +1447,21 @@
 # ---------------------------------------------------------------- Print screen
         my $idx=0;
 	my $shown=0;
-        if (($ishidden) || ($isencrypted) || ($randompick>=0)) {
+        if (($ishidden) || ($isencrypted) || ($randompick>=0) 
+	    || ($is_random_order)) {
            $r->print('<p>'.&mt('Parameters').':<ul>'.
                      ($randompick>=0?'<li>'.&mt('randomly pick [_1] resources',$randompick).'</li>':'').
+                     ($is_random_order?'<li>'.&mt('contents randomly ordered').'</li>':'').
                      ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
                      ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
                      '</ul></p>');
-        }                                                                                                     
+        }
         if ($randompick>=0) {
            $r->print('<p>'.&mt('Caution: this folder is set to randomly pick a subset of resources. Adding or removing resources from this folder will change the set of resources that the students see, resulting in spurious or missing credit for completed problems, not limited to ones you modify. Do not modify the contents of this folder if it is in active student use.').'</p>');
         }
+        if ($is_random_order) {
+           $r->print('<p>'.&mt('Caution: this folder is set to randomly order its contents. Adding or removing resources from this folder will change the order of resources shown. Do not modify the contents of this folder if it is in active student use.').'</p>');
+        }
         $r->print('<table>');
         foreach my $res (@LONCAPA::map::order) {
            my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
@@ -1889,7 +1906,9 @@
                                                .':'.((&LONCAPA::map::getparameter($orderidx,
                                               'parameter_hiddenresource'))[0]=~/^yes$/i)
                                                .':'.((&LONCAPA::map::getparameter($orderidx,
-                                              'parameter_encrypturl'))[0]=~/^yes$/i);
+                                              'parameter_encrypturl'))[0]=~/^yes$/i)
+                                               .':'.((&LONCAPA::map::getparameter($orderidx,
+                                              'parameter_randomorder'))[0]=~/^yes$/i);
 	$url.='folderpath='.&escape($folderpath).$cpinfo;
 	$parameterset='<label>'.&mt('Randomly Pick: ').
 	    '<input type="text" size="4" onChange="this.form.changeparms.value='."'randompick'".';this.form.submit()" name="randpick_'.$orderidx.'" value="'.
@@ -1924,16 +1943,21 @@
     if (($allowed) && ($folder!~/^supplemental/)) {
  	my %lt=&Apache::lonlocal::texthash(
  			      'hd' => 'Hidden',
- 			      'ec' => 'URL hidden');
+ 			      'ec' => 'URL hidden',
+ 			      'ro' => 'Random Order',);
 	my $enctext=
-	    ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
+	    ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="checked"':'');
 	my $hidtext=
-	    ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
+	    ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="checked"':'');
+	my $rotext=
+	    ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
 	$line.=(<<ENDPARMS);
 <td bgcolor="#BBBBFF"><font size='-2'>
 <nobr><label><input type="checkbox" name="hidprs_$orderidx" onClick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label></nobr></td>
 <td bgcolor="#BBBBFF"><font size='-2'>
 <nobr><label><input type="checkbox" name="encprs_$orderidx" onClick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label></nobr></td>
+<td bgcolor="#BBBBFF"><font size='-2'>
+<nobr><label><input type="checkbox" name="randorder_$orderidx" onClick="this.form.changeparms.value='randomorder';this.form.submit()" $rotext /> $lt{'ro'}</label></nobr></td>
 <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
 ENDPARMS
     }

--albertel1183073207--