Skip to content

Commit

Permalink
Add a scaffold preview_can_change_state option that determines beha…
Browse files Browse the repository at this point in the history
…vior when preview is used.

The default value is 1, and in that case scaffolds will continue to
behave as they currently do.  If this option is set to 0, then when an
answer preview occurs, the scaffold state will remain the same as before
the preview occured.  Opened scaffolds will stay open, closed scaffolds
will stay closed, and scaffolds that could't be opened still can't be
opened.  Note this refers to the initial open/closed state when the
problem loads, and does not respect opening or closing of scaffolds
(that can be opened or closed) by the user.

This uses the persistence hash to store the state. Note that state is
really the scores for all answers in scaffold sections.  It is important
to note that state is usually not saved by the frontend until an answer
submission occurs (although it is saved in a hidden form field for
instructors), and if there is no state, then it assumes the problem is
in its initial state, and uses scores of 0 for all answers.
  • Loading branch information
drgrice1 committed Dec 18, 2024
1 parent 1936e20 commit 788f8d1
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions macros/core/scaffold.pl
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,16 @@ =head1 DESCRIPTION
have the student open it by hand before anwering the questions. In
this case, set this value to 0 (it is 1 by default).
=item C<S<< preview_can_change_state => 0 or 1 >>
This determines if scaffold state can be changed when a preview occurs
(i.e., when the "Preview My Answers" button is used). If this is 0,
then when a preview occurs any scaffold sections that were open before
the preview will remain open, and any scaffold sections that were closed
before the preview will remain closed. If this is 1, then the rules
described above will be applied using the scores of the answers in the
parts. This is 1 by default.
=item C<S<< numbered => 0 or 1 >>>
This determines whether each section is automatically numbered before
Expand Down Expand Up @@ -353,6 +363,7 @@ sub new {
hardcopy_is_open => "always", # open all possible sections in hardcopy
open_first_section => 1, # 0 means don't open any sections initially
numbered => 0, # 1 means sections will be printed with their number
preview_can_change_state => 1,
%options,
number => ++$scaffold_no, # the number for this scaffold
depth => $scaffold_depth, # the nesting depth for this scaffold
Expand Down Expand Up @@ -536,16 +547,24 @@ sub add_container {
# Nothing needs to be done for the PTX display mode.
return if $Scaffold::isPTX;

my $scaffoldScores = main::persistent_data('_scaffold_scores') // {};

# Provide a "scaffold_force" option in the AnswerHash that can be used to force
# Scaffold to consider the score to be 1. This is used by PGessaymacros.pl.
# Also, if answers are being previewed and the preview_can_change_state option is 0, then use the scores saved
# in the persistent data hash form the last answer submission (if there is no data for an answer, then the
# anwser is considered blank).
for (@{ $self->{ans_names} }) {
next unless defined $PG_ANSWERS_HASH->{$_};
$scaffold->{scores}{$_} =
$PG_ANSWERS_HASH->{$_}{ans_eval}{rh_ans}{scaffold_force}
? 1
$scaffold->{scores}{$_} = $scaffoldScores->{$_} =
$PG_ANSWERS_HASH->{$_}{ans_eval}{rh_ans}{scaffold_force} ? 1
: !$scaffold->{preview_can_change_state} && $PG_ANSWERS_HASH->{$_}{ans_eval}{rh_ans}{isPreview}
? $scaffoldScores->{$_}
: $PG_ANSWERS_HASH->{$_}{ans_eval}{rh_ans}{score};
}

main::persistent_data(_scaffold_scores => $scaffoldScores);

# Set the active scaffold to the scaffold for this section so that is_correct, can_open,
# and is_open methods use the correct one.
$Scaffold::scaffold = $scaffold;
Expand Down

0 comments on commit 788f8d1

Please sign in to comment.