From d7778a2d0bea138649dcdfd86d8f5b7e3cf593f6 Mon Sep 17 00:00:00 2001 From: Nathan Wallach Date: Thu, 20 Apr 2023 17:09:01 +0300 Subject: [PATCH] Allow hiding the the structure of a MultiAnswer answer during preview by setting boolean scaffold_past_open in the rh_ans hash of all answers in sections which were past the last open one. --- macros/core/scaffold.pl | 4 ++++ macros/parsers/parserMultiAnswer.pl | 23 ++++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/macros/core/scaffold.pl b/macros/core/scaffold.pl index d8191952f6..83bf22b8ff 100644 --- a/macros/core/scaffold.pl +++ b/macros/core/scaffold.pl @@ -463,6 +463,10 @@ sub section_answers { if $answers{$name} && (($answers{$name}{type} || "") eq "essay" || $answers{$name}{"scaffold_force"}); $evaluator->{rh_ans}{ans_message} = ""; delete $evaluator->{rh_ans}{error_message}; + # In sections which are not yet open, make that known to answer + # evaluators. For MultiAnswer using a single result, this allows + # hiding the structure of the answer during a preview. + $PG_ANSWERS_HASH->{$name}{ans_eval}{rh_ans}{scaffold_past_open} = 1 if ($section_no > $prior_last_open); } my $myLastSet; # we save the name of the last answer field whose score was set diff --git a/macros/parsers/parserMultiAnswer.pl b/macros/parsers/parserMultiAnswer.pl index 3d1af6e841..75f5cf43d4 100644 --- a/macros/parsers/parserMultiAnswer.pl +++ b/macros/parsers/parserMultiAnswer.pl @@ -292,6 +292,10 @@ sub single_check { $ans->{_filter_name} = "MultiAnswer Single Check"; my $inputs = $main::inputs_ref; $self->{ans}[0] = $self->{cmp}[0]->evaluate($ans->{student_ans}); + # Allow hiding the the structure of the answer for an + # answer in an unopened part of a scaffold problem. + my $hide_preview = 0; + $hide_preview = 1 if ($ans->{scaffold_past_open}); foreach my $i (1 .. $self->length - 1) { $self->{ans}[$i] = $self->{cmp}[$i]->evaluate($inputs->{ $self->ANS_NAME($i) }); } @@ -328,13 +332,18 @@ sub single_check { . ''; } if ($nonblank) { - $ans->{preview_latex_string} = - ( - defined($self->{tex_format}) - ? sprintf($self->{tex_format}, @latex) - : join($self->{tex_separator}, @latex)); - $ans->{preview_text_string} = - (defined($self->{format}) ? sprintf($self->{format}, @text) : join($self->{separator}, @text)); + if ($hide_preview) { + $ans->{preview_latex_string} = ""; + $ans->{preview_text_string} = ""; + } else { + $ans->{preview_latex_string} = + ( + defined($self->{tex_format}) + ? sprintf($self->{tex_format}, @latex) + : join($self->{tex_separator}, @latex)); + $ans->{preview_text_string} = + (defined($self->{format}) ? sprintf($self->{format}, @text) : join($self->{separator}, @text)); + } $ans->{student_ans} = (defined($self->{format}) ? sprintf($self->{format}, @student) : join($self->{separator}, @student)); }