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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 03 Nov 2005 22:59:35 -0000


albertel		Thu Nov  3 17:59:35 2005 EDT

  Modified files:              
    /loncom/homework	bridgetask.pm 
  Log:
  - reworking how the randomization in a BT works, now saves away the instance picked and restores taht
  - added ability to 'disable' an instance so that it will no longer get picked.
  
  
Index: loncom/homework/bridgetask.pm
diff -u loncom/homework/bridgetask.pm:1.74 loncom/homework/bridgetask.pm:1.75
--- loncom/homework/bridgetask.pm:1.74	Thu Nov  3 16:29:57 2005
+++ loncom/homework/bridgetask.pm	Thu Nov  3 17:59:35 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.74 2005/11/03 21:29:57 albertel Exp $
+# $Id: bridgetask.pm,v 1.75 2005/11/03 22:59:35 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1427,12 +1427,39 @@
 }
 
 sub get_instance {
-    &Apache::response::pushrandomnumber();
-    my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
-    my $num=@order;
-    my $version=&get_version();
-    my $which=($version-1)%$num;
-    return $order[$which];
+    my ($dim)=@_;
+    my $rand_alg=&Apache::lonnet::get_rand_alg();
+    if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
+	$rand_alg eq '64bit2' || $rand_alg eq '64bit3' ||
+	$rand_alg eq '64bit4' ) {
+	&Apache::response::pushrandomnumber();
+	my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
+	my $num=@order;
+	my $version=&get_version();
+	my $which=($version-1)%$num;
+	return $order[$which];
+    } else {
+	my ($version,$previous) = &get_version();
+	my $instance = 
+	    $Apache::lonhomework::history{"resource.$version.0.$dim.instance"};
+	if (defined($instance)) { return $instance; }
+
+	&Apache::response::pushrandomnumber();
+	my @instances = @{$dimension{'instances'}};
+	# remove disabled instances
+	for (my $i=0; $i < $#instances; $i++) {
+	    if ($dimension{$instances[$i].'.disabled'}) {
+		splice(@instances,$i,1);
+		$i--;
+	    }
+	}
+	@instances = &Math::Random::random_permutation(@instances);
+	$instance  = $instances[($version-1)%scalar(@instances)];
+	$Apache::lonhomework::results{"resource.$version.0.$dim.instance"} = 
+	    $instance;
+	&Apache::response::poprandomnumber();
+	return $instance;
+    }
 }
 
 {
@@ -1441,7 +1468,7 @@
 	my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 	my $result=&Apache::lonxml::endredirection();
 	my $dim=&get_id($parstack,$safeeval);
-	my $instance=&get_instance();
+	my $instance=&get_instance($dim);
 	my $version=&get_version();
 	if ($target eq 'web') {
 	    @Apache::scripttag::parser_env = @_;
@@ -1622,6 +1649,10 @@
     push(@Apache::bridgetask::instancelist,$id);
     $dimension{$id.'.optionalrequired'}=
 	&Apache::lonxml::get_param('OptionalRequired',$parstack,$safeeval);
+    my $disabled = &Apache::lonxml::get_param('Disabled',$parstack,$safeeval);
+    if (lc($disabled) eq 'yes') {
+	$dimension{$id.'.disabled'}='1';
+    }
     return '';
 }