From 788f8d1fc6c9543407f4d0a9a52ffd072f60a405 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Mon, 16 Dec 2024 16:26:42 -0600 Subject: [PATCH] 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. --- macros/core/scaffold.pl | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/macros/core/scaffold.pl b/macros/core/scaffold.pl index f69b58c33..df34ff125 100644 --- a/macros/core/scaffold.pl +++ b/macros/core/scaffold.pl @@ -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 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 0 or 1 >>> This determines whether each section is automatically numbered before @@ -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 @@ -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;