--- loncom/homework/radiobuttonresponse.pm 2012/01/24 12:05:12 1.153.6.5 +++ loncom/homework/radiobuttonresponse.pm 2012/01/25 11:37:32 1.153.6.6 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # mutliple choice style responses # -# $Id: radiobuttonresponse.pm,v 1.153.6.5 2012/01/24 12:05:12 foxr Exp $ +# $Id: radiobuttonresponse.pm,v 1.153.6.6 2012/01/25 11:37:32 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -571,6 +571,8 @@ sub displayallfoils{ return $result; } + + sub whichfoils { my ( $max, $randomize ) = @_; @@ -787,6 +789,25 @@ sub whichfoils { &Apache::lonxml::debug("Answer is $answer"); return ( $answer, @whichfalse ); } + +## +# Return a list of foil texts given foil names. +# +# @param $whichfoils - Reference to a list of foil names. +# +# @return array +# @retval foil texts +# +sub get_foil_texts { + my ($whichfoils) = @_; + my @foil_texts; + + foreach my $name (@{$whichfoils}) { + push(@foil_texts, $Apache::response::foilgroup{$name . '.text'}); + } + return @foil_texts; +} + ## # Generate the HTML for a single html foil. # @param $part - The part for which the response is being generated. @@ -984,17 +1005,13 @@ sub display_latex_exam { my $line = 0; my $i = 0; - &Apache::lonnet::logthis("LaTeX exam: $direction $vbegin $vend"); if ($direction eq 'horizontal') { # Marshall the display text for each foil and turn things over to # Apache::response::make_horizontal_bubbles: - my @foil_texts; - foreach my $name (@{$whichfoils}) { - push(@foil_texts, $Apache::response::foilgroup{$name . '.text'}); - } + my @foil_texts = &get_foil_texts($whichfoils); $result .= &Apache::caparesponse::make_horizontal_latex_bubbles( $whichfoils, \@foil_texts, '$\bigcirc$'); @@ -1077,14 +1094,25 @@ sub display_latex { my ($whichfoils, $direction, $vbegin, $vend) = @_; my $result; - $result .= $vbegin; - foreach my $name (@{$whichfoils}) { - $result .= '\vspace*{-2 mm}\item ' - . $Apache::response::foilgroup{ $name . '.text' }; - } + # how we render depends on the direction. + # Vertical is some kind of list environment determined by vbegin/vend. + # Horizontal is a table that is generated by + # Apache::caparesponse::make_horizontal_latex_bubbles with an empty string + # for the actual bubble text. - $result .= $vend; + if ($direction eq 'horizontal') { + my @foil_texts = &get_foil_texts($whichfoils); + $result .= &Apache::caparesponse::make_horizontal_latex_bubbles( + $whichfoils, \@foil_texts, ''); + } else { + $result .= $vbegin; + foreach my $name (@{$whichfoils}) { + $result .= '\vspace*{-2 mm}\item ' + . $Apache::response::foilgroup{ $name . '.text' }; + } + $result .= $vend; + } return $result; }