Skip to content

Commit

Permalink
Allow hiding the the structure of a MultiAnswer answer during
Browse files Browse the repository at this point in the history
preview by setting boolean scaffold_past_open in the rh_ans
hash of all answers in sections which were past the last open
one.
  • Loading branch information
taniwallach committed Apr 22, 2023
1 parent 18d56d9 commit d7778a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions macros/core/scaffold.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 16 additions & 7 deletions macros/parsers/parserMultiAnswer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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) });
}
Expand Down Expand Up @@ -328,13 +332,18 @@ sub single_check {
. '</TABLE>';
}
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));
}
Expand Down

0 comments on commit d7778a2

Please sign in to comment.