forked from TsedeyT/moodle-block_course_daterollover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
183 lines (138 loc) · 4.11 KB
/
edit.php
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
/*
This file is part of Moodle - http://moodle.org/
Moodle license:
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see http://www.gnu.org/licenses/gpl-3.0.html
Plug-in name: block_course_daterollover
Plug-in description:
The plug-in adjust assignment dates according to the course start date,
it will set forward assignment items by x number of days, which includes allowsubmissionfrom,
due-date, cutoffdate, upcoming events, in a course through one centralized screen
rather than having to go into each individual assignment activity.
This started as a fork from TsedeyT's original work.
@creator Tsedey Terefe <[email protected]>
@forker J. Anton Thelander <[email protected]>
@license GNU General Public License version 3
@package block
@subpackage course_daterollover
*/
global $CFG,$DB,$course,$PAGE;
require_once('../../config.php');
require_once($CFG->dirroot."/course/lib.php");
require_once($CFG->libdir.'/filelib.php');
require_once($CFG->dirroot.'/blocks/course_daterollover/course_daterollover_form.php');
require_login($SITE);
$courseid=required_param('id',PARAM_INT);
$sql3=$DB->get_fieldset_select('assign','course','course=?',array($courseid));
//If there is at least one assignment for the course, enter this if-statement (if $sql3 is not empty).
if (!empty($sql3))
{
$course= $DB->get_record('course',array ('id'=>$courseid),'*',MUST_EXIST);
$coursecontext = context_course::instance($course->id);//returns an object not just an ID
require_capability('block/course_daterollover:changedate', $coursecontext);
block_load_class('course_daterollover');
$block=new block_course_daterollover();
$form=new course_daterollover_form
(
null,
array('coursecontext'=>$coursecontext)
);
if ($data=$form->get_data())
{
$sql2=$DB->get_fieldset_select
(
'course',
'startdate',
'id=?',
array($courseid)
);
$assignments=$DB->get_records
(
'assign',
array('course'=>$courseid)
);
foreach($assignments as $assignment)
{
$record=new stdClass();
$record->id=$assignment->id;
$currentime=time();
$tiral3=(($data->date)-($sql2[0]));
$record->duedate=
(
($assignment->duedate)+
($data->date)-
($sql2[0])
);
$record->allowsubmissionsfromdate=
(
($assignment->allowsubmissionsfromdate)+
($data->date)-
($sql2[0])
);
$record->cutoffdate=
(
($assignment->cutoffdate)+
($data->date)-
($sql2[0])
);
$record->timemodified=$currentime;
$DB->update_record
(
'assign',
$record
);
}
$upcomingevents=$DB->get_records
(
'event',
array('courseid'=>$courseid)
);
foreach($upcomingevents as $upcomingevent)
{
$eventrecord=new stdClass();
$eventrecord->id=$upcomingevent->id;
$currentime=time();
$eventrecord->timestart=
(
($upcomingevent->timestart)+
($data->date)-($sql2[0])
);
$eventrecord->timemodified=$currentime ;
$DB->update_record
(
'event',
$eventrecord
);
}
$as=$DB->get_records
(
'course',
array('id'=>$courseid)
);
foreach ($as as $a )
{
$courserecord=new stdClass();
$courserecord->id=$a->id;
$courserecord->startdate=$data->date;
$DB->update_record
(
'course',
$courserecord
);
}
}
}
//Go to the current course's homepage, maybe change back to this page.
//redirect($CFG->wwwroot.'/course/view.php?id='.$courseid, '', 0);
//Redirect to the current course's calendar view.
redirect($CFG->wwwroot.'/calendar/view.php?view=upcoming&course='.$courseid, '', 0);
?>