forked from bostelm/moodle-mod_scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderable.php
699 lines (599 loc) · 22.2 KB
/
renderable.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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
/**
* This file contains the definition for the renderable classes for the assignment
*
* @package mod_scheduler
* @copyright 2014 Henning Bostelmann and others (see README.txt)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
use \mod_scheduler\model\scheduler;
use \mod_scheduler\model\slot;
use \mod_scheduler\model\appointment;
/**
* This class represents a table of slots associated with one student
*
* @copyright 2014 Henning Bostelmann and others (see README.txt)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class scheduler_slot_table implements renderable {
/** @var array list of slots in this table */
public $slots = array();
/** @var scheduler the scheduler that the slots are in */
public $scheduler;
/** @var bool whether to show grades in the table */
public $showgrades;
/** @var bool whether any slot in the table has other students to show */
public $hasotherstudents = false;
/** @var bool whether to show start/end time of the slots */
public $showslot = true;
/** @var bool whether to show the attended/not attended icons */
public $showattended = false;
/** @var bool whether to show action buttons (for cancelling) */
public $showactions = true;
/** @var bool whether to show (confidential) teacher notes */
public $showteachernotes = false;
/** @var bool whether to show a link to edit appointments */
public $showeditlink = false;
/** @var bool whether to show the location of the appointment */
public $showlocation = true;
/** @var bool whether to show the students in the slot */
public $showstudent = false;
/** @var moodle_url|null action URL for buttons */
public $actionurl;
/**
* Add a slot to the table.
*
* @param slot $slotmodel the slot to be added
* @param appointment $appointmentmodel the corresponding appointment
* @param array $otherstudents any other students in the same slot
* @param bool $cancancel whether the user can canel the appointment
* @param bool $canedit whether the user can edit the slot/appointment
* @param bool $canview whether the user can view the appointment
*/
public function add_slot(slot $slotmodel, appointment $appointmentmodel,
$otherstudents, $cancancel = false, $canedit = false, $canview = false) {
$slot = new stdClass();
$slot->slotid = $slotmodel->id;
if ($this->showstudent) {
$slot->student = $appointmentmodel->student;
}
$slot->starttime = $slotmodel->starttime;
$slot->endtime = $slotmodel->endtime;
$slot->attended = $appointmentmodel->attended;
$slot->location = $slotmodel->appointmentlocation;
$slot->slotnote = $slotmodel->notes;
$slot->slotnoteformat = $slotmodel->notesformat;
$slot->teacher = $slotmodel->get_teacher();
$slot->appointmentid = $appointmentmodel->id;
if ($this->scheduler->uses_appointmentnotes()) {
$slot->appointmentnote = $appointmentmodel->appointmentnote;
$slot->appointmentnoteformat = $appointmentmodel->appointmentnoteformat;
}
if ($this->scheduler->uses_teachernotes() && $this->showteachernotes) {
$slot->teachernote = $appointmentmodel->teachernote;
$slot->teachernoteformat = $appointmentmodel->teachernoteformat;
}
$slot->otherstudents = $otherstudents;
$slot->cancancel = $cancancel;
$slot->canedit = $canedit;
$slot->canview = $canview;
if ($this->showgrades) {
$slot->grade = $appointmentmodel->grade;
}
$this->showactions = $this->showactions || $cancancel;
$this->hasotherstudents = $this->hasotherstudents || (bool) $otherstudents;
$this->slots[] = $slot;
}
/**
* Create a new slot table.
*
* @param scheduler $scheduler the scheduler in which the slots are
* @param bool $showgrades whether to show grades
* @param moodle_url|null $actionurl action URL for buttons
*/
public function __construct(scheduler $scheduler, $showgrades=true, $actionurl = null) {
$this->scheduler = $scheduler;
$this->showgrades = $showgrades && $scheduler->uses_grades();
$this->actionurl = $actionurl;
}
}
/**
* This class represents a list of students in a slot, to be displayed "inline" within a larger table
*
* @copyright 2014 Henning Bostelmann and others (see README.txt)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class scheduler_student_list implements renderable {
/** @var array list of students to be displayed */
public $students = array();
/** @var scheduler the scheduler in whose context the list is */
public $scheduler;
/** @var bool whether tho show the grades of the students */
public $showgrades;
/** @var bool whether to show students in an expandable list */
public $expandable = true;
/** @var bool whether the expandable list is already expanded */
public $expanded = true;
/** @var bool whether appointments can be edited */
public $editable = false;
/** @var string name of the checkbox group used for marking students as seen */
public $checkboxname = '';
/** @var string text of the edit button */
public $buttontext = '';
/** @var moodle_url|null action URL for buttons */
public $actionurl = null;
/** @var bool whether to include links to individual appointments */
public $linkappointment = false;
/**
* Add a student to the list.
*
* @param appointment $appointment the appointment to add (one student)
* @param bool $highlight whether this entry is highlighted
* @param bool $checked whether the "seen" tickbox is checked
* @param bool $showgrade whether to show a grade with this entry
* @param bool $showstudprovided whether to show an icon for student-provided files
* @param bool $editattended whether to make the attended tickbox editable
*/
public function add_student(appointment $appointment, $highlight, $checked = false,
$showgrade = true, $showstudprovided = false, $editattended = false) {
$student = new stdClass();
$student->user = $appointment->get_student();
if ($this->showgrades && $showgrade) {
$student->grade = $appointment->grade;
} else {
$student->grade = null;
}
$student->highlight = $highlight;
$student->checked = $checked;
$student->editattended = $editattended;
$student->entryid = $appointment->id;
$scheduler = $appointment->get_scheduler();
$student->notesprovided = false;
$student->filesprovided = 0;
if ($showstudprovided) {
$student->notesprovided = $scheduler->uses_studentnotes() && $appointment->has_studentnotes();
if ($scheduler->uses_studentfiles()) {
$student->filesprovided = $appointment->count_studentfiles();
}
}
$this->students[] = $student;
}
/**
* Create a new student list.
*
* @param scheduler $scheduler the scheduler in whose context the list is
* @param bool $showgrades whether tho show grades of students
*/
public function __construct(scheduler $scheduler, $showgrades = true) {
$this->scheduler = $scheduler;
$this->showgrades = $showgrades;
}
}
/**
* This class represents a table of slots which a student can book.
*
* @copyright 2014 Henning Bostelmann and others (see README.txt)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class scheduler_slot_booker implements renderable {
/**
* @var array list of slots to be displayed
*/
public $slots = array();
/**
* @var scheduler scheduler in whose context the list is
*/
public $scheduler;
/**
* @var int the id number of the student booking slots
*/
public $studentid;
/**
* @var moodle_url action url for buttons
*/
public $actionurl;
/**
* Add a slot to the list.
*
* @param slot $slotmodel the slot to be added
* @param bool $canbook whether the slot can be booked
* @param bool $bookedbyme whether the slot is already booked by the current student
* @param string $groupinfo information about group slots
* @param array $otherstudents other students in this slot
*/
public function add_slot(slot $slotmodel, $canbook, $bookedbyme, $groupinfo, $otherstudents) {
$slot = new stdClass();
$slot->slotid = $slotmodel->id;
$slot->starttime = $slotmodel->starttime;
$slot->endtime = $slotmodel->endtime;
$slot->location = $slotmodel->appointmentlocation;
$slot->notes = $slotmodel->notes;
$slot->notesformat = $slotmodel->notesformat;
$slot->bookedbyme = $bookedbyme;
$slot->canbook = $canbook;
$slot->groupinfo = $groupinfo;
$slot->teacher = $slotmodel->get_teacher();
$slot->otherstudents = $otherstudents;
$this->slots[] = $slot;
}
/**
* Contructs a slot booker.
*
* @param scheduler $scheduler the scheduler in which the booking takes place
* @param int $studentid the student who books
* @param moodle_url $actionurl
* @param int $maxselect no longer used
*/
public function __construct(scheduler $scheduler, $studentid, moodle_url $actionurl, $maxselect) {
$this->scheduler = $scheduler;
$this->studentid = $studentid;
$this->actionurl = $actionurl;
}
}
/**
* Command bar with action buttons, used by teachers.
*
* @copyright 2014 Henning Bostelmann and others (see README.txt)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class scheduler_command_bar implements renderable {
/**
* @var array list of drop-down menus in the command bar
*/
public $menus = array();
/**
* @var array list of action_link objects used in the menu
*/
public $linkactions = array();
/**
* @var string title of the menu
*/
public $title = '';
/**
* Adds a group of menu items in a menu.
*
* @param string $title the title of the group
* @param array $actions an array of action_menu_link instances, representing the commands
*/
public function add_group($title, array $actions) {
$menu = new action_menu($actions);
$menu->actiontext = $title;
$this->menus[] = $menu;
}
/**
* Creates an action link with an optional confirmation dialogue attached.
*
* @param moodle_url $url URL of the action
* @param string $titlekey key of the link title
* @param string $iconkey key of the icon to display
* @param string|null $confirmkey key for the confirmation text
* @param string|null $id id attribute of the new link
* @return action_link the new action link
*/
public function action_link(moodle_url $url, $titlekey, $iconkey, $confirmkey = null, $id = null) {
$title = get_string($titlekey, 'scheduler');
$pix = new pix_icon($iconkey, $title, 'moodle', array('class' => 'iconsmall', 'title' => ''));
$attributes = array();
if ($id) {
$attributes['id'] = $id;
}
$confirmaction = null;
if ($confirmkey) {
$confirmaction = new confirm_action(get_string($confirmkey, 'scheduler'));
}
$act = new action_link($url, $title, $confirmaction, $attributes, $pix);
$act->primary = false;
return $act;
}
/**
* Contructs a command bar
*/
public function __construct() {
// Nothing to add right now.
}
}
/**
* This class represents a table of slots displayed to a teacher, with options to modify the list.
*
* @copyright 2014 Henning Bostelmann and others (see README.txt)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class scheduler_slot_manager implements renderable {
/**
* @var array list of slots
*/
public $slots = array();
/**
* @var scheduler scheduler in whose context the list is
*/
public $scheduler;
/**
* @var moodle_url action URL for buttons
*/
public $actionurl;
/**
* @var bool should the teacher owning the slot be shown?
*/
public $showteacher = true;
/**
* Add a slot to the list.
*
* @param slot $slotmodel the slot to be added
* @param scheduler_student_list $students the list of students in the slot
* @param bool $editable whether the slot is editable
*/
public function add_slot(slot $slotmodel, scheduler_student_list $students, $editable) {
$slot = new stdClass();
$slot->slotid = $slotmodel->id;
$slot->starttime = $slotmodel->starttime;
$slot->endtime = $slotmodel->endtime;
$slot->location = $slotmodel->appointmentlocation;
$slot->teacher = $slotmodel->get_teacher();
$slot->students = $students;
$slot->editable = $editable;
$slot->isattended = $slotmodel->is_attended();
$slot->isappointed = $slotmodel->get_appointment_count();
$slot->exclusivity = $slotmodel->exclusivity;
$this->slots[] = $slot;
}
/**
* Contructs a slot manager.
*
* @param scheduler $scheduler the scheduler in which the booking takes place
* @param moodle_url $actionurl action URL for buttons
*/
public function __construct(scheduler $scheduler, moodle_url $actionurl) {
$this->scheduler = $scheduler;
$this->actionurl = $actionurl;
}
}
/**
* A list of students displayed to a teacher, with action menus to schedule the students.
*
* @copyright 2014 Henning Bostelmann and others (see README.txt)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class scheduler_scheduling_list implements renderable {
/**
* @var array lines in the list
*/
public $lines = array();
/**
* @var scheduler the scheduler in whose context the list is
*/
public $scheduler;
/**
* @var array extra headers for custom fields in the list
*/
public $extraheaders;
/**
* @var string HTML id of the list
*/
public $id = 'schedulinglist';
/**
* Add a line to the list.
*
* @param string $pix icon to display next to the student's name
* @param string $name name of the student
* @param array $extrafields content of extra data fields to be displayed
* @param array $actions actions to be displayed in an action menu
*/
public function add_line($pix, $name, array $extrafields, $actions) {
$line = new stdClass();
$line->pix = $pix;
$line->name = $name;
$line->extrafields = $extrafields;
$line->actions = $actions;
$this->lines[] = $line;
}
/**
* Contructs a scheduling list.
*
* @param scheduler $scheduler the scheduler in which the booking takes place
* @param array $extraheaders headers for extra data fields
*/
public function __construct(scheduler $scheduler, array $extraheaders) {
$this->scheduler = $scheduler;
$this->extraheaders = $extraheaders;
}
}
/**
* Represents information about a student's total grade in the scheduler, plus gradebook information.
*
* To be used in teacher screens.
*
* @copyright 2014 Henning Bostelmann and others (see README.txt)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class scheduler_totalgrade_info implements renderable {
/**
* @var stdClass|null gradebook grade for the student
*/
public $gbgrade;
/**
* @var scheduler scheduler in whose context the information is
*/
public $scheduler;
/**
* @var bool whether to show a total grade
*/
public $showtotalgrade;
/**
* @var int the total grade to display
*/
public $totalgrade;
/**
* Constructs a grade info object
*
* @param scheduler $scheduler the scheduler in question
* @param stdClass $gbgrade information about the grade in the gradebook (may be null)
* @param bool $showtotalgrade whether the total grade in the scheduler should be shown
* @param int $totalgrade the total grade of the student in this scheduler
*/
public function __construct(scheduler $scheduler, $gbgrade, $showtotalgrade = false, $totalgrade = 0) {
$this->scheduler = $scheduler;
$this->gbgrade = $gbgrade;
$this->showtotalgrade = $showtotalgrade;
$this->totalgrade = $totalgrade;
}
}
/**
* This class represents a list of scheduling conflicts.
*
* @copyright 2014 Henning Bostelmann and others (see README.txt)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class scheduler_conflict_list implements renderable {
/**
* @var array list of conflicts
*/
public $conflicts = array();
/**
* Add a conflict to the list.
*
* @param stdClass $conflict information about the conflict
* @param stdClass $user the user who is affected
*/
public function add_conflict(stdClass $conflict, $user = null) {
$c = clone($conflict);
if ($user) {
$c->userfullname = fullname($user);
} else {
$c->userfullname = '';
}
$this->conflicts[] = $c;
}
/**
* Add several conflicts to the list.
*
* @param array $conflicts information about the conflicts
*/
public function add_conflicts(array $conflicts) {
foreach ($conflicts as $c) {
$this->add_conflict($c);
}
}
}
/**
* Information about an appointment in the scheduler.
*
* @copyright 2014 Henning Bostelmann and others (see README.txt)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class scheduler_appointment_info implements renderable {
/**
* @var scheduler scheduler in whose context the appointment is
*/
public $scheduler;
/**
* @var slot slot in which the appointment is
*/
public $slot;
/**
* @var appointment the appointment itself
*/
public $appointment;
/**
* @var bool whether to show information about the slot (times, etc.)
*/
public $showslotinfo;
/**
* @var bool whether to show booking instructions
*/
public $showbookinginfo;
/**
* @var bool whether to show information about the student
*/
public $showstudentdata;
/**
* @var string information about the group the booking is for
*/
public $groupinfo;
/**
* @var bool whether the information is shown to a student (rather than a teacher)
*/
public $onstudentside;
/**
* @var bool whether to show grades and appointment notes
*/
public $showresult;
/**
* Create appointment information for a new appointment in a slot.
*
* @param slot $slot the slot in question
* @param bool $showbookinginstr whether to show booking instructions
* @param bool $onstudentside whether the screen is shown to a student
* @param string $groupinfo information about the group that the booking is for
* @return scheduler_appointment_info
*/
public static function make_from_slot(slot $slot, $showbookinginstr = true, $onstudentside = true,
$groupinfo = null) {
$info = new scheduler_appointment_info();
$info->slot = $slot;
$info->scheduler = $slot->get_scheduler();
$info->showslotinfo = true;
$info->showbookinginfo = $showbookinginstr;
$info->showstudentdata = false;
$info->showresult = false;
$info->onstudentside = $onstudentside;
$info->groupinfo = $groupinfo;
return $info;
}
/**
* Create appointment information for an existing appointment.
*
* @param slot $slot the slot in question
* @param appointment $appointment the appointment in question
* @param string $onstudentside whether the screen is shown to a student
* @return scheduler_appointment_info
*/
public static function make_from_appointment(slot $slot, appointment $appointment, $onstudentside = true) {
$info = new scheduler_appointment_info();
$info->slot = $slot;
$info->appointment = $appointment;
$info->scheduler = $slot->get_scheduler();
$info->showslotinfo = true;
$info->showboookinginfo = true;
$info->showstudentdata = $info->scheduler->uses_studentdata();
$info->showresult = true;
$info->onstudentside = $onstudentside;
$info->groupinfo = null;
return $info;
}
/**
* Create appointment information for an existing appointment, shown to a teacher.
* This excludes booking instructions and results.
*
* @param slot $slot the slot in question
* @param appointment $appointment the appointment in question
* @return scheduler_appointment_info
*/
public static function make_for_teacher(slot $slot, appointment $appointment) {
$info = new scheduler_appointment_info();
$info->slot = $slot;
$info->appointment = $appointment;
$info->scheduler = $slot->get_scheduler();
$info->showslotinfo = true;
$info->showboookinginfo = false;
$info->showstudentdata = $info->scheduler->uses_studentdata();
$info->showresult = false;
$info->onstudentside = false;
$info->groupinfo = null;
return $info;
}
}