Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions lib/WeBWorK/ContentGenerator/Problem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -480,22 +480,28 @@ async sub initialize ($c) {
if (defined $problem->{prPeriod} && $problem->{prPeriod} > -1);

$prEnabled = 0 if ($rerandomizePeriod < 1 || $c->{editMode});

my $canUpdateProblemRandomization = $userID eq $effectiveUserID
|| $authz->hasPermissions($userID, 'record_answers_when_acting_as_student');

if ($prEnabled) {
$problem->{prCount} = 0
if !defined $problem->{prCount} || $problem->{prCount} =~ /^\s*$/;

$problem->{prCount} += $c->{submitAnswers} ? 1 : 0;
$problem->{prCount} += $c->{submitAnswers} && $canUpdateProblemRandomization ? 1 : 0;

$requestNewSeed = 0
if ($problem->{prCount} < $rerandomizePeriod || after($c->{set}->due_date, $c->submitTime));
if (!$canUpdateProblemRandomization
|| $problem->{prCount} < $rerandomizePeriod
|| after($c->{set}->due_date, $c->submitTime));

if ($requestNewSeed) {
# obtain new random seed to hopefully change the problem
$problem->{problem_seed} =
($problem->{problem_seed} + $problem->num_correct + $problem->num_incorrect) % 10000;
$problem->{prCount} = 0;
}
if ($problem->{prCount} > -1) {
if ($canUpdateProblemRandomization && $problem->{prCount} > -1) {
my $pureProblem = $db->getUserProblem($problem->user_id, $problem->set_id, $problem->problem_id);
$pureProblem->problem_seed($problem->{problem_seed});
$pureProblem->prCount($problem->{prCount});
Expand All @@ -507,9 +513,11 @@ async sub initialize ($c) {
my %will = map { $_ => $can{$_} && $want{$_} } keys %can;

if ($prEnabled && $problem->{prCount} >= $rerandomizePeriod && !after($c->{set}->due_date, $c->submitTime)) {
$can{requestNewSeed} = 1;
$c->{newVersionRequired} = 1;
$can{requestNewSeed} = $canUpdateProblemRandomization;
$want{requestNewSeed} = 1;
$will{requestNewSeed} = 1;
$will{requestNewSeed} = $canUpdateProblemRandomization;
$can{getSubmitButton} = 0;
$c->{showCorrectOnRandomize} = $ce->{pg}{options}{showCorrectOnRandomize};
# If this happens, it means that the page was refreshed. So prevent the answers from
# being recorded and the number of attempts from being increased.
Expand Down Expand Up @@ -1015,7 +1023,7 @@ sub output_score_summary ($c) {

my $prMessage = '';
if ($prEnabled) {
my $attempts_before_rr = $c->{will}{requestNewSeed} ? 0 : ($rerandomizePeriod - $problem->{prCount});
my $attempts_before_rr = $c->{newVersionRequired} ? 0 : ($rerandomizePeriod - $problem->{prCount});

$prMessage = ' '
. $c->maketext('You have [quant,_1,attempt,attempts] left before new version will be requested.',
Expand Down
21 changes: 16 additions & 5 deletions lib/WeBWorK/ContentGenerator/ShowMeAnother.pm
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ async sub initialize ($c) {
|| have_different_answers($showMeAnotherNewPG, $showMeAnotherOriginalPG))
{
# Increment the counter detailing the number of times showMeAnother has been used,
# and update the database.
my $userProblem =
$db->getUserProblem($c->{effectiveUserID}, $c->stash('setID'), $c->stash('problemID'));
$userProblem->{showMeAnotherCount} = ++$c->{showMeAnother}{Count};
$db->putUserProblem($userProblem);
# and update the database unless acting as another user.
if ($c->{userID} eq $c->{effectiveUserID}) {
my $userProblem =
$db->getUserProblem($c->{effectiveUserID}, $c->stash('setID'), $c->stash('problemID'));
$userProblem->{showMeAnotherCount} = ++$c->{showMeAnother}{Count};
$db->putUserProblem($userProblem);
}

# Save the problem seed from ShowMeAnother so that it can be used when the page reloads.
$c->authen->session->{showMeAnother}{problemSeed} = $newProblemSeed;
Expand All @@ -158,6 +160,8 @@ async sub initialize ($c) {
$c->{can}{recordAnswers} = 0;
$c->{can}{checkAnswers} = 0; # This is turned on if the showMeAnother conditions are met below.
$c->{can}{getSubmitButton} = 0;
$c->{can}{requestNewSeed} = 0;
$c->{newVersionRequired} = 0;

if ($c->stash->{isPossible}) {
$c->{can}{showCorrectAnswers} =
Expand Down Expand Up @@ -287,6 +291,13 @@ sub output_comments ($c) { return '' }
sub output_grader ($c) { return '' }
sub nav ($c, $args) { return '' }

# Past answers are for the original problem, not this version.
sub output_past_answer_button ($c) { return '' }

# The problem seed for this version is only stored in the user's session, so a link in a
# feedback email can not take the instructor to this version of the problem.
sub output_email_instructor ($c) { return '' }

# Outputs the summary of the questions that the student has answered for the
# current problem, along with available information about correctness.
sub output_summary ($c) {
Expand Down
9 changes: 8 additions & 1 deletion templates/ContentGenerator/Problem/submit_buttons.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
% my %can = %{ $c->{can} };
% my %will = %{ $c->{will} };
% my $effectiveUser = param('effectiveUser');
% if ($will{requestNewSeed}) {
% if ($will{requestNewSeed} && $authen->{user_id} eq $effectiveUser) {
<%= submit_button maketext('Request New Version'),
id => 'enter_key_submit',
name => 'requestNewSeed',
Expand Down Expand Up @@ -59,6 +59,13 @@
class => 'btn btn-primary mb-1' =%>
% }
%
% if ($will{requestNewSeed}) {
<%= submit_button maketext('Request New Version for [_1]', $effectiveUser),
id => 'submitAnswers_id',
name => 'requestNewSeed',
class => 'btn btn-primary mb-1' =%>
% }
%
% if ($can{getSubmitButton}) {
% if ($authen->{user_id} ne $effectiveUser) {
% # If acting as a student, make it clear that answer submissions will
Expand Down