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
1 change: 1 addition & 0 deletions conf/defaults.config
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ $achievementPointsPerProblem = 5;
$achievementPointsPerProblemReduced = 3;
$achievementPreambleFile = "preamble.at";
$achievementExcludeSet = [];
$achievementExtensionFactor = 1;
$mail{achievementEmailFrom} = '';
$showCourseHomeworkTotals = 1;

Expand Down
2 changes: 1 addition & 1 deletion lib/WeBWorK/AchievementItems.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ sub UserItems ($c, $userName, $set, $records) {

for my $item (@{ +ITEMS }) {
next unless $globalData->{$item};
my $achievementItem = "WeBWorK::AchievementItems::$item"->new;
my $achievementItem = "WeBWorK::AchievementItems::$item"->new($c);
$achievementItem->{count} = $globalData->{$item};

# Return list of achievements items if $set is not defined.
Expand Down
12 changes: 7 additions & 5 deletions lib/WeBWorK/AchievementItems/AddNewTestGW.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;
use WeBWorK::Utils qw(x);
use WeBWorK::Utils::DateTime qw(between);

sub new ($class) {
sub new ($class, $c) {
Comment thread
drgrice1 marked this conversation as resolved.
return bless {
id => 'AddNewTestGW',
name => x('Oil of Cleansing'),
description => x(
'Unlock an additional version of a test. If used before the close date of '
. 'the test this will allow you to generate a new version of the test.'
)
description => [
x(
'Unlock an additional version of a test. If used before the close date of '
. 'the test this will allow you to generate a new version of the test.'
)
]
}, $class;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/WeBWorK/AchievementItems/DoubleProb.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;
use WeBWorK::Utils qw(x);
use WeBWorK::Utils::DateTime qw(after);

sub new ($class) {
sub new ($class, $c) {
return bless {
id => 'DoubleProb',
name => x('Cupcake of Enlargement'),
description => x('Causes a single homework problem to be worth twice as much.')
description => [ x('Causes a single homework problem to be worth twice as much.') ]
}, $class;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/WeBWorK/AchievementItems/DoubleSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;
use WeBWorK::Utils qw(x);
use WeBWorK::Utils::DateTime qw(after);

sub new ($class) {
sub new ($class, $c) {
return bless {
id => 'DoubleSet',
name => x('Cake of Enlargement'),
description => x('Cause the selected homework set to count for twice as many points as it normally would.')
description =>
[ x('Cause the selected homework set to count for twice as many points as it normally would.') ]
}, $class;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/WeBWorK/AchievementItems/DuplicateProb.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;
use WeBWorK::Utils qw(x);
use WeBWorK::Utils::DateTime qw(between);

sub new ($class) {
sub new ($class, $c) {
return bless {
id => 'DuplicateProb',
name => x('Box of Transmogrification'),
description => x('Causes a homework problem to become a clone of another problem from the same set.')
description => [ x('Causes a homework problem to become a clone of another problem from the same set.') ]
}, $class;
}

Expand Down
57 changes: 34 additions & 23 deletions lib/WeBWorK/AchievementItems/ExtendDueDate.pm
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
package WeBWorK::AchievementItems::ExtendDueDate;
use Mojo::Base 'WeBWorK::AchievementItems', -signatures;

# Item to extend a close date by 24 hours.
# Item to extend a close date by 24 * $achievementExtensionFactor hours.

use WeBWorK::Utils qw(x);
use WeBWorK::Utils::DateTime qw(before after between);
use WeBWorK::Utils::DateTime qw(before after between getExtensionTime);

use constant ONE_DAY => 86400;
sub new ($class, $c) {
my ($time, $timeText) = getExtensionTime($c, 1);

sub new ($class) {
return bless {
id => 'ExtendDueDate',
name => x('Tunic of Extension'),
description => x(
'Adds 24 hours to the close date of a homework. '
. 'This will randomize problem details if used after the original close date.'
)
description => [
x(
'Adds [_1] to the close date of a homework. '
. 'This will randomize problem details if used after the original close date.',
$timeText
)
],
time => $time,
timeText => $timeText
}, $class;
}

sub can_use ($self, $set, $records, $c) {
return $set->assignment_type eq 'default' && between($set->open_date, $set->due_date + ONE_DAY);
return $set->assignment_type eq 'default' && between($set->open_date, $set->due_date + $self->{time});
}

sub print_form ($self, $set, $records, $c) {
my $randomization_statement = after($set->due_date) ? $c->maketext('All problems will be rerandomized.') : '';
if ($set->enable_reduced_scoring) {
if (before($set->reduced_scoring_date + ONE_DAY)) {
if (before($set->reduced_scoring_date + $self->{time})) {
return $c->c(
$c->tag('p', $c->maketext('Extend the deadline by 24 hours. [_1]', $randomization_statement)),
$c->tag(
'p',
$c->maketext('Extend the deadline by [_1]. [_2]', $self->{timeText}, $randomization_statement)
),
$c->tag(
'ul',
$c->c(
Expand All @@ -37,7 +45,7 @@ sub print_form ($self, $set, $records, $c) {
$c->maketext(
'You will be able to receive full credit until [_1].',
$c->formatDateTime(
$set->reduced_scoring_date + ONE_DAY,
$set->reduced_scoring_date + $self->{time},
$c->ce->{studentDateDisplayFormat}
)
)
Expand All @@ -46,7 +54,10 @@ sub print_form ($self, $set, $records, $c) {
'li',
$c->maketext(
'You will be able to receive reduced credit until [_1].',
$c->formatDateTime($set->due_date + ONE_DAY, $c->ce->{studentDateDisplayFormat})
$c->formatDateTime(
$set->due_date + $self->{time},
$c->ce->{studentDateDisplayFormat}
)
)
)
)->join('')
Expand All @@ -57,8 +68,9 @@ sub print_form ($self, $set, $records, $c) {
$c->tag(
'p',
$c->maketext(
'Extend the reduced credit deadline of this assignment to [_1] (an additional 24 hours). [_2]',
$c->formatDateTime($set->due_date + ONE_DAY, $c->ce->{studentDateDisplayFormat}),
'Extend the reduced credit deadline of this assignment to [_1] (an additional [_2]). [_3]',
$c->formatDateTime($set->due_date + $self->{time}, $c->ce->{studentDateDisplayFormat}),
$self->{timeText},
$randomization_statement
)
),
Expand All @@ -76,8 +88,9 @@ sub print_form ($self, $set, $records, $c) {
return $c->tag(
'p',
$c->maketext(
'Extend the close date of this assignment to [_1] (an additional 24 hours). [_2]',
$c->formatDateTime($set->due_date + ONE_DAY, $c->ce->{studentDateDisplayFormat}),
'Extend the close date of this assignment to [_1] (an additional [_2]). [_3]',
$c->formatDateTime($set->due_date + $self->{time}, $c->ce->{studentDateDisplayFormat}),
$self->{timeText},
$randomization_statement
)
);
Expand All @@ -104,11 +117,11 @@ sub use_item ($self, $set, $records, $c) {

# Add time to the reduced scoring date if it was defined in the first place
if ($set->reduced_scoring_date) {
$set->reduced_scoring_date($set->reduced_scoring_date + ONE_DAY);
$set->reduced_scoring_date($set->reduced_scoring_date + $self->{time});
$userSet->reduced_scoring_date($set->reduced_scoring_date);
}
# Add time to the close date
$set->due_date($set->due_date + ONE_DAY);
$set->due_date($set->due_date + $self->{time});
$userSet->due_date($set->due_date);
# This may require also extending the answer date.
if ($set->due_date > $set->answer_date) {
Expand All @@ -117,10 +130,8 @@ sub use_item ($self, $set, $records, $c) {
}
$db->putUserSet($userSet);

return $c->maketext(
'Close date of this assignment extended by 24 hours to [_1].',
$c->formatDateTime($set->due_date, $c->ce->{studentDateDisplayFormat})
);
return $c->maketext('Close date of this assignment extended by [_1] to [_2].',
$self->{timeText}, $c->formatDateTime($set->due_date, $c->ce->{studentDateDisplayFormat}));
}

1;
49 changes: 28 additions & 21 deletions lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,32 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;
# Item to extend the close date on a test

use WeBWorK::Utils qw(x);
use WeBWorK::Utils::DateTime qw(before between);
use WeBWorK::Utils::DateTime qw(before between getExtensionTime);

use constant ONE_DAY => 86400;
sub new ($class, $c) {
my ($time, $timeText) = getExtensionTime($c, 1);

sub new ($class) {
return bless {
id => 'ExtendDueDateGW',
name => x('Amulet of Extension'),
description => x('Extends the close date of a test by 24 hours.')
description => [ x('Extends the close date of a test by [_1].', $timeText) ],
time => $time,
timeText => $timeText,
}, $class;
}

sub can_use ($self, $set, $records, $c) {
return
$set->assignment_type =~ /gateway/
&& $set->set_id !~ /,v\d+$/
&& between($set->open_date, $set->due_date + ONE_DAY);
&& between($set->open_date, $set->due_date + $self->{time});
}

sub print_form ($self, $set, $records, $c) {
if ($set->enable_reduced_scoring) {
if (before($set->reduced_scoring_date + ONE_DAY)) {
if (before($set->reduced_scoring_date + $self->{time})) {
return $c->c(
$c->tag('p', $c->maketext('Extend the deadline by 24 hours.')),
$c->tag('p', $c->maketext('Extend the deadline by [_1].', $self->{timeText})),
$c->tag(
'ul',
$c->c(
Expand All @@ -36,7 +38,7 @@ sub print_form ($self, $set, $records, $c) {
$c->maketext(
'You will be able to receive full credit until [_1].',
$c->formatDateTime(
$set->reduced_scoring_date + ONE_DAY,
$set->reduced_scoring_date + $self->{time},
$c->ce->{studentDateDisplayFormat}
)
)
Expand All @@ -45,7 +47,10 @@ sub print_form ($self, $set, $records, $c) {
'li',
$c->maketext(
'You will be able to receive reduced credit until [_1].',
$c->formatDateTime($set->due_date + ONE_DAY, $c->ce->{studentDateDisplayFormat})
$c->formatDateTime(
$set->due_date + $self->{time},
$c->ce->{studentDateDisplayFormat}
)
)
)
)->join('')
Expand All @@ -56,8 +61,9 @@ sub print_form ($self, $set, $records, $c) {
$c->tag(
'p',
$c->maketext(
'Extend the reduced credit deadline of this assignment to [_1] (an additional 24 hours).',
$c->formatDateTime($set->due_date + ONE_DAY, $c->ce->{studentDateDisplayFormat})
'Extend the reduced credit deadline of this assignment to [_1] (an additional [_2]).',
$c->formatDateTime($set->due_date + $self->{time}, $c->ce->{studentDateDisplayFormat}),
$self->{timeText}
)
),
$c->tag(
Expand All @@ -74,8 +80,9 @@ sub print_form ($self, $set, $records, $c) {
return $c->tag(
'p',
$c->maketext(
'Extend the close date of this assignment to [_1] (an additional 24 hours).',
$c->formatDateTime($set->due_date + ONE_DAY, $c->ce->{studentDateDisplayFormat})
'Extend the close date of this assignment to [_1] (an additional [_2]).',
$c->formatDateTime($set->due_date + $self->{time}, $c->ce->{studentDateDisplayFormat}),
$self->{timeText}
)
);
}
Expand All @@ -87,12 +94,12 @@ sub use_item ($self, $set, $records, $c) {

# Add time to the reduced scoring date, due date, and answer date.
if ($set->reduced_scoring_date) {
$set->reduced_scoring_date($set->reduced_scoring_date + ONE_DAY);
$set->reduced_scoring_date($set->reduced_scoring_date + $self->{time});
$userSet->reduced_scoring_date($set->reduced_scoring_date);
}
$set->due_date($set->due_date + ONE_DAY);
$set->due_date($set->due_date + $self->{time});
$userSet->due_date($set->due_date);
$set->answer_date($set->answer_date + ONE_DAY);
$set->answer_date($set->answer_date + $self->{time});
$userSet->answer_date($set->answer_date);
$db->putUserSet($userSet);

Expand All @@ -102,15 +109,15 @@ sub use_item ($self, $set, $records, $c) {
#my @versions = $db->listSetVersions($userName, $setID);
#for my $version (@versions) {
# $set = $db->getSetVersion($userName, $setID, $version);
# $set->reduced_scoring_date($set->reduced_scoring_date() + ONE_DAY)
# $set->reduced_scoring_date($set->reduced_scoring_date() + $self->{time})
# if defined($set->reduced_scoring_date()) && $set->reduced_scoring_date();
# $set->due_date($set->due_date() + ONE_DAY);
# $set->answer_date($set->answer_date() + ONE_DAY);
# $set->due_date($set->due_date() + $self->{time});
# $set->answer_date($set->answer_date() + $self->{time});
# $db->putSetVersion($set);
#}

return $c->maketext('Close date of this test extended by 24 hours to [_1].',
$c->formatDateTime($set->due_date, $c->ce->{studentDateDisplayFormat}));
return $c->maketext('Close date of this test extended by [_1] to [_2].',
$self->{timeText}, $c->formatDateTime($set->due_date, $c->ce->{studentDateDisplayFormat}));
}

1;
Loading
Loading