diff --git a/lib/WeBWorK/AchievementItems/ReducedCred.pm b/lib/WeBWorK/AchievementItems/ReducedCred.pm index 089dbfe410..ee77b15ac3 100644 --- a/lib/WeBWorK/AchievementItems/ReducedCred.pm +++ b/lib/WeBWorK/AchievementItems/ReducedCred.pm @@ -20,9 +20,11 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures; # Reduced scoring needs to be enabled for this item to work. use WeBWorK::Utils qw(x nfreeze_base64 thaw_base64); -use WeBWorK::Utils::DateTime qw(between); +use WeBWorK::Utils::DateTime qw(after between); use WeBWorK::Utils::Sets qw(format_set_name_display); +use constant ONE_DAY => 86400; + sub new ($class) { return bless { id => 'ReducedCred', @@ -39,7 +41,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) { for my $i (0 .. $#$sets) { push(@openSets, [ format_set_name_display($sets->[$i]->set_id) => $sets->[$i]->set_id ]) - if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default'); + if (between($sets->[$i]->open_date, $sets->[$i]->due_date + ONE_DAY()) + && $sets->[$i]->assignment_type eq 'default'); } return unless @openSets; @@ -79,12 +82,24 @@ sub use_item ($self, $userName, $c) { my $userSet = $db->getUserSet($userName, $setID); return "Couldn't find that set!" unless $set && $userSet; - # Enable reduced scoring on the set and add the reduced scoring period to the due date. - my $additionalTime = 60 * $ce->{pg}{ansEvalDefaults}{reducedScoringPeriod}; + # Change the seed for all of the problems if the set is currently closed. + if (after($set->due_date)) { + my @probIDs = $db->listUserProblems($userName, $setID); + for my $probID (@probIDs) { + my $problem = $db->getUserProblem($userName, $setID, $probID); + $problem->problem_seed($problem->problem_seed + 100); + $db->putUserProblem($problem); + } + } + + # Either there is already a valid reduced scoring date, or set the reduced scoring date to the close date. + $userSet->reduced_scoring_date($set->due_date) + unless ($set->reduced_scoring_date && ($set->reduced_scoring_date < $set->due_date)); $userSet->enable_reduced_scoring(1); - $userSet->reduced_scoring_date($set->due_date()); - $userSet->due_date($set->due_date() + $additionalTime); - $userSet->answer_date($set->answer_date() + $additionalTime); + # Add time to the close date + $userSet->due_date($set->due_date + ONE_DAY()); + # This may require also extending the answer date. + $userSet->answer_date($userSet->due_date) if ($userSet->due_date > $set->answer_date); $db->putUserSet($userSet); $globalData->{ $self->{id} }--;