Skip to content

Commit 94f971b

Browse files
committed
Add a scaffold preview_can_change_state option that determines behavior 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.
1 parent ab50953 commit 94f971b

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

macros/core/scaffold.pl

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ =head1 DESCRIPTION
184184
have the student open it by hand before anwering the questions. In
185185
this case, set this value to 0 (it is 1 by default).
186186
187+
=item C<S<< preview_can_change_state => 0 or 1 >>
188+
189+
This determines if scaffold state can be changed when a preview occurs
190+
(i.e., when the "Preview My Answers" button is used). If this is 0,
191+
then when a preview occurs any scaffold sections that were open before
192+
the preview will remain open, and any scaffold sections that were closed
193+
before the preview will remain closed. If this is 1, then the rules
194+
described above will be applied using the scores of the answers in the
195+
parts. This is 1 by default.
196+
187197
=item C<S<< numbered => 0 or 1 >>>
188198
189199
This determines whether each section is automatically numbered before
@@ -353,6 +363,7 @@ sub new {
353363
hardcopy_is_open => "always", # open all possible sections in hardcopy
354364
open_first_section => 1, # 0 means don't open any sections initially
355365
numbered => 0, # 1 means sections will be printed with their number
366+
preview_can_change_state => 1,
356367
%options,
357368
number => ++$scaffold_no, # the number for this scaffold
358369
depth => $scaffold_depth, # the nesting depth for this scaffold
@@ -536,16 +547,24 @@ sub add_container {
536547
# Nothing needs to be done for the PTX display mode.
537548
return if $Scaffold::isPTX;
538549

550+
my $scaffoldScores = main::persistent_data('_scaffold_scores') // {};
551+
539552
# Provide a "scaffold_force" option in the AnswerHash that can be used to force
540553
# Scaffold to consider the score to be 1. This is used by PGessaymacros.pl.
554+
# Also, if answers are being previewed and the preview_can_change_state option is 0, then use the scores saved
555+
# in the persistent data hash form the last answer submission (if there is no data for an answer, then the
556+
# anwser is considered blank).
541557
for (@{ $self->{ans_names} }) {
542558
next unless defined $PG_ANSWERS_HASH->{$_};
543-
$scaffold->{scores}{$_} =
544-
$PG_ANSWERS_HASH->{$_}{ans_eval}{rh_ans}{scaffold_force}
545-
? 1
559+
$scaffold->{scores}{$_} = $scaffoldScores->{$_} =
560+
$PG_ANSWERS_HASH->{$_}{ans_eval}{rh_ans}{scaffold_force} ? 1
561+
: !$scaffold->{preview_can_change_state} && $PG_ANSWERS_HASH->{$_}{ans_eval}{rh_ans}{isPreview}
562+
? $scaffoldScores->{$_}
546563
: $PG_ANSWERS_HASH->{$_}{ans_eval}{rh_ans}{score};
547564
}
548565

566+
main::persistent_data(_scaffold_scores => $scaffoldScores);
567+
549568
# Set the active scaffold to the scaffold for this section so that is_correct, can_open,
550569
# and is_open methods use the correct one.
551570
$Scaffold::scaffold = $scaffold;

0 commit comments

Comments
 (0)