-
-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathSuperExtendDueDate.pm
More file actions
124 lines (112 loc) · 3.68 KB
/
SuperExtendDueDate.pm
File metadata and controls
124 lines (112 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package WeBWorK::AchievementItems::SuperExtendDueDate;
use Mojo::Base 'WeBWorK::AchievementItems', -signatures;
# Item to extend a close date by 48 hours.
use WeBWorK::Utils qw(x);
use WeBWorK::Utils::DateTime qw(before after between);
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. '
. 'This will randomize problem details if used after the original close date.'
)
}, $class;
}
sub can_use ($self, $set, $records) {
return $set->assignment_type eq 'default' && between($set->open_date, $set->due_date + TWO_DAYS);
}
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 + TWO_DAYS)) {
return $c->c(
$c->tag('p', $c->maketext('Extend the deadline by 48hours. [_1]', $randomization_statement)),
$c->tag(
'ul',
$c->c(
$c->tag(
'li',
$c->maketext(
'You will be able to receive full credit until [_1].',
$c->formatDateTime(
$set->reduced_scoring_date + TWO_DAYS,
$c->ce->{studentDateDisplayFormat}
)
)
),
$c->tag(
'li',
$c->maketext(
'You will be able to receive reduced credit until [_1].',
$c->formatDateTime($set->due_date + TWO_DAYS, $c->ce->{studentDateDisplayFormat})
)
)
)->join('')
),
)->join('');
} else {
return $c->c(
$c->tag(
'p',
$c->maketext(
'Extend the reduced credit deadline of this assignment to [_1] (an additional 48 hours). [_2]',
$c->formatDateTime($set->due_date + TWO_DAYS, $c->ce->{studentDateDisplayFormat}),
$randomization_statement
)
),
$c->tag(
'p',
$c->maketext(
'Because the deadline has already passed you will only receive reduced credit during this extension.'
)
)
)->join('');
}
} else {
return $c->tag(
'p',
$c->maketext(
'Extend the close date of this assignment to [_1] (an additional 48 hours). [_2]',
$c->formatDateTime($set->due_date + TWO_DAYS, $c->ce->{studentDateDisplayFormat}),
$randomization_statement
)
);
}
}
sub use_item ($self, $set, $records, $c) {
my $db = $c->db;
my $userSet = $db->getUserSet($set->user_id, $set->set_id);
# Change the seed for all of the problems if the set is currently closed.
if (after($set->due_date)) {
my %userProblems =
map { $_->problem_id => $_ }
$db->getUserProblemsWhere({ user_id => $set->user_id, set_id => $set->set_id });
for my $problem (@$records) {
my $userProblem = $userProblems{ $problem->problem_id };
$userProblem->problem_seed($userProblem->problem_seed % 2**31 + 1);
$problem->problem_seed($userProblem->problem_seed);
$db->putUserProblem($userProblem);
}
}
# 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 + TWO_DAYS);
$userSet->reduced_scoring_date($set->reduced_scoring_date);
}
# Add time to the close date
$set->due_date($set->due_date + TWO_DAYS);
$userSet->due_date($set->due_date);
# This may require also extending the answer date.
if ($set->due_date > $set->answer_date) {
$set->answer_date($set->due_date);
$userSet->answer_date($set->answer_date);
}
$db->putUserSet($userSet);
return $c->maketext(
'Close date of this assignment extended by 48 hours to [_1].',
$c->formatDateTime($set->due_date, $c->ce->{studentDateDisplayFormat})
);
}
1;