Skip to content

Commit 65fc09c

Browse files
committed
Add extension time factor setting.
Add `$achievementExtensionFactor` setting that is used to configure the length of extensions. This works as a multiplicative factor, by multiplying the base time (either 24 or 48 hours) by the factor. The extension time is always rounded to the nearest hour, and cannot be less than a single hour (two hours for the super extensions). This affects all items that have an extension time. * ExtendDueDate * ExtendDueDateGW * ExtendReducedDate * ReducedCred * RessurectGW * RessurectHW * SuperExtendDueDate * SuperExtendReducedDate
1 parent 0b1fa1c commit 65fc09c

24 files changed

Lines changed: 274 additions & 340 deletions

conf/defaults.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ $achievementPointsPerProblem = 5;
141141
$achievementPointsPerProblemReduced = 3;
142142
$achievementPreambleFile = "preamble.at";
143143
$achievementExcludeSet = [];
144+
$achievementExtensionFactor = 1;
144145
$mail{achievementEmailFrom} = '';
145146
$showCourseHomeworkTotals = 1;
146147

lib/WeBWorK/AchievementItems.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ sub UserItems ($c, $userName, $set, $records) {
7272

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

7878
# Return list of achievements items if $set is not defined.
@@ -116,9 +116,9 @@ sub UserItems ($c, $userName, $set, $records) {
116116
# This should only be called if count != 0.
117117
sub remaining_title ($self, $c) {
118118
if ($self->count > 0) {
119-
return $c->maketext('[_1] ([_2] remaining)', $c->maketext($self->name), $self->count);
119+
return $c->maketext('[_1] ([_2] remaining)', $self->name, $self->count);
120120
} else {
121-
return $c->maketext('[_1] (unlimited reusability)', $c->maketext($self->name));
121+
return $c->maketext('[_1] (unlimited reusability)', $self->name);
122122
}
123123
}
124124

lib/WeBWorK/AchievementItems/AddNewTestGW.pm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;
33

44
# Item to allow students to take an additional version of a test within its test version interval
55

6-
use WeBWorK::Utils qw(x);
76
use WeBWorK::Utils::DateTime qw(between);
87

9-
sub new ($class) {
8+
sub new ($class, $c) {
109
return bless {
1110
id => 'AddNewTestGW',
12-
name => x('Oil of Cleansing'),
13-
description => x(
11+
name => $c->maketext('Oil of Cleansing'),
12+
description => $c->maketext(
1413
'Unlock an additional version of a test. If used before the close date of '
1514
. 'the test this will allow you to generate a new version of the test.'
1615
)

lib/WeBWorK/AchievementItems/DoubleProb.pm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;
33

44
# Item to make a problem worth double.
55

6-
use WeBWorK::Utils qw(x);
76
use WeBWorK::Utils::DateTime qw(after);
87

9-
sub new ($class) {
8+
sub new ($class, $c) {
109
return bless {
1110
id => 'DoubleProb',
12-
name => x('Cupcake of Enlargement'),
13-
description => x('Causes a single homework problem to be worth twice as much.')
11+
name => $c->maketext('Cupcake of Enlargement'),
12+
description => $c->maketext('Causes a single homework problem to be worth twice as much.')
1413
}, $class;
1514
}
1615

lib/WeBWorK/AchievementItems/DoubleSet.pm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;
33

44
# Item to make a homework set worth twice as much
55

6-
use WeBWorK::Utils qw(x);
76
use WeBWorK::Utils::DateTime qw(after);
87

9-
sub new ($class) {
8+
sub new ($class, $c) {
109
return bless {
1110
id => 'DoubleSet',
12-
name => x('Cake of Enlargement'),
13-
description => x('Cause the selected homework set to count for twice as many points as it normally would.')
11+
name => $c->maketext('Cake of Enlargement'),
12+
description =>
13+
$c->maketext('Cause the selected homework set to count for twice as many points as it normally would.')
1414
}, $class;
1515
}
1616

lib/WeBWorK/AchievementItems/DuplicateProb.pm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;
33

44
# Item to turn one problem into another problem
55

6-
use WeBWorK::Utils qw(x);
76
use WeBWorK::Utils::DateTime qw(between);
87

9-
sub new ($class) {
8+
sub new ($class, $c) {
109
return bless {
1110
id => 'DuplicateProb',
12-
name => x('Box of Transmogrification'),
13-
description => x('Causes a homework problem to become a clone of another problem from the same set.')
11+
name => $c->maketext('Box of Transmogrification'),
12+
description =>
13+
$c->maketext('Causes a homework problem to become a clone of another problem from the same set.')
1414
}, $class;
1515
}
1616

lib/WeBWorK/AchievementItems/ExtendDueDate.pm

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
package WeBWorK::AchievementItems::ExtendDueDate;
22
use Mojo::Base 'WeBWorK::AchievementItems', -signatures;
33

4-
# Item to extend a close date by 24 hours.
4+
# Item to extend a close date by 24 * $achievementExtensionFactor hours.
55

6-
use WeBWorK::Utils qw(x);
7-
use WeBWorK::Utils::DateTime qw(before after between);
6+
use WeBWorK::Utils::DateTime qw(before after between getExtensionTime);
87

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

11-
sub new ($class) {
1211
return bless {
1312
id => 'ExtendDueDate',
14-
name => x('Tunic of Extension'),
15-
description => x(
16-
'Adds 24 hours to the close date of a homework. '
17-
. 'This will randomize problem details if used after the original close date.'
18-
)
13+
name => $c->maketext('Tunic of Extension'),
14+
description => $c->maketext(
15+
'Adds [_1] to the close date of a homework. '
16+
. 'This will randomize problem details if used after the original close date.',
17+
$timeText
18+
),
19+
time => $time,
20+
timeText => $timeText
1921
}, $class;
2022
}
2123

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

2628
sub print_form ($self, $set, $records, $c) {
2729
my $randomization_statement = after($set->due_date) ? $c->maketext('All problems will be rerandomized.') : '';
2830
if ($set->enable_reduced_scoring) {
29-
if (before($set->reduced_scoring_date + ONE_DAY)) {
31+
if (before($set->reduced_scoring_date + $self->{time})) {
3032
return $c->c(
31-
$c->tag('p', $c->maketext('Extend the deadline by 24 hours. [_1]', $randomization_statement)),
33+
$c->tag(
34+
'p',
35+
$c->maketext('Extend the deadline by [_1]. [_2]', $self->{timeText}, $randomization_statement)
36+
),
3237
$c->tag(
3338
'ul',
3439
$c->c(
@@ -37,7 +42,7 @@ sub print_form ($self, $set, $records, $c) {
3742
$c->maketext(
3843
'You will be able to receive full credit until [_1].',
3944
$c->formatDateTime(
40-
$set->reduced_scoring_date + ONE_DAY,
45+
$set->reduced_scoring_date + $self->{time},
4146
$c->ce->{studentDateDisplayFormat}
4247
)
4348
)
@@ -46,7 +51,10 @@ sub print_form ($self, $set, $records, $c) {
4651
'li',
4752
$c->maketext(
4853
'You will be able to receive reduced credit until [_1].',
49-
$c->formatDateTime($set->due_date + ONE_DAY, $c->ce->{studentDateDisplayFormat})
54+
$c->formatDateTime(
55+
$set->due_date + $self->{time},
56+
$c->ce->{studentDateDisplayFormat}
57+
)
5058
)
5159
)
5260
)->join('')
@@ -57,8 +65,9 @@ sub print_form ($self, $set, $records, $c) {
5765
$c->tag(
5866
'p',
5967
$c->maketext(
60-
'Extend the reduced credit deadline of this assignment to [_1] (an additional 24 hours). [_2]',
61-
$c->formatDateTime($set->due_date + ONE_DAY, $c->ce->{studentDateDisplayFormat}),
68+
'Extend the reduced credit deadline of this assignment to [_1] (an additional [_2]). [_3]',
69+
$c->formatDateTime($set->due_date + $self->{time}, $c->ce->{studentDateDisplayFormat}),
70+
$self->{timeText},
6271
$randomization_statement
6372
)
6473
),
@@ -76,8 +85,9 @@ sub print_form ($self, $set, $records, $c) {
7685
return $c->tag(
7786
'p',
7887
$c->maketext(
79-
'Extend the close date of this assignment to [_1] (an additional 24 hours). [_2]',
80-
$c->formatDateTime($set->due_date + ONE_DAY, $c->ce->{studentDateDisplayFormat}),
88+
'Extend the close date of this assignment to [_1] (an additional [_2]). [_3]',
89+
$c->formatDateTime($set->due_date + $self->{time}, $c->ce->{studentDateDisplayFormat}),
90+
$self->{timeText},
8191
$randomization_statement
8292
)
8393
);
@@ -104,11 +114,11 @@ sub use_item ($self, $set, $records, $c) {
104114

105115
# Add time to the reduced scoring date if it was defined in the first place
106116
if ($set->reduced_scoring_date) {
107-
$set->reduced_scoring_date($set->reduced_scoring_date + ONE_DAY);
117+
$set->reduced_scoring_date($set->reduced_scoring_date + $self->{time});
108118
$userSet->reduced_scoring_date($set->reduced_scoring_date);
109119
}
110120
# Add time to the close date
111-
$set->due_date($set->due_date + ONE_DAY);
121+
$set->due_date($set->due_date + $self->{time});
112122
$userSet->due_date($set->due_date);
113123
# This may require also extending the answer date.
114124
if ($set->due_date > $set->answer_date) {
@@ -117,10 +127,8 @@ sub use_item ($self, $set, $records, $c) {
117127
}
118128
$db->putUserSet($userSet);
119129

120-
return $c->maketext(
121-
'Close date of this assignment extended by 24 hours to [_1].',
122-
$c->formatDateTime($set->due_date, $c->ce->{studentDateDisplayFormat})
123-
);
130+
return $c->maketext('Close date of this assignment extended by [_1] to [_2].',
131+
$self->{timeText}, $c->formatDateTime($set->due_date, $c->ce->{studentDateDisplayFormat}));
124132
}
125133

126134
1;

lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,32 @@ use Mojo::Base 'WeBWorK::AchievementItems', -signatures;
44
# Item to extend the close date on a test
55

66
use WeBWorK::Utils qw(x);
7-
use WeBWorK::Utils::DateTime qw(before between);
7+
use WeBWorK::Utils::DateTime qw(before between getExtensionTime);
88

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

11-
sub new ($class) {
1212
return bless {
1313
id => 'ExtendDueDateGW',
14-
name => x('Amulet of Extension'),
15-
description => x('Extends the close date of a test by 24 hours.')
14+
name => $c->maketext('Amulet of Extension'),
15+
description => $c->maketext('Extends the close date of a test by [_1].', $timeText),
16+
time => $time,
17+
timeText => $timeText,
1618
}, $class;
1719
}
1820

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

2628
sub print_form ($self, $set, $records, $c) {
2729
if ($set->enable_reduced_scoring) {
28-
if (before($set->reduced_scoring_date + ONE_DAY)) {
30+
if (before($set->reduced_scoring_date + $self->{time})) {
2931
return $c->c(
30-
$c->tag('p', $c->maketext('Extend the deadline by 24 hours.')),
32+
$c->tag('p', $c->maketext('Extend the deadline by [_1].', $self->{timeText})),
3133
$c->tag(
3234
'ul',
3335
$c->c(
@@ -36,7 +38,7 @@ sub print_form ($self, $set, $records, $c) {
3638
$c->maketext(
3739
'You will be able to receive full credit until [_1].',
3840
$c->formatDateTime(
39-
$set->reduced_scoring_date + ONE_DAY,
41+
$set->reduced_scoring_date + $self->{time},
4042
$c->ce->{studentDateDisplayFormat}
4143
)
4244
)
@@ -45,7 +47,10 @@ sub print_form ($self, $set, $records, $c) {
4547
'li',
4648
$c->maketext(
4749
'You will be able to receive reduced credit until [_1].',
48-
$c->formatDateTime($set->due_date + ONE_DAY, $c->ce->{studentDateDisplayFormat})
50+
$c->formatDateTime(
51+
$set->due_date + $self->{time},
52+
$c->ce->{studentDateDisplayFormat}
53+
)
4954
)
5055
)
5156
)->join('')
@@ -56,8 +61,9 @@ sub print_form ($self, $set, $records, $c) {
5661
$c->tag(
5762
'p',
5863
$c->maketext(
59-
'Extend the reduced credit deadline of this assignment to [_1] (an additional 24 hours).',
60-
$c->formatDateTime($set->due_date + ONE_DAY, $c->ce->{studentDateDisplayFormat})
64+
'Extend the reduced credit deadline of this assignment to [_1] (an additional [_2]).',
65+
$c->formatDateTime($set->due_date + $self->{time}, $c->ce->{studentDateDisplayFormat}),
66+
$self->{timeText}
6167
)
6268
),
6369
$c->tag(
@@ -74,8 +80,9 @@ sub print_form ($self, $set, $records, $c) {
7480
return $c->tag(
7581
'p',
7682
$c->maketext(
77-
'Extend the close date of this assignment to [_1] (an additional 24 hours).',
78-
$c->formatDateTime($set->due_date + ONE_DAY, $c->ce->{studentDateDisplayFormat})
83+
'Extend the close date of this assignment to [_1] (an additional [_2]).',
84+
$c->formatDateTime($set->due_date + $self->{time}, $c->ce->{studentDateDisplayFormat}),
85+
$self->{timeText}
7986
)
8087
);
8188
}
@@ -87,12 +94,12 @@ sub use_item ($self, $set, $records, $c) {
8794

8895
# Add time to the reduced scoring date, due date, and answer date.
8996
if ($set->reduced_scoring_date) {
90-
$set->reduced_scoring_date($set->reduced_scoring_date + ONE_DAY);
97+
$set->reduced_scoring_date($set->reduced_scoring_date + $self->{time});
9198
$userSet->reduced_scoring_date($set->reduced_scoring_date);
9299
}
93-
$set->due_date($set->due_date + ONE_DAY);
100+
$set->due_date($set->due_date + $self->{time});
94101
$userSet->due_date($set->due_date);
95-
$set->answer_date($set->answer_date + ONE_DAY);
102+
$set->answer_date($set->answer_date + $self->{time});
96103
$userSet->answer_date($set->answer_date);
97104
$db->putUserSet($userSet);
98105

@@ -102,15 +109,15 @@ sub use_item ($self, $set, $records, $c) {
102109
#my @versions = $db->listSetVersions($userName, $setID);
103110
#for my $version (@versions) {
104111
# $set = $db->getSetVersion($userName, $setID, $version);
105-
# $set->reduced_scoring_date($set->reduced_scoring_date() + ONE_DAY)
112+
# $set->reduced_scoring_date($set->reduced_scoring_date() + $self->{time})
106113
# if defined($set->reduced_scoring_date()) && $set->reduced_scoring_date();
107-
# $set->due_date($set->due_date() + ONE_DAY);
108-
# $set->answer_date($set->answer_date() + ONE_DAY);
114+
# $set->due_date($set->due_date() + $self->{time});
115+
# $set->answer_date($set->answer_date() + $self->{time});
109116
# $db->putSetVersion($set);
110117
#}
111118

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

116123
1;

0 commit comments

Comments
 (0)