version 1.153.6.9, 2012/02/04 20:40:07
|
version 1.153.6.10, 2012/02/05 16:11:57
|
Line 43 BEGIN {
|
Line 43 BEGIN {
|
('radiobuttonresponse') ); |
('radiobuttonresponse') ); |
} |
} |
|
|
|
#--------------------------------------------------------------------------- |
|
# |
|
# Generic utility subs. |
|
|
sub bubble_line_count { |
sub bubble_line_count { |
my ( $numfoils, $bubbles_per_line ) = @_; |
my ( $numfoils, $bubbles_per_line ) = @_; |
my $bubble_lines; |
my $bubble_lines; |
Line 54 sub bubble_line_count {
|
Line 58 sub bubble_line_count {
|
|
|
} |
} |
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
# |
|
# XML handlers. |
sub start_radiobuttonresponse { |
sub start_radiobuttonresponse { |
my ( $target, $token, $tagstack, $parstack, $parser, $safeeval, $style ) = |
my ( $target, $token, $tagstack, $parstack, $parser, $safeeval, $style ) = |
@_; |
@_; |
Line 488 sub display_survey_html {
|
Line 496 sub display_survey_html {
|
# foil lives in a <p> |
# foil lives in a <p> |
# |
# |
|
|
my $closing_html; |
|
my $pre_foil; |
|
my $post_foil; |
|
|
|
if ($direction eq 'horizontal') { |
|
$result .= '<table><tr>'; |
|
$closing_html = '</tr></table>'; |
|
$pre_foil = '<td>'; |
|
$post_foil = '</td>'; |
|
} else { |
|
$pre_foil = '<br />'; |
|
} |
|
# Different rendering depending on whether answers are shown: |
|
|
|
|
my ($opening_html, $closing_html, $pre_foil, $post_foil) = |
|
&html_direction_fragments($direction); |
|
|
if ($showanswer) { |
$result = $opening_html; |
foreach my $name (@{$names}) { |
|
|
# Different rendering depending on whether answers are shown: |
|
# I played with different factorings but this seems the most concise/clear... |
|
# although I don't like the $showanswer conditino inside the loop. Other things I tried |
|
# - two loops..much longer code..no gain in clarity. |
|
# - Using a visitor patttern passing it the rendering code chunklets and |
|
# an anonymous hash reference for state data etc. Very cool but |
|
# quite a bit more code and quite a bit less clear. |
|
|
|
my $temp = 0; |
|
foreach my $name (@{$names}) { |
|
$result .= $pre_foil; |
|
|
$result .= $pre_foil; |
if ($showanswer) { |
my $foiltext = $Apache::response::foilgroup{$name . '.text'}; |
my $foiltext = $Apache::response::foilgroup{$name . '.text'}; |
|
|
# Bold the prior response: |
# Bold the prior response: |
Line 516 sub display_survey_html {
|
Line 524 sub display_survey_html {
|
} else { |
} else { |
$result .= $foiltext; |
$result .= $foiltext; |
} |
} |
|
} else { |
$result .= $post_foil; |
|
} |
|
} else { |
|
my $temp = 0; |
|
foreach my $name (@{$names}) { |
|
$result .= $pre_foil; |
|
|
|
$result .= &html_radiobutton( |
$result .= &html_radiobutton( |
$part, $Apache::inputtags::response['-1'], $name, $lastresponse, $temp |
$part, $Apache::inputtags::response['-1'], $name, $lastresponse, $temp |
); |
); |
|
|
$result .= $post_foil; |
|
$temp++; |
|
|
|
} |
} |
|
|
|
$result .= $post_foil; |
|
$temp++; |
} |
} |
|
|
|
|
$result .= $closing_html; |
$result .= $closing_html; |
return $result; |
return $result; |
|
|
Line 631 sub latex_vertical_environment {
|
Line 632 sub latex_vertical_environment {
|
} |
} |
} |
} |
|
|
|
## |
|
# Figure out the key html fragments that depend on the rendering direction: |
|
# |
|
# @param $direction - 'horizontal' for horizontal direction. |
|
# |
|
# @return list |
|
# @retval (part_start, part_end, foil_start, foil_end) |
|
# Where: |
|
# - part_start is the HTML to emit at the start of the part. |
|
# - part_end is the HTML to emit at the end of the part. |
|
# - foil_start is the HTML to emit prior to each foil. |
|
# - foil_end is the HTML to emit after each foil |
|
# |
|
sub html_direction_fragments { |
|
my $direction = shift; |
|
if ($direction eq 'horizontal') { |
|
return ('<table><tr>', '</tr></table>', '<td>', '</td>'); |
|
} else { |
|
return ('', '<br />', '<br />', ''); |
|
} |
|
} |
|
|
## |
## |
# |
# |
Line 1005 sub display_foils_html {
|
Line 1026 sub display_foils_html {
|
my ($whichfoils, $target, $direction, $part, $show_answer) = @_; |
my ($whichfoils, $target, $direction, $part, $show_answer) = @_; |
my $result; |
my $result; |
|
|
|
|
# if the answers get shown, we need to label each item as correct or |
# if the answers get shown, we need to label each item as correct or |
# incorrect. |
# incorrect. |
|
|
if ($show_answer) { |
my ($opening_html, $finalclose, $item_pretext, $item_posttext) = |
my $item_pretext = '<br />'; # html prior to each item |
&html_direction_fragments($direction); |
my $item_posttext = ''; # html after each item. |
|
my $finalclose = ''; # html to close off the whole shebang |
|
|
|
|
$result .= $opening_html; |
|
|
# Horizontal layout is a table with each foil in a cell |
|
|
|
if ($direction eq 'horizontal') { |
if ($show_answer) { |
$result = '<table><tr>'; |
|
$item_pretext = '<td>' . $item_pretext; |
|
$item_posttext = '</td>'; |
|
$finalclose = '</tr></table>'; |
|
} |
|
|
|
foreach my $name (@{$whichfoils}) { |
foreach my $name (@{$whichfoils}) { |
|
|
Line 1055 sub display_foils_html {
|
Line 1070 sub display_foils_html {
|
$result .= "\n"; # make the html a bit more readable. |
$result .= "\n"; # make the html a bit more readable. |
} |
} |
|
|
$result .= $finalclose; |
|
|
|
} else { |
} else { |
$result .= '<br />'; # end line prior to foilgroup: |
|
|
|
# Not showing the answers, we need to generate the HTML appropriate |
|
# to allowing the student to respond. |
|
|
|
my $item_pretext; |
|
my $item_posttext; |
|
my $lastresponse = &get_last_response($part); |
my $lastresponse = &get_last_response($part); |
|
|
if ( $direction eq 'horizontal' ) { |
|
$item_pretext = '<td>'; |
|
$item_posttext = '</td>'; |
|
} |
|
else { |
|
$item_pretext = '<br/>'; |
|
} |
|
my $item_no = 0; |
my $item_no = 0; |
foreach my $name (@{$whichfoils}) { |
foreach my $name (@{$whichfoils}) { |
$result .= $item_pretext; |
$result .= $item_pretext; |
Line 1084 sub display_foils_html {
|
Line 1084 sub display_foils_html {
|
$result .= $item_posttext; |
$result .= $item_posttext; |
$item_no++; |
$item_no++; |
} |
} |
|
|
if ($direction eq 'horizontal' ) { |
|
$result .= "</tr></table>"; |
|
} else { |
|
$result .= "<br />"; |
|
} |
|
} |
} |
|
$result .= $finalclose; |
|
|
return $result; |
return $result; |
} |
} |
Line 1114 sub display_latex_exam {
|
Line 1110 sub display_latex_exam {
|
my $line = 0; |
my $line = 0; |
my $i = 0; |
my $i = 0; |
|
|
|
|
if ($direction eq 'horizontal') { |
if ($direction eq 'horizontal') { |
|
|
# Marshall the display text for each foil and turn things over to |
# Marshall the display text for each foil and turn things over to |
Line 1124 sub display_latex_exam {
|
Line 1120 sub display_latex_exam {
|
$result .= &Apache::caparesponse::make_horizontal_latex_bubbles( |
$result .= &Apache::caparesponse::make_horizontal_latex_bubbles( |
$whichfoils, \@foil_texts, '$\bigcirc$'); |
$whichfoils, \@foil_texts, '$\bigcirc$'); |
|
|
|
|
} else { |
} else { |
$result .= "\\begin{$venv}"; |
$result .= "\\begin{$venv}"; |
|
|