-
Notifications
You must be signed in to change notification settings - Fork 0
/
studentview.php
333 lines (298 loc) · 16.4 KB
/
studentview.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?php
/**
* @package mod-scheduler
* @category mod
* @author Gustav Delius, Valery Fremaux > 1.8
*
* This page prints the screen view for the student
*/
/**
*
*/
if (!defined('MOODLE_INTERNAL')){
error("This file cannot be loaded directly");
}
if ($action){
include_once 'studentview.controller.php';
}
$teacher = get_record('user', 'id', $scheduler->teacher);
$mygroups = get_groups ($course->id, $USER->id);
/// printing head information
print_heading($scheduler->name, 'center', 4, 'h1');
if (!empty($scheduler->description)){
print_simple_box($scheduler->description, 'center', '80%');
}
print_simple_box_start('center', '80%');
if (scheduler_has_slot($USER->id, $scheduler, true)) {
print_string('welcomebackstudent', 'scheduler');
} else {
print_string('welcomenewstudent', 'scheduler');
}
print_simple_box_end();
// clean all late slots (for every body, anyway, they are passed !!)
scheduler_free_late_unused_slots($scheduler->id);
/// get information about appointment attention
$sql = "
SELECT
COUNT(*)
FROM
{$CFG->prefix}scheduler_slots AS s,
{$CFG->prefix}scheduler_appointment AS a
WHERE
s.id = a.slotid AND
a.studentid = {$USER->id} AND
a.attended = 1 AND
s.schedulerid = {$scheduler->id}
";
$hasattended = count_records_sql($sql);
/// get available slots
$haveunattendedappointments = false;
if ($slots = scheduler_get_available_slots($USER->id, $scheduler->id, true)) {
$minhidedate = 0; // very far in the past
$studentSlots = array();
$studentAttendedSlots = array();
foreach($slots as $slot) {
/// check if other appointement is not "on the way". Student could not apply to it.
if (scheduler_get_conflicts($scheduler->id, $slot->starttime, $slot->starttime + $slot->duration * 60, 0, $USER->id, SCHEDULER_OTHERS)){
continue;
}
/// check if not mine and late, don't care
if (!$slot->appointedbyme and $slot->starttime + (60 * $slot->duration) < time()){
continue;
}
/// check what to print in groupsession indication
if ($slot->exclusivity == 0){
$slot->groupsession = get_string('yes');
} else {
// $consumed = scheduler_get_consumed($scheduler->id, $slot->starttime, $slot->starttime + $slot->duration * 60, $slot->teacher);
if ($slot->exclusivity > $slot->population){
$slot->groupsession = get_string('limited', 'scheduler', ($slot->exclusivity - $slot->population)."/".$slot->exclusivity);
} else { // should not be visible to students
$slot->groupsession = get_string('complete', 'scheduler');
}
}
/// examine slot situations and elects those which have sense for the current student
// I am in slot, unconditionnally
if ($slot->appointedbyme) {
if ($slot->attended){
$studentAttendedSlots[$slot->starttime.'_'.$slot->teacherid] = $slot;
} else {
$studentSlots[$slot->starttime.'_'.$slot->teacherid] = $slot;
}
// binary or and and required here to calculate properly
$haveunattendedappointments = $haveunattendedappointments | ($slot->appointedbyme & !$slot->attended);
} else {
// slot is free
if (!$slot->appointed) {
//if student is only allowed one appointment and this student has already had their then skip this record
if (($hasattended) and ($scheduler->schedulermode == 'oneonly')){
continue;
}
elseif ($slot->hideuntil <= time()){
$studentSlots[$slot->starttime.'_'.$slot->teacherid] = $slot;
}
$minhidedate = ($slot->hideuntil < $minhidedate || $minhidedate == 0) ? $slot->hideuntil : $minhidedate ;
}
// slot is booked by another student, group booking is allowed and there is still room
elseif ($slot->appointed and (($slot->exclusivity == 0) || ($slot->exclusivity > $slot->population))) {
// there is already a record fot this time/teacher : sure its our's
if (array_key_exists($slot->starttime.'_'.$slot->teacherid, $studentSlots)) continue;
// else record the slot with this user (not me).
$studentSlots[$slot->starttime.'_'.$slot->teacherid] = $slot;
}
}
}
/// prepare attended slot table
if (count($studentAttendedSlots)){
print_heading(get_string('attendedslots' ,'scheduler'));
$table->head = array ($strdate, format_string($scheduler->staffrolename), $strnote, $strgrade);
$table->align = array ('LEFT', 'CENTER', 'LEFT', 'LEFT');
$table->size = array ('', '', '40%', '150');
$table->width = '90%';
$table->data = array();
$previousdate = '';
$previoustime = 0;
$previousendtime = 0;
foreach($studentAttendedSlots as $key => $aSlot){
/// preparing data
$startdate = scheduler_userdate($aSlot->starttime,1);
$starttime = scheduler_usertime($aSlot->starttime,1);
$endtime = scheduler_usertime($aSlot->starttime + ($aSlot->duration * 60),1);
//$startdatestr = ($startdate == $previousdate) ? '' : $startdate ;
//$starttimestr = ($starttime == $previoustime) ? '' : $starttime ;
//$endtimestr = ($endtime == $previousendtime) ? '' : $endtime ;
//Full date and time shown for each attended slots
$startdatestr = $startdate;
$starttimestr = $starttime;
$endtimestr = $endtime;
$studentappointment = get_record('scheduler_appointment', 'slotid', $aSlot->id, 'studentid', $USER->id);
if ($scheduler->scale > 0){
$studentappointment->grade = $studentappointment->grade.'/'.$scheduler->scale;
}
if (has_capability('mod/scheduler:seeotherstudentsresults', $context)){
$appointments = scheduler_get_appointments($aSlot->id);
$collegues = '';
foreach($appointments as $appstudent){
$grade = $appstudent->grade;
if ($scheduler->scale > 0){
$grade = $grade . '/' . $scheduler->scale;
}
$student = get_record('user', 'id', $appstudent->studentid);
$picture = print_user_picture($appstudent->studentid, $course->id, $student->picture, 0, true, true);
$name = fullname($student);
if ($appstudent->studentid == $USER->id) $name = "<b>$name</b>" ; // it's me !!
$collegues .= " $picture $name ($grade)<br/>";
}
} else {
$collegues = $studentappointment->grade;
}
$studentnotes1 = '';
$studentnotes2 = '';
if ($aSlot->notes != ''){
$studentnotes1 = '<div class="slotnotes">';
$studentnotes1 .= '<b>'.get_string('yourslotnotes', 'scheduler').'</b><br/>';
$studentnotes1 .= format_string($aSlot->notes).'</div>';
}
if ($studentappointment->appointmentnote != ''){
$studentnotes2 .= '<div class="appointmentnote">';
$studentnotes2 .= '<b>'.get_string('yourappointmentnote', 'scheduler').'</b><br/>';
$studentnotes2 .= format_string($studentappointment->appointmentnote).'</div>';
}
$studentnotes = "{$studentnotes1}{$studentnotes2}";
// recording data into table
$table->data[] = array ("<span class=\"attended\">$startdatestr</span><br/><div class=\"timelabel\">[$starttimestr - $endtimestr]</div>", "<a href=\"../../user/view.php?id={$aSlot->teacherid}&course={$scheduler->course}\">".fullname(get_record('user', 'id', $aSlot->teacherid)).'</a>',$studentnotes, $collegues);
$previoustime = $starttime;
$previousendtime = $endtime;
$previousdate = $startdate;
}
print_table($table);
}
/// prepare appointable slot table
print_heading(get_string('slots' ,'scheduler'));
unset($table);
$table->head = array ($strdate, $strstart, $strend, get_string('choice', 'scheduler'), format_string($scheduler->staffrolename), get_string('groupsession', 'scheduler'));
$table->align = array ('LEFT', 'LEFT', 'CENTER', 'CENTER', 'LEFT');
$table->data = array();
$previousdate = '';
$previoustime = 0;
$previousendtime = 0;
$canappoint = false;
foreach($studentSlots as $key => $aSlot){
$startdate = scheduler_userdate($aSlot->starttime,1);
$starttime = scheduler_usertime($aSlot->starttime,1);
$endtime = scheduler_usertime($aSlot->starttime + ($aSlot->duration * 60),1);
$startdatestr = ($startdate == $previousdate) ? '' : $startdate ;
//$starttimestr = ($starttime == $previoustime) ? '' : $starttime ;
//$endtimestr = ($endtime == $previousendtime) ? '' : $endtime ;
//Full time shown for each appointable slots
$startdatestr = $startdate;
$starttimestr = $starttime;
$endtimestr = $endtime;
if ($aSlot->appointedbyme and !$aSlot->attended){
$radio = "<input type=\"radio\" name=\"slotid\" value=\"{$aSlot->id}\" checked=\"checked\" />\n";
$table->data[] = array ("<b>$startdatestr</b>", "<b>$starttime</b>", "<b>$endtime</b>", $radio, "<b>"."<a href=\"../../user/view.php?id={$aSlot->teacherid}&course=$scheduler->course\">".fullname(get_record('user', 'id', $aSlot->teacherid)).'</a></b>','<b>'.$aSlot->groupsession.'</b>');
} else {
if ($aSlot->appointed and has_capability('mod/scheduler:seeotherstudentsbooking', $context)){
$appointments = scheduler_get_appointments($aSlot->id);
$collegues = "<div style=\"visibility:hidden; display:none\" id=\"collegues{$aSlot->id}\"><br/>";
foreach($appointments as $appstudent){
$student = get_record('user', 'id', $appstudent->studentid);
$picture = print_user_picture($appstudent->studentid, $course->id, $student->picture, 0, true, true);
$name = "<a href=\"view.php?what=viewstudent&id={$cm->id}&studentid={$student->id}&course={$scheduler->course}&order=DESC\">".fullname($student).'</a>';
$collegues .= " $picture $name<br/>";
}
$collegues .= '</div>';
$aSlot->groupsession .= " <a href=\"javascript:toggleVisibility('{$aSlot->id}')\"><img name=\"group<?php p($aSlot->id) ?>\" src=\"{$CFG->pixpath}/t/switch_plus.gif\" border=\"0\" title=\"".get_string('whosthere', 'scheduler')."\"></a> {$collegues}";
}
$canappoint = true;
$canusegroup = ($aSlot->appointed) ? 0 : 1;
$radio = "<input type=\"radio\" name=\"slotid\" value=\"{$aSlot->id}\" onclick=\"checkGroupAppointment($canusegroup)\" />\n";
$table->data[] = array ($startdatestr, $starttimestr, $endtimestr, $radio, "<a href=\"../../user/view.php?id={$aSlot->teacherid}&course={$scheduler->course}\">".fullname(get_record('user', 'id', $aSlot->teacherid)).'</a>', $aSlot->groupsession);
}
$previoustime = $starttime;
$previousendtime = $endtime;
$previousdate = $startdate;
}
/// print slot table
if (count($table->data)){
?>
<center>
<form name="appoint" action="view.php" method="get">
<input type="hidden" name="what" value="savechoice" />
<input type="hidden" name="id" value="<?php p($cm->id) ?>" />
<script type="text/javascript">
function checkGroupAppointment(enable){
var numgroups = '<?php p(count($mygroups)) ?>';
if (!enable){
if (numgroups > 1){ // we have a select. we must force "appointsolo".
document.forms['appoint'].elements['appointgroup'].options[0].selected = true;
}
}
document.forms['appoint'].elements['appointgroup'].disabled = !enable;
}
</script>
<?php
print_table($table);
/// add some global script
?>
<script type="text/javascript">
function toggleVisibility(id){
obj = document.getElementById('collegues' + id);
if (obj.style.visibility == "hidden"){
obj.style.visibility = "visible";
obj.style.display = "block";
document.images["group"+id].src='<?php echo $CFG->pixpath."/t/switch_minus.gif" ?>';
} else {
obj.style.visibility = "hidden";
obj.style.display = "none";
document.images["group"+id].src='<?php echo $CFG->pixpath."/t/switch_plus.gif" ?>';
}
}
</script>
<?php
if ($canappoint){
/*
Should add a note from the teacher to the student.
TODO : addfield into appointments
print_heading(get_string('savechoice', 'scheduler'), 3);
echo '<table><tr><td valign="top" align="right"><b>';
print_string('studentnotes', 'scheduler');
echo ' :</b></td><td valign="top" align="left"><textarea name="notes" cols="60" rows="20"></textarea></td></tr></table>';
*/
echo '<br /><input type="submit" value="'.get_string('savechoice', 'scheduler').'" /> ';
if ($groupmode){
if (count($mygroups) == 1){
$groups = array_values($mygroups);
echo ' <input type="checkbox" name="appointgroup" value="'.$groups[0]->id.'" /> '.get_string('appointformygroup', 'scheduler').': '.$groups[0]->name;
helpbutton('appointagroup', get_string('appointagroup', 'scheduler'), 'scheduler');
}
if (count($mygroups) > 1){
print_string('appointfor', 'scheduler');
foreach($mygroups as $group){
$groupchoice[0] = get_string('appointsolo','scheduler');
$groupchoice[$group->id] = $group->name;
}
choose_from_menu($groupchoice, 'appointgroup', '', '');
helpbutton('appointagroup', get_string('appointagroup', 'scheduler'), 'scheduler');
}
}
}
echo '</form>';
if ($haveunattendedappointments and has_capability('mod/scheduler:disengage', $context)){
echo "<br/><a href=\"view.php?id={$cm->id}&what=disengage\">".get_string('disengage','scheduler').'</a>';
}
echo '</center>';
}
else {
if ($minhidedate > time()){
$noslots = get_string('noslotsopennow', 'scheduler') .'<br/><br/>';
$noslots .= get_string('firstslotavailable', 'scheduler') . '<span style="color:#C00000"><b>'.userdate($minhidedate).'</b></span>';
} else {
$noslots = get_string('noslotsavailable', 'scheduler') .'<br/><br/>';
}
print_simple_box($noslots, 'center', '70%');
}
} else {
notify(get_string('noslots', 'scheduler'));
}
?>