"; }
+ if ($target ne 'tex') {
+ if (($direction eq 'horizontal') && ($target ne 'tex')) { $result.=""; }
+ } else {
+ $result.='\vskip 0 mm ';
+ }
}
}
}
- if ($direction eq 'horizontal') { $result.=''; }
+
+ if (($direction eq 'horizontal') && ($target ne 'tex')) { $result.=''; }
return $result;
}
+=pod
+
+=item &whichfoils($max,$randomize)
+
+Randomizes the list of foils.
+Respects
+ - each foils desire to be randomized
+ - the existance of Concept groups of foils (select 1 foil from each)
+ - and selects a single correct statement from all possilble true statments
+ - and limits it to a toal of $max foils
+
+WARNING: this routine uses the random number generator, it should only
+be called once per target, otherwise it can cause randomness changes in
+homework problems.
+
+Arguments
+ $max - maximum number of foils to select (including the true one)
+ (so a max of 5 is: 1 true, 4 false)
+
+ $randomize - whether to randomize the listing of foils, by default
+ will randomize, only if randomize is 'no' will it not
+
+Returns
+ $answer - location in the array of the correct answer
+ @foils - array of foil names in to display order
+
+=cut
+
sub whichfoils {
my ($max,$randomize)=@_;
@@ -289,7 +412,7 @@ sub whichfoils {
my ($truecnt,$falsecnt) = &getfoilcounts();
my $count=0;
# we will add in 1 of the true statements
- if (($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; }
+ if ( $max>0 && ($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; $max=$count; }
my $answer=int(&Math::Random::random_uniform() * ($count));
&Apache::lonxml::debug("Count is $count, $answer is $answer");
my @names;
@@ -417,10 +540,9 @@ sub whichfoils {
}
sub displayfoils {
- my ($target,$max,$randomize,$direction)=@_;
+ my ($target,$answer,$whichfoils,$direction, $bubbles_per_line)=@_;
my $result;
- my ($answer,@whichfoils)=&whichfoils($max,$randomize);
my $part=$Apache::inputtags::part;
my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
if ( ($target ne 'tex') &&
@@ -430,7 +552,7 @@ sub displayfoils {
$result.='
';
}
}
- foreach my $name (@whichfoils) {
+ foreach my $name (@{ $whichfoils }) {
if ($direction eq 'horizontal') {
if ($target ne 'tex') { $result.='
'; }
}
@@ -462,6 +584,7 @@ sub displayfoils {
} else {
my @alphabet = ('A'..'Z');
my $i = 0;
+ my $bubble_number = 0;
my $temp=0;
my $id=$Apache::inputtags::response['-1'];
my $part=$Apache::inputtags::part;
@@ -470,7 +593,7 @@ sub displayfoils {
if ($target ne 'tex' && $direction eq 'horizontal') {
$result.="
";
}
- foreach my $name (@whichfoils) {
+ foreach my $name (@{ $whichfoils }) {
if ($target ne 'tex') {
if ($direction eq 'horizontal') {
$result.="
";
@@ -480,13 +603,23 @@ sub displayfoils {
}
if ($target ne 'tex') {
$result.= '';
- $result.="";
+ $result .= ' />'.$Apache::response::foilgroup{$name.'.text'}."";
} else {
if ($Apache::lonhomework::type eq 'exam') {
$result .= '{\small \textbf{'.$alphabet[$i].'}}$\bigcirc$'.$Apache::response::foilgroup{$name.'.text'}.'\\\\'; #' stupid emacs
$i++;
+ $bubble_number++;
+ if($bubble_number >= $bubbles_per_line) {
+ $i = 0;
+ $bubble_number = 0;
+ $result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]';
+ }
} else {
$result .= '\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
}
@@ -505,8 +638,10 @@ sub displayfoils {
}
sub displayallanswers {
- my @names = @{ $Apache::response::foilgroup{'names'} };
-
+ my @names;
+ if ( $Apache::response::foilgroup{'names'} ) {
+ @names= @{ $Apache::response::foilgroup{'names'} };
+ }
my $result=&Apache::response::answer_header('radiobuttonresponse');
foreach my $name (@names) {
$result.=&Apache::response::answer_part('radiobuttonresponse',
@@ -517,13 +652,17 @@ sub displayallanswers {
}
sub displayanswers {
- my ($max,$randomize)=@_;
- my ($answer,@whichopt) = &whichfoils($max,$randomize);
+ my ($answer, $whichopt)=@_;
my $result=&Apache::response::answer_header('radiobuttonresponse');
- foreach my $name (@whichopt) {
+ if ($Apache::lonhomework::type eq 'exam') {
+ my $correct = ('A'..'Z')[$answer];
$result.=&Apache::response::answer_part('radiobuttonresponse',
- $Apache::response::foilgroup{$name.'.value'})
- }
+ $correct);
+ }
+ foreach my $name (@{ $whichopt }) {
+ $result.=&Apache::response::answer_part('radiobuttonresponse',
+ $Apache::response::foilgroup{$name.'.value'});
+ }
$result.=&Apache::response::answer_footer('radiobuttonresponse');
return $result;
}