diff --git a/lib/WeBWorK/AchievementItems/ExtendDueDate.pm b/lib/WeBWorK/AchievementItems/ExtendDueDate.pm index f20aba7474..f645c59734 100644 --- a/lib/WeBWorK/AchievementItems/ExtendDueDate.pm +++ b/lib/WeBWorK/AchievementItems/ExtendDueDate.pm @@ -19,14 +19,19 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures; # Item to extend a close date by 24 hours. 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 => 'ExtendDueDate', name => x('Tunic of Extension'), - description => x('Adds 24 hours to the close date of a homework.') + description => x( + 'Adds 24 hours to the close date of a homework. ' + . 'This will randomize problem details if used after the original close date.' + ) }, $class; } @@ -35,7 +40,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; @@ -71,10 +77,20 @@ sub use_item ($self, $userName, $c) { my $userSet = $db->getUserSet($userName, $setID); return q{Couldn't find that set!} unless $set && $userSet; - # Add time to the reduced scoring date, due date, and answer date. - $userSet->reduced_scoring_date($set->reduced_scoring_date() + 86400) if $set->reduced_scoring_date; - $userSet->due_date($set->due_date() + 86400); - $userSet->answer_date($set->answer_date() + 86400); + # Change the seed for all of the problems if the set is currently closed. + if (after($set->due_date)) { + for my $problem ($db->getUserProblemsWhere({ user_id => $userName, set_id => $setID })) { + $problem->problem_seed($problem->problem_seed % 2**31 + 1); + $db->putUserProblem($problem); + } + } + + # Add time to the reduced scoring date if it was defined in the first place + $userSet->reduced_scoring_date($set->reduced_scoring_date + ONE_DAY) if $set->reduced_scoring_date; + # 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} }--; diff --git a/lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm b/lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm index 3d99f661f7..cccefc6f12 100644 --- a/lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm +++ b/lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm @@ -22,6 +22,8 @@ use WeBWorK::Utils qw(x nfreeze_base64 thaw_base64); use WeBWorK::Utils::DateTime qw(between); use WeBWorK::Utils::Sets qw(format_set_name_display); +use constant ONE_DAY => 86400; + sub new ($class) { return bless { id => 'ExtendDueDateGW', @@ -78,10 +80,10 @@ sub use_item ($self, $userName, $c) { return q{Couldn't find that set!} unless $set && $userSet; # Add time to the reduced scoring date, due date, and answer date. - $userSet->reduced_scoring_date($set->reduced_scoring_date() + 86400) + $userSet->reduced_scoring_date($set->reduced_scoring_date() + ONE_DAY) if defined($set->reduced_scoring_date()) && $set->reduced_scoring_date(); - $userSet->due_date($set->due_date() + 86400); - $userSet->answer_date($set->answer_date() + 86400); + $userSet->due_date($set->due_date() + ONE_DAY); + $userSet->answer_date($set->answer_date() + ONE_DAY); $db->putUserSet($userSet); # Add time to the reduced scoring date, due date, and answer date for all versions. @@ -89,10 +91,10 @@ sub use_item ($self, $userName, $c) { for my $version (@versions) { $set = $db->getSetVersion($userName, $setID, $version); - $set->reduced_scoring_date($set->reduced_scoring_date() + 86400) + $set->reduced_scoring_date($set->reduced_scoring_date() + ONE_DAY) if defined($set->reduced_scoring_date()) && $set->reduced_scoring_date(); - $set->due_date($set->due_date() + 86400); - $set->answer_date($set->answer_date() + 86400); + $set->due_date($set->due_date() + ONE_DAY); + $set->answer_date($set->answer_date() + ONE_DAY); $db->putSetVersion($set); } diff --git a/lib/WeBWorK/AchievementItems/ReducedCred.pm b/lib/WeBWorK/AchievementItems/ReducedCred.pm index 9ff714ecb8..297c275d7e 100644 --- a/lib/WeBWorK/AchievementItems/ReducedCred.pm +++ b/lib/WeBWorK/AchievementItems/ReducedCred.pm @@ -20,16 +20,19 @@ 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', name => x('Ring of Reduction'), description => x( 'Enable reduced scoring for a homework set. This will allow you to submit answers ' - . 'for partial credit for 24 hours after the close date.' + . 'for partial credit for 24 hours after the close date. ' + . 'This will randomize problem details if used after the original close date.' ) }, $class; } @@ -39,7 +42,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 +83,22 @@ 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)) { + for my $problem ($db->getUserProblemsWhere({ user_id => $userName, set_id => $setID })) { + $problem->problem_seed($problem->problem_seed % 2**31 + 1); + $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} }--; diff --git a/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm b/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm index 28ee31a660..ccf960321d 100644 --- a/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm +++ b/lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm @@ -19,14 +19,19 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures; # Item to extend a close date by 48 hours. 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 TWO_DAYS => 172800; + sub new ($class) { return bless { id => 'SuperExtendDueDate', name => x('Robe of Longevity'), - description => x('Adds 48 hours to the close date of a homework.') + description => x( + 'Adds 48 hours to the close date of a homework. ' + . 'This will randomize problem details if used after the original close date.' + ) }, $class; } @@ -35,7 +40,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 + TWO_DAYS) + && $sets->[$i]->assignment_type eq 'default'); } return unless @openSets; @@ -71,10 +77,20 @@ sub use_item ($self, $userName, $c) { my $userSet = $db->getUserSet($userName, $setID); return q{Couldn't find that set!} unless $set && $userSet; - # Add time to the reduced scoring date, due date, and answer date. - $userSet->reduced_scoring_date($set->reduced_scoring_date() + 172800) if $set->reduced_scoring_date; - $userSet->due_date($set->due_date() + 172800); - $userSet->answer_date($set->answer_date() + 172800); + # Change the seed for all of the problems if the set is currently closed. + if (after($set->due_date)) { + for my $problem ($db->getUserProblemsWhere({ user_id => $userName, set_id => $setID })) { + $problem->problem_seed($problem->problem_seed % 2**31 + 1); + $db->putUserProblem($problem); + } + } + + # Add time to the reduced scoring date if it was defined in the first place + $userSet->reduced_scoring_date($set->reduced_scoring_date + TWO_DAYS) if $set->reduced_scoring_date; + # Add time to the close date + $userSet->due_date($set->due_date + TWO_DAYS); + # 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} }--;