From 4f264797c2e7a39cf65cfdba2bc9d17b21f59aef Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Mon, 11 Dec 2023 20:08:20 -0600 Subject: [PATCH] Add a correct answer "reveal" option. This option makes it so that correct answers are not visible and the "Reveal" button must be clicked to show them even after answers are available for students. This was requested by @dlglin. --- conf/defaults.config | 17 ++++++++++++++++- lib/WeBWorK/ContentGenerator/GatewayQuiz.pm | 6 +++--- lib/WeBWorK/ContentGenerator/Problem.pm | 6 +++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/conf/defaults.config b/conf/defaults.config index ee511fabed..ea2124c959 100644 --- a/conf/defaults.config +++ b/conf/defaults.config @@ -206,14 +206,19 @@ $pg{options}{periodicRandomizationPeriod} = 5; $pg{options}{showCorrectOnRandomize} = 0; ############################################################################### -# automaticAnswerFeedback +# answer feedback options ################################################################################ + # If set to 1, then answer feedback is automatically shown when returning to an # answered problem or after answers are available for the assignment. This is # present in problems when a student opens the problem without the student # needing to click the "Check Answers" button. $pg{options}{automaticAnswerFeedback} = 1; +# If set to 1, then a "Reveal" button must be clicked to reveal correct answers +# even after the answer date. +$pg{options}{correctRevealBtnAlways} = 0; + ################################################################################ # Single Problem Grader ################################################################################ @@ -2065,6 +2070,16 @@ $ConfigValues = [ ), type => 'boolean' }, + { + var => 'pg{options}{correctRevealBtnAlways}', + doc => x('Show correct answer "Reveal" button always'), + doc2 => x( + 'A "Reveal" button must be clicked to make a correct answer visible any time that correct answers for ' + . ' a problem are shown. Note that this is always the case for instructors before answers are ' + . ' available to students, and in "Show Me Another" problems.' + ), + type => 'boolean' + } ], [ x('E-Mail'), diff --git a/lib/WeBWorK/ContentGenerator/GatewayQuiz.pm b/lib/WeBWorK/ContentGenerator/GatewayQuiz.pm index 9f558b9569..3d32d66071 100644 --- a/lib/WeBWorK/ContentGenerator/GatewayQuiz.pm +++ b/lib/WeBWorK/ContentGenerator/GatewayQuiz.pm @@ -1484,9 +1484,9 @@ async sub getProblemHTML ($c, $effectiveUser, $set, $formFields, $mergedProblem) && $c->can_showCorrectAnswersForAll($set, $c->{problem}, $c->{tmplSet})), showMessages => 1, showCorrectAnswers => ( - $c->{will}{showProblemGrader} - || (!$c->{previewAnswers} && $c->can_showCorrectAnswersForAll($set, $c->{problem}, $c->{tmplSet})) - ? 2 + $c->{will}{showProblemGrader} ? 2 + : !$c->{previewAnswers} && $c->can_showCorrectAnswersForAll($set, $c->{problem}, $c->{tmplSet}) + ? ($c->ce->{pg}{options}{correctRevealBtnAlways} ? 1 : 2) : ($c->{submitAnswers} || $c->{will}{checkAnswers}) && $c->{will}{showCorrectAnswers} ? 1 : 0 ), diff --git a/lib/WeBWorK/ContentGenerator/Problem.pm b/lib/WeBWorK/ContentGenerator/Problem.pm index 97ba196122..b7e629673c 100644 --- a/lib/WeBWorK/ContentGenerator/Problem.pm +++ b/lib/WeBWorK/ContentGenerator/Problem.pm @@ -597,9 +597,9 @@ async sub pre_header_initialize ($c) { && after($c->{set}->answer_date, $c->submitTime)), showMessages => 1, showCorrectAnswers => ( - $will{showProblemGrader} - || (!$c->{previewAnswers} && after($c->{set}->answer_date, $c->submitTime)) - || ($c->{submitAnswers} && $c->{showCorrectOnRandomize}) ? 2 + $will{showProblemGrader} || ($c->{submitAnswers} && $c->{showCorrectOnRandomize}) ? 2 + : !$c->{previewAnswers} && after($c->{set}->answer_date, $c->submitTime) + ? ($ce->{pg}{options}{correctRevealBtnAlways} ? 1 : 2) : (($c->{submitAnswers} || $will{checkAnswers}) && $will{showCorrectAnswers}) ? 1 : 0 ),