--- loncom/homework/radiobuttonresponse.pm 2012/01/05 11:56:34 1.153 +++ loncom/homework/radiobuttonresponse.pm 2012/01/20 11:41:31 1.153.6.1 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # mutliple choice style responses # -# $Id: radiobuttonresponse.pm,v 1.153 2012/01/05 11:56:34 foxr Exp $ +# $Id: radiobuttonresponse.pm,v 1.153.6.1 2012/01/20 11:41:31 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -387,6 +387,7 @@ sub format_prior_answer { } +## sub displayallfoils { my ( $direction, $target ) = @_; my $result; @@ -767,6 +768,87 @@ sub whichfoils { &Apache::lonxml::debug("Answer is $answer"); return ( $answer, @whichfalse ); } +## +# Display foils in html rendition: +# +# @param $whichfoils - Set of foils to display. +# @param $target - Rendition target...there are several html targets. +# @param $direction - 'horizontal' if layout is horizontal. +# @param $part - Part of the problem that's being displayed. +# @param $solved - Solution state of the problem. +# @param $show_answer- True if answers should be shown. +# +# @return string +# @retval generated html. +# +sub display_foils_html { + my ($whichfoils, $target, $direction, $part, $solved, $show_answer) = @_; + my $result; + + # if the answers get shown, we need to label each item as correct or + # incorrect. + + if ($show_answer) { + my $item_pretext = '
'; # html prior to each item + my $item_posttext = ''; # html after each item. + my $finalclose = ''; # html to close off the whole shebang + + + # Horizontal layout is a table with each foil in a cell + + if ($direction eq 'horizontal') { + $result = ''; + $item_pretext = ''; + $finalclose = '
' . $item_pretext; + $item_posttext = '
'; + } + + foreach my $name (@{$whichfoils}) { + + # If the item gets further surrounded by tags, this + # holds the closures for those tages. + + my $item_closetag = ''; + + $result .= $item_pretext; + + # Label each foil as correct or incorrect: + + if ($Apache::response::foilgroup{$name . '.value'} eq 'true') { + $result .= &mt('Correct:') . ''; + $item_closetag .= ''; + + } else { + $result .= &mt('Incorrect'); + } + + # Web rendition encloses the + # item text in a label tag as well: + + if ($target eq 'web') { + $result .= '' . $item_closetag; + } + $result .= $Apache::response::foilgroup{$name . '.text'}; + $result .= $item_closetag; + $result .= $item_posttext; + $result .= "\n"; # make the html a bit more readable. + } + + $result .= $finalclose; + + } else { + # Not showing the answers, we need to generate the HTML appropriate + # to allowing the student to respond. + + + } + + return $result; +} + + +## sub displayfoils { my ( $target, $answer, $whichfoils, $direction, $bubbles_per_line ) = @_; @@ -777,48 +859,52 @@ sub displayfoils { if ( ( $target ne 'tex' ) && &Apache::response::show_answer() ) { - if ( $direction eq 'horizontal' ) { - if ( $target ne 'tex' ) { - $result .= ''; - } - } - foreach my $name ( @{$whichfoils} ) { - if ( $direction eq 'horizontal' ) { - if ( $target ne 'tex' ) { $result .= ''; } - } - } - if ( $direction eq 'horizontal' ) { - if ( $target ne 'tex' ) { - $result .= '
'; } - } - if ( $target ne 'tex' ) { - $result .= "
"; - } - else { - $result .= '\item \vskip -2 mm '; - } - if ( $Apache::response::foilgroup{ $name . '.value' } eq 'true' ) { - if ( $target ne 'tex' ) { - $result .= &mt('Correct:') . ''; - } - else { - $result .= &mt('Correct:') . ' \textbf{'; - } - } - else { - $result .= &mt('Incorrect:'); - } - if ( $target eq 'web' ) { $result .= ""; } - if ( $Apache::response::foilgroup{ $name . '.value' } eq 'true' ) { - if ( $target ne 'tex' ) { $result .= ''; } - else { $result .= '}'; } - } - if ( $direction eq 'horizontal' ) { - if ( $target ne 'tex' ) { $result .= '
'; - } - } + + $result = &display_foils_html( + $whichfoils, $target, $direction, $part, $solved, 1); + +# if ( $direction eq 'horizontal' ) { +# if ( $target ne 'tex' ) { +# $result .= ''; +# } +# } +# foreach my $name ( @{$whichfoils} ) { +# if ( $direction eq 'horizontal' ) { +# if ( $target ne 'tex' ) { $result .= ''; } +# } +# } +# if ( $direction eq 'horizontal' ) { +# if ( $target ne 'tex' ) { +# $result .= '
'; } +# } +# if ( $target ne 'tex' ) { +# $result .= "
"; +# } +# else { +# $result .= '\item \vskip -2 mm '; +# } +# if ( $Apache::response::foilgroup{ $name . '.value' } eq 'true' ) { +# if ( $target ne 'tex' ) { +# $result .= &mt('Correct:') . ''; +# } +# else { +# $result .= &mt('Correct:') . ' \textbf{'; +# } +# } +# else { +# $result .= &mt('Incorrect:'); +# } +# if ( $target eq 'web' ) { $result .= ""; } +# if ( $Apache::response::foilgroup{ $name . '.value' } eq 'true' ) { +# if ( $target ne 'tex' ) { $result .= ''; } +# else { $result .= '}'; } +# } +# if ( $direction eq 'horizontal' ) { +# if ( $target ne 'tex' ) { $result .= '
'; +# } +# } } else { my @alphabet = ( 'A' .. 'Z' );