--- loncom/homework/structuretags.pm 2019/11/04 19:36:46 1.566 +++ loncom/homework/structuretags.pm 2019/11/05 18:08:09 1.568 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.566 2019/11/04 19:36:46 raeburn Exp $ +# $Id: structuretags.pm,v 1.568 2019/11/05 18:08:09 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -678,10 +678,18 @@ sub setup_rndseed { } if ($Apache::lonhomework::type eq 'randomizetry') { my $partfortries = $Apache::inputtags::part; +# +# Where question type is "randomizetry" for a problem containing +# a single part (and unless type is explicitly set to not be +# "randomizetry" for that part), the number of tries used to +# determine randomization will be for that part, and randomization +# from calls to &random() in a perl script block before the part tag, +# will change based on the number of tries, and value of the +# "randomizeontries" parameter in effect for the single part. +# 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') { + if ((@{$probpartlist} == 1) && ($probpartlist->[0] ne $partfortries)) { + if (&Apache::lonnet::EXT('resource.'.$probpartlist->[0].'.type') eq 'randomizetry') { $partfortries = $probpartlist->[0]; } else { $partfortries = ''; @@ -1814,11 +1822,13 @@ sub start_problem { } elsif ((($target eq 'grade') && ($Apache::lonhomework::type eq 'randomizetry')) || ($target eq 'answer')) { my ($symb)= &Apache::lonnet::whichuser(); - my $navmap = Apache::lonnavmaps::navmap->new(); - if (ref($navmap)) { - my $res = $navmap->getBySymb($symb); - if (ref($res)) { - $probpartlist = $res->parts(); + if ($symb ne '') { + my $navmap = Apache::lonnavmaps::navmap->new(); + if (ref($navmap)) { + my $res = $navmap->getBySymb($symb); + if (ref($res)) { + $probpartlist = $res->parts(); + } } } } @@ -1838,7 +1848,14 @@ sub start_problem { if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') { + my ($symb) = &Apache::lonnet::whichuser(); #handle rand seed in construction space + if (($env{'request.state'} eq 'construct') || ($symb eq '')) { + my $partorder=&Apache::lonnet::metadata($env{'request.uri'},'partorder'); + if ($partorder ne '') { + @{$probpartlist} = split(/,/,$partorder); + } + } my $rndseed=&setup_rndseed($safeeval,$target,$probpartlist); if (($target eq 'grade') && &Apache::response::submitted()) { if ($Apache::lonhomework::type eq 'randomizetry') { @@ -1853,7 +1870,6 @@ sub start_problem { } } } - my ($symb)=&Apache::lonnet::whichuser(); if ($env{'request.state'} ne "construct" && ($symb eq '' || $Apache::lonhomework::type eq 'practice')) { @@ -3009,10 +3025,9 @@ sub start_part { } 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') || ($Apache::lonhomework::randomizetrypart)) && + 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') {