This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
studentview.controller.php
215 lines (195 loc) · 10.3 KB
/
studentview.controller.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
/**
* Controller for student view
*
* @package mod-scheduler
* @category mod
* @author Gustav Delius, Valery Fremaux > 1.8
*
* @usecase 'savechoice', needs mod/scheduler:appoint
* @usecase 'disengage', needs mod/scheduler:disengage
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from view.php in mod/scheduler
}
/************************************************ Saving choice ************************************************/
if ($action == 'savechoice' && has_capability('mod/scheduler:appoint', $context)) {
// get parameters
$slotid = optional_param('slotid', '', PARAM_INT);
$appointgroup = optional_param('appointgroup', 0, PARAM_INT);
// $notes = optional_param('notes', '', PARAM_TEXT);
if (!$slotid) {
notice(get_string('notselected', 'scheduler'), "view.php?id={$cm->id}");
}
if (!$slot = get_record('scheduler_slots', 'id', $slotid)) {
error('Invalid slot ID');
}
$astudentid = $USER->id; //?? TDMU
//chek is this user are appointed to overlaped slot in the another scheduler
$RemoteConflict = scheduler_get_conflicts($slot->schedulerid, $slot->starttime, $slot->starttime+HOURSECS, 0, $astudentid, SCHEDULER_OTHERS, false);
if ($RemoteConflict) {
print_simple_box_start('center');
echo '<h2 style="color:red;">'.get_string('multicoursesappointmentoverlap', 'scheduler').'</h2>';
echo '<ul>';
foreach ($RemoteConflict as $aConflict){
$conflictinfo = scheduler_get_courseinfobyslotid($aConflict->id);
echo '<li> ' . scheduler_userdate($conflictinfo->starttime, 1) . ' ' . scheduler_usertime($conflictinfo->starttime, 1) . ' ' . get_string('incourse', 'scheduler') . ': ' . $conflictinfo->shortname . ' - ' . $conflictinfo->fullname . "</li>\n";
}
echo '</ul><br/>';
print_simple_box_end();
print_continue("{$CFG->wwwroot}/mod/scheduler/view.php?id={$cm->id}");
print_footer($course);
exit();
}
$available = scheduler_get_appointments($slotid);
$consumed = ($available) ? count($available) : 0 ;
// if slot is already overcrowded
if ($slot->exclusivity > 0 && $slot->exclusivity <= $consumed) {
print_simple_box_start('center');
echo '<h2 style="color:red;">'.get_string('slot_is_just_in_use', 'scheduler').'</h2>';
print_simple_box_end();
print_continue("{$CFG->wwwroot}/mod/scheduler/view.php?id={$cm->id}");
print_footer($course);
exit();
}
/// If we are scheduling a full group we must discard all pending appointments of other participants of the scheduled group
/// just add the list of other students for searching slots to delete
if ($appointgroup){
if (!function_exists('build_navigation')){
// we are still in 1.8
$oldslotownersarray = groups_get_members($appointgroup, 'student');
} else {
// we are still in 1.8
$oldslotownersarray = groups_get_members($appointgroup);
}
// special hack for 1.8 / 1.9 compatibility for groups_get_members()
foreach($oldslotownersarray as $oldslotownermember){
if (is_numeric($oldslotownermember)){
// we are in 1.8
if (has_capability("mod/scheduler:appoint", $context, $oldslotownermember)){
$oldslotowners[] = $oldslotownermember;
}
} else {
// we are in 1.9
if (has_capability("mod/scheduler:appoint", $context, $oldslotownermember->id)){
$oldslotowners[] = $oldslotownermember->id;
}
}
}
} else {
// single user appointment : get current user in
$oldslotowners[] = $USER->id;
}
$oldslotownerlist = implode("','", $oldslotowners);
/// cleans up old slots if not attended (attended are definitive results, with grades)
$sql = "
SELECT
s.*,
a.id as appointmentid
FROM
{$CFG->prefix}scheduler_slots AS s,
{$CFG->prefix}scheduler_appointment AS a
WHERE
s.id = a.slotid AND
s.schedulerid = '{$slot->schedulerid}' AND
a.studentid IN ('$oldslotownerlist') AND
a.attended = 0
";
if ($scheduler->schedulermode == 'onetime'){
$sql .= " AND s.starttime > ".time();
}
if ($oldappointments = get_records_sql($sql)){
foreach($oldappointments as $oldappointment){
scheduler_delete_appointment($oldappointment->appointmentid, $oldappointment, $scheduler);
// notify teacher
if ($scheduler->allownotifications){
$student = get_record('user', 'id', $USER->id);
$teacher = get_record('user', 'id', $oldappointment->teacherid);
include_once($CFG->dirroot.'/mod/scheduler/mailtemplatelib.php');
$vars = array( 'SITE' => $SITE->shortname,
'SITE_URL' => $CFG->wwwroot,
'COURSE_SHORT' => $COURSE->shortname,
'COURSE' => $COURSE->fullname,
'COURSE_URL' => $CFG->wwwroot.'/course/view.php?id='.$COURSE->id,
'MODULE' => $scheduler->name,
'USER' => fullname($student),
'DATE' => userdate($oldappointment->starttime,get_string('strftimedate')), // BUGFIX CONTRIB-937
'TIME' => userdate($oldappointment->starttime,get_string('strftimetime')), // BUGFIX end
'DURATION' => $oldappointment->duration );
$notification = compile_mail_template('cancelled', $vars );
$notificationHtml = compile_mail_template('cancelled_html', $vars );
email_to_user($teacher, $student, get_string('cancelledbystudent', 'scheduler', $SITE->shortname), $notification, $notificationHtml);
}
// delete all calendar events for that slot
scheduler_delete_calendar_events($oldappointment);
// renew all calendar events as some appointments may be left for other students
scheduler_add_update_calendar_events($oldappointment, $course);
}
}
/// create new appointment and add it for each member of the group
foreach($oldslotowners as $astudentid){
$appointment->slotid = $slotid;
// $appointment->notes = $notes;
$appointment->studentid = $astudentid;
$appointment->attended = 0;
$appointment->timecreated = time();
$appointment->timemodified = time();
if (!insert_record('scheduler_appointment', $appointment)) {
error('Couldn\'t save choice to database');
}
scheduler_events_update($slot, $course);
// notify teacher
if ($scheduler->allownotifications){
$student = get_record('user', 'id', $appointment->studentid);
$teacher = get_record('user', 'id', $slot->teacherid);
include_once($CFG->dirroot.'/mod/scheduler/mailtemplatelib.php');
$vars = array( 'SITE' => $SITE->shortname,
'SITE_URL' => $CFG->wwwroot,
'COURSE_SHORT' => $COURSE->shortname,
'COURSE' => $COURSE->fullname,
'COURSE_URL' => $CFG->wwwroot.'/course/view.php?id='.$COURSE->id,
'MODULE' => $scheduler->name,
'USER' => fullname($student),
'DATE' => userdate($slot->starttime,get_string('strftimedate')), // BUGFIX CONTRIB-937
'TIME' => userdate($slot->starttime,get_string('strftimetime')), // BUGFIX end
'DURATION' => $slot->duration );
$notification = compile_mail_template('applied', $vars );
$notificationHtml = compile_mail_template('applied_html', $vars );
email_to_user($teacher, $student, get_string('newappointment', 'scheduler', $SITE->shortname), $notification, $notificationHtml);
}
}
}
// *********************************** Disengage alone from the slot ******************************/
if (($action == 'disengage') && has_capability('mod/scheduler:disengage', $context)) {
$appointments = scheduler_get_user_appointments($scheduler);
if ($appointments){
foreach($appointments as $appointment){
$oldslot = get_record('scheduler_slots', 'id', $appointment->slotid);
scheduler_delete_appointment($appointment->id, $oldslot, $scheduler);
// notify teacher
if ($scheduler->allownotifications){
$student = get_record('user', 'id', $USER->id);
$teacher = get_record('user', 'id', $oldslot->teacherid);
include_once($CFG->dirroot.'/mod/scheduler/mailtemplatelib.php');
$vars = array( 'SITE' => $SITE->shortname,
'SITE_URL' => $CFG->wwwroot,
'COURSE_SHORT' => $COURSE->shortname,
'COURSE' => $COURSE->fullname,
'COURSE_URL' => $CFG->wwwroot.'/course/view.php?id='.$COURSE->id,
'MODULE' => $scheduler->name,
'USER' => fullname($student),
'DATE' => userdate($oldslot->starttime,get_string('strftimedate')), // BUGFIX CONTRIB-937
'TIME' => userdate($oldslot->starttime,get_string('strftimetime')), // BUGFIX end
'DURATION' => $oldslot->duration );
$notification = compile_mail_template('cancelled', $vars );
$notificationHtml = compile_mail_template('cancelled_html', $vars );
email_to_user($teacher, $student, get_string('cancelledbystudent', 'scheduler', $SITE->shortname), $notification, $notificationHtml);
}
}
// delete calendar events for that slot
scheduler_delete_calendar_events($oldslot);
// renew all calendar events as some appointments may be left for other students
scheduler_add_update_calendar_events($oldslot, $course);
}
}
?>