--- loncom/homework/bridgetask.pm 2005/11/03 21:29:57 1.74
+++ loncom/homework/bridgetask.pm 2005/11/04 15:31:53 1.76
@@ -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.76 2005/11/04 15:31:53 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1427,12 +1427,39 @@ sub start_Dimension {
}
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,80 +1468,86 @@ sub get_instance {
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 = @_;
$result.=&Apache::scripttag::xmlparse($dimension{'intro'});
- @Apache::scripttag::parser_env = @_;
- $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
- if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass' ||
- $Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
-
- my $dim_status=$Apache::lonhomework::history{"resource.$version.$dim.status"};
- my $mandatory='Mandatory';
- if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') {
- $mandatory='Optional';
- }
- my $dim_info="
\n";
- if ($dim_status eq 'pass') {
- $dim_info.='
Question : you passed this '.$mandatory.' question
';
- }
- if ($dim_status eq 'fail') {
- $dim_info.='
Question : you did not pass this '.$mandatory.' question
';
- }
- my $man_count=0;
- my $man_passed=0;
- my $opt_count=0;
- my $opt_passed=0;
- foreach my $id (@{$dimension{$instance.'.criterias'}}) {
- if ($dimension{$instance.'.criteria.'.$id.'.mandatory'}
- eq 'N') {
- $opt_count++;
- if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"} eq 'pass') {
- $opt_passed++;
- }
- } else {
- $man_count++;
- if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"} eq 'pass') {
- $man_passed++;
- }
- }
- }
- if ($man_passed eq $man_count) { $man_passed='all'; }
- my $opt_req=$dimension{$instance.'.optionalrequired'};
- if ($opt_req !~ /\S/) { $opt_req='0'; }
- $dim_info.="\n
".&mt('You passed [_1] of the [_2] mandatory components and [_3] of the [_4] optional components, of which you were required to pass [_5].',$man_passed,$man_count,$opt_passed,$opt_count,$opt_req)."
\n
";
-
- my $internal_location=&internal_location($dim);
- $result=~s/\Q$internal_location\E/$dim_info/;
-
- foreach my $id (@{$dimension{$instance.'.criterias'}}) {
- my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
- my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"};
- my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
- if ($mandatory) {
- $mandatory='Mandatory';
- } else {
+ my @instances = $instance;
+ if (&Apache::response::showallfoils()) {
+ @instances = @{$dimension{'instances'}};
+ }
+ foreach my $instance (@instances) {
+ @Apache::scripttag::parser_env = @_;
+ $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.text'});
+ if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass' ||
+ $Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
+
+ my $dim_status=$Apache::lonhomework::history{"resource.$version.$dim.status"};
+ my $mandatory='Mandatory';
+ if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') {
$mandatory='Optional';
}
- if ($status eq 'fail') {
- } elsif ($status eq 'pass') {
- } else {
- &Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status");
+ my $dim_info="\n";
+ if ($dim_status eq 'pass') {
+ $dim_info.='
Question : you passed this '.$mandatory.' question
';
+ }
+ if ($dim_status eq 'fail') {
+ $dim_info.='
Question : you did not pass this '.$mandatory.' question
';
+ }
+ my $man_count=0;
+ my $man_passed=0;
+ my $opt_count=0;
+ my $opt_passed=0;
+ foreach my $id (@{$dimension{$instance.'.criterias'}}) {
+ if ($dimension{$instance.'.criteria.'.$id.'.mandatory'}
+ eq 'N') {
+ $opt_count++;
+ if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"} eq 'pass') {
+ $opt_passed++;
+ }
+ } else {
+ $man_count++;
+ if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"} eq 'pass') {
+ $man_passed++;
+ }
+ }
}
- my $status_display=$status;
- $status_display=~s/^([a-z])/uc($1)/e;
- @Apache::scripttag::parser_env = @_;
- $result.='
'.$mandatory.
- ' Criteria
';
- @Apache::scripttag::parser_env = @_;
- $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id});
- $result.='
'.$status_display.'
';
- if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) {
- $result.='';
+ if ($man_passed eq $man_count) { $man_passed='all'; }
+ my $opt_req=$dimension{$instance.'.optionalrequired'};
+ if ($opt_req !~ /\S/) { $opt_req='0'; }
+ $dim_info.="\n
".&mt('You passed [_1] of the [_2] mandatory components and [_3] of the [_4] optional components, of which you were required to pass [_5].',$man_passed,$man_count,$opt_passed,$opt_count,$opt_req)."
\n
";
+
+ my $internal_location=&internal_location($dim);
+ $result=~s/\Q$internal_location\E/$dim_info/;
+
+ foreach my $id (@{$dimension{$instance.'.criterias'}}) {
+ my $status=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.status"};
+ my $comment=$Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"};
+ my $mandatory=($dimension{$instance.'.criteria.'.$id.'.mandatory'} ne 'N');
+ if ($mandatory) {
+ $mandatory='Mandatory';
+ } else {
+ $mandatory='Optional';
+ }
+ if ($status eq 'fail') {
+ } elsif ($status eq 'pass') {
+ } else {
+ &Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status");
+ }
+ my $status_display=$status;
+ $status_display=~s/^([a-z])/uc($1)/e;
+ @Apache::scripttag::parser_env = @_;
+ $result.='
'.$mandatory.
+ ' Criteria
';
+ @Apache::scripttag::parser_env = @_;
+ $result.=&Apache::scripttag::xmlparse($dimension{$instance.'.criteria.'.$id});
+ $result.='
'.$status_display.'
';
+ if ($Apache::lonhomework::history{"resource.$version.$dim.$instance.$id.comment"}) {
+ $result.='';
+ }
+ $result.='
';
}
- $result.='
';
}
}
} elsif ($target eq 'webgrade') {
@@ -1622,6 +1655,10 @@ sub start_Instance {
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 '';
}