Implement data privacy provider.
[moodle-mod_attendance.git] / renderables.php
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17 /**
18 * Attendance module renderable components are defined here
19 *
20 * @package mod_attendance
21 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25 defined('MOODLE_INTERNAL') || die();
26
27 require_once(dirname(__FILE__).'/locallib.php');
28
29
30 /**
31 * Represents info about attendance tabs.
32 *
33 * Proxy class for security reasons (renderers must not have access to all attendance methods)
34 *
35 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 *
38 */
39 class attendance_tabs implements renderable {
40 /** Sessions tab */
41 const TAB_SESSIONS = 1;
42 /** Add tab */
43 const TAB_ADD = 2;
44 /** Rerort tab */
45 const TAB_REPORT = 3;
46 /** Export tab */
47 const TAB_EXPORT = 4;
48 /** Preferences tab */
49 const TAB_PREFERENCES = 5;
50 /** Temp users tab */
51 const TAB_TEMPORARYUSERS = 6; // Tab for managing temporary users.
52 /** Update tab */
53 const TAB_UPDATE = 7;
54 /** Warnings tab */
55 const TAB_WARNINGS = 8;
56 /** Absentee tab */
57 const TAB_ABSENTEE = 9;
58 /** @var int current tab */
59 public $currenttab;
60
61 /** @var stdClass attendance */
62 private $att;
63
64 /**
65 * Prepare info about sessions for attendance taking into account view parameters.
66 *
67 * @param mod_attendance_structure $att
68 * @param int $currenttab - one of attendance_tabs constants
69 */
70 public function __construct(mod_attendance_structure $att, $currenttab=null) {
71 $this->att = $att;
72 $this->currenttab = $currenttab;
73 }
74
75 /**
76 * Return array of rows where each row is an array of tab objects
77 * taking into account permissions of current user
78 */
79 public function get_tabs() {
80 $toprow = array();
81 $context = $this->att->context;
82 $capabilities = array(
83 'mod/attendance:manageattendances',
84 'mod/attendance:takeattendances',
85 'mod/attendance:changeattendances'
86 );
87 if (has_any_capability($capabilities, $context)) {
88 $toprow[] = new tabobject(self::TAB_SESSIONS, $this->att->url_manage()->out(),
89 get_string('sessions', 'attendance'));
90 }
91
92 if (has_capability('mod/attendance:manageattendances', $context)) {
93 $toprow[] = new tabobject(self::TAB_ADD,
94 $this->att->url_sessions()->out(true,
95 array('action' => mod_attendance_sessions_page_params::ACTION_ADD)),
96 get_string('addsession', 'attendance'));
97 }
98 if (has_capability('mod/attendance:viewreports', $context)) {
99 $toprow[] = new tabobject(self::TAB_REPORT, $this->att->url_report()->out(),
100 get_string('report', 'attendance'));
101 }
102
103 if (has_capability('mod/attendance:viewreports', $context) &&
104 get_config('attendance', 'enablewarnings')) {
105 $toprow[] = new tabobject(self::TAB_ABSENTEE, $this->att->url_absentee()->out(),
106 get_string('absenteereport', 'attendance'));
107 }
108
109 if (has_capability('mod/attendance:export', $context)) {
110 $toprow[] = new tabobject(self::TAB_EXPORT, $this->att->url_export()->out(),
111 get_string('export', 'attendance'));
112 }
113
114 if (has_capability('mod/attendance:changepreferences', $context)) {
115 $toprow[] = new tabobject(self::TAB_PREFERENCES, $this->att->url_preferences()->out(),
116 get_string('statussetsettings', 'attendance'));
117
118 if (get_config('attendance', 'enablewarnings')) {
119 $toprow[] = new tabobject(self::TAB_WARNINGS, $this->att->url_warnings()->out(),
120 get_string('warnings', 'attendance'));
121 }
122 }
123 if (has_capability('mod/attendance:managetemporaryusers', $context)) {
124 $toprow[] = new tabobject(self::TAB_TEMPORARYUSERS, $this->att->url_managetemp()->out(),
125 get_string('tempusers', 'attendance'));
126 }
127 if ($this->currenttab == self::TAB_UPDATE && has_capability('mod/attendance:manageattendances', $context)) {
128 $toprow[] = new tabobject(self::TAB_UPDATE,
129 $this->att->url_sessions()->out(true,
130 array('action' => mod_attendance_sessions_page_params::ACTION_UPDATE)),
131 get_string('changesession', 'attendance'));
132 }
133
134 return array($toprow);
135 }
136 }
137
138 /**
139 * Class attendance_filter_controls
140 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
141 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
142 */
143 class attendance_filter_controls implements renderable {
144 /** @var int current view mode */
145 public $pageparams;
146 /** @var stdclass */
147 public $cm;
148 /** @var int */
149 public $curdate;
150 /** @var int */
151 public $prevcur;
152 /** @var int */
153 public $nextcur;
154 /** @var string */
155 public $curdatetxt;
156 /** @var boolean */
157 public $reportcontrol;
158 /** @var string */
159 private $urlpath;
160 /** @var array */
161 private $urlparams;
162 /** @var mod_attendance_structure */
163 public $att;
164
165 /**
166 * attendance_filter_controls constructor.
167 * @param mod_attendance_structure $att
168 * @param bool $report
169 */
170 public function __construct(mod_attendance_structure $att, $report = false) {
171 global $PAGE;
172
173 $this->pageparams = $att->pageparams;
174
175 $this->cm = $att->cm;
176
177 // This is a report control only if $reports is true and the attendance block can be graded.
178 $this->reportcontrol = $report;
179
180 $this->curdate = $att->pageparams->curdate;
181
182 $date = usergetdate($att->pageparams->curdate);
183 $mday = $date['mday'];
184 $mon = $date['mon'];
185 $year = $date['year'];
186
187 switch ($this->pageparams->view) {
188 case ATT_VIEW_DAYS:
189 $format = get_string('strftimedm', 'attendance');
190 $this->prevcur = make_timestamp($year, $mon, $mday - 1);
191 $this->nextcur = make_timestamp($year, $mon, $mday + 1);
192 $this->curdatetxt = userdate($att->pageparams->startdate, $format);
193 break;
194 case ATT_VIEW_WEEKS:
195 $format = get_string('strftimedm', 'attendance');
196 $this->prevcur = $att->pageparams->startdate - WEEKSECS;
197 $this->nextcur = $att->pageparams->startdate + WEEKSECS;
198 $this->curdatetxt = userdate($att->pageparams->startdate, $format).
199 " - ".userdate($att->pageparams->enddate, $format);
200 break;
201 case ATT_VIEW_MONTHS:
202 $format = '%B';
203 $this->prevcur = make_timestamp($year, $mon - 1);
204 $this->nextcur = make_timestamp($year, $mon + 1);
205 $this->curdatetxt = userdate($att->pageparams->startdate, $format);
206 break;
207 }
208
209 $this->urlpath = $PAGE->url->out_omit_querystring();
210 $params = $att->pageparams->get_significant_params();
211 $params['id'] = $att->cm->id;
212 $this->urlparams = $params;
213
214 $this->att = $att;
215 }
216
217 /**
218 * Helper function for url.
219 *
220 * @param array $params
221 * @return moodle_url
222 */
223 public function url($params=array()) {
224 $params = array_merge($this->urlparams, $params);
225
226 return new moodle_url($this->urlpath, $params);
227 }
228
229 /**
230 * Helper function for url path.
231 * @return string
232 */
233 public function url_path() {
234 return $this->urlpath;
235 }
236
237 /**
238 * Helper function for url_params.
239 * @param array $params
240 * @return array
241 */
242 public function url_params($params=array()) {
243 $params = array_merge($this->urlparams, $params);
244
245 return $params;
246 }
247
248 /**
249 * Return groupmode.
250 * @return int
251 */
252 public function get_group_mode() {
253 return $this->att->get_group_mode();
254 }
255
256 /**
257 * Return groupslist.
258 * @return mixed
259 */
260 public function get_sess_groups_list() {
261 return $this->att->pageparams->get_sess_groups_list();
262 }
263
264 /**
265 * Get current session type.
266 * @return mixed
267 */
268 public function get_current_sesstype() {
269 return $this->att->pageparams->get_current_sesstype();
270 }
271 }
272
273 /**
274 * Represents info about attendance sessions taking into account view parameters.
275 *
276 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
277 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
278 */
279 class attendance_manage_data implements renderable {
280 /** @var array of sessions*/
281 public $sessions;
282
283 /** @var int number of hidden sessions (sessions before $course->startdate)*/
284 public $hiddensessionscount;
285 /** @var array */
286 public $groups;
287 /** @var int */
288 public $hiddensesscount;
289
290 /** @var mod_attendance_structure */
291 public $att;
292 /**
293 * Prepare info about attendance sessions taking into account view parameters.
294 *
295 * @param mod_attendance_structure $att instance
296 */
297 public function __construct(mod_attendance_structure $att) {
298
299 $this->sessions = $att->get_filtered_sessions();
300
301 $this->groups = groups_get_all_groups($att->course->id);
302
303 $this->hiddensessionscount = $att->get_hidden_sessions_count();
304
305 $this->att = $att;
306 }
307
308 /**
309 * Helper function to return urls.
310 * @param int $sessionid
311 * @param int $grouptype
312 * @return mixed
313 */
314 public function url_take($sessionid, $grouptype) {
315 return url_helpers::url_take($this->att, $sessionid, $grouptype);
316 }
317
318 /**
319 * Must be called without or with both parameters
320 *
321 * @param int $sessionid
322 * @param null $action
323 * @return mixed
324 */
325 public function url_sessions($sessionid=null, $action=null) {
326 return url_helpers::url_sessions($this->att, $sessionid, $action);
327 }
328 }
329
330 /**
331 * class take data.
332 *
333 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
334 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
335 */
336 class attendance_take_data implements renderable {
337 /** @var array */
338 public $users;
339 /** @var array|null|stdClass */
340 public $pageparams;
341 /** @var int */
342 public $groupmode;
343 /** @var stdclass */
344 public $cm;
345 /** @var array */
346 public $statuses;
347 /** @var mixed */
348 public $sessioninfo;
349 /** @var array */
350 public $sessionlog;
351 /** @var array */
352 public $sessions4copy;
353 /** @var bool */
354 public $updatemode;
355 /** @var string */
356 private $urlpath;
357 /** @var array */
358 private $urlparams;
359 /** @var mod_attendance_structure */
360 public $att;
361
362 /**
363 * attendance_take_data constructor.
364 * @param mod_attendance_structure $att
365 */
366 public function __construct(mod_attendance_structure $att) {
367 if ($att->pageparams->grouptype) {
368 $this->users = $att->get_users($att->pageparams->grouptype, $att->pageparams->page);
369 } else {
370 $this->users = $att->get_users($att->pageparams->group, $att->pageparams->page);
371 }
372
373 $this->pageparams = $att->pageparams;
374
375 $this->groupmode = $att->get_group_mode();
376 $this->cm = $att->cm;
377
378 $this->statuses = $att->get_statuses();
379
380 $this->sessioninfo = $att->get_session_info($att->pageparams->sessionid);
381 $this->updatemode = $this->sessioninfo->lasttaken > 0;
382
383 if (isset($att->pageparams->copyfrom)) {
384 $this->sessionlog = $att->get_session_log($att->pageparams->copyfrom);
385 } else if ($this->updatemode) {
386 $this->sessionlog = $att->get_session_log($att->pageparams->sessionid);
387 } else {
388 $this->sessionlog = array();
389 }
390
391 if (!$this->updatemode) {
392 $this->sessions4copy = $att->get_today_sessions_for_copy($this->sessioninfo);
393 }
394
395 $this->urlpath = $att->url_take()->out_omit_querystring();
396 $params = $att->pageparams->get_significant_params();
397 $params['id'] = $att->cm->id;
398 $this->urlparams = $params;
399
400 $this->att = $att;
401 }
402
403 /**
404 * Url function
405 * @param array $params
406 * @param array $excludeparams
407 * @return moodle_url
408 */
409 public function url($params=array(), $excludeparams=array()) {
410 $params = array_merge($this->urlparams, $params);
411
412 foreach ($excludeparams as $paramkey) {
413 unset($params[$paramkey]);
414 }
415
416 return new moodle_url($this->urlpath, $params);
417 }
418
419 /**
420 * Url view helper.
421 * @param array $params
422 * @return mixed
423 */
424 public function url_view($params=array()) {
425 return url_helpers::url_view($this->att, $params);
426 }
427
428 /**
429 * Url path helper.
430 * @return string
431 */
432 public function url_path() {
433 return $this->urlpath;
434 }
435 }
436
437 /**
438 * Class user data.
439 *
440 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
441 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
442 */
443 class attendance_user_data implements renderable {
444 /** @var mixed|object */
445 public $user;
446 /** @var array|null|stdClass */
447 public $pageparams;
448 /** @var array */
449 public $statuses;
450 /** @var array */
451 public $summary;
452 /** @var attendance_filter_controls */
453 public $filtercontrols;
454 /** @var array */
455 public $sessionslog;
456 /** @var array */
457 public $groups;
458 /** @var array */
459 public $coursesatts;
460 /** @var string */
461 private $urlpath;
462 /** @var array */
463 private $urlparams;
464
465 /**
466 * attendance_user_data constructor.
467 * @param mod_attendance_structure $att
468 * @param int $userid
469 */
470 public function __construct(mod_attendance_structure $att, $userid) {
471 $this->user = $att->get_user($userid);
472
473 $this->pageparams = $att->pageparams;
474
475 if ($this->pageparams->mode == mod_attendance_view_page_params::MODE_THIS_COURSE) {
476 $this->statuses = $att->get_statuses(true, true);
477
478 $this->summary = new mod_attendance_summary($att->id, array($userid), $att->pageparams->startdate,
479 $att->pageparams->enddate);
480
481 $this->filtercontrols = new attendance_filter_controls($att);
482
483 $this->sessionslog = $att->get_user_filtered_sessions_log_extended($userid);
484
485 $this->groups = groups_get_all_groups($att->course->id);
486 } else {
487 $this->coursesatts = attendance_get_user_courses_attendances($userid);
488 $this->statuses = array();
489 $this->summary = array();
490 foreach ($this->coursesatts as $atid => $ca) {
491 // Check to make sure the user can view this cm.
492 $modinfo = get_fast_modinfo($ca->courseid);
493 if (!$modinfo->instances['attendance'][$ca->attid]->uservisible) {
494 unset($this->coursesatts[$atid]);
495 continue;
496 } else {
497 $this->coursesatts[$atid]->cmid = $modinfo->instances['attendance'][$ca->attid]->get_course_module_record()->id;
498 }
499 $this->statuses[$ca->attid] = attendance_get_statuses($ca->attid);
500 $this->summary[$ca->attid] = new mod_attendance_summary($ca->attid, array($userid));
501 }
502 }
503 $this->urlpath = $att->url_view()->out_omit_querystring();
504 $params = $att->pageparams->get_significant_params();
505 $params['id'] = $att->cm->id;
506 $this->urlparams = $params;
507 }
508
509 /**
510 * url helper.
511 * @return moodle_url
512 */
513 public function url() {
514 return new moodle_url($this->urlpath, $this->urlparams);
515 }
516 }
517
518 /**
519 * Class report data.
520 *
521 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
522 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
523 */
524 class attendance_report_data implements renderable {
525 /** @var array|null|stdClass */
526 public $pageparams;
527 /** @var array */
528 public $users;
529 /** @var array */
530 public $groups;
531 /** @var array */
532 public $sessions;
533 /** @var array */
534 public $statuses;
535 /** @var array includes disablrd/deleted statuses. */
536 public $allstatuses;
537 /** @var array */
538 public $usersgroups = array();
539 /** @var array */
540 public $sessionslog = array();
541 /** @var array|mod_attendance_summary */
542 public $summary = array();
543 /** @var mod_attendance_structure */
544 public $att;
545
546 /**
547 * attendance_report_data constructor.
548 * @param mod_attendance_structure $att
549 */
550 public function __construct(mod_attendance_structure $att) {
551 $currenttime = time();
552 if ($att->pageparams->view == ATT_VIEW_NOTPRESENT) {
553 $att->pageparams->enddate = $currenttime;
554 }
555
556 $this->pageparams = $att->pageparams;
557
558 $this->users = $att->get_users($att->pageparams->group, $att->pageparams->page);
559
560 if (isset($att->pageparams->userids)) {
561 foreach ($this->users as $key => $user) {
562 if (!in_array($user->id, $att->pageparams->userids)) {
563 unset($this->users[$key]);
564 }
565 }
566 }
567
568 $this->groups = groups_get_all_groups($att->course->id);
569
570 $this->sessions = $att->get_filtered_sessions();
571
572 $this->statuses = $att->get_statuses(true, true);
573 $this->allstatuses = $att->get_statuses(false, true);
574
575 if ($att->pageparams->view == ATT_VIEW_SUMMARY) {
576 $this->summary = new mod_attendance_summary($att->id);
577 } else {
578 $this->summary = new mod_attendance_summary($att->id, array_keys($this->users),
579 $att->pageparams->startdate, $att->pageparams->enddate);
580 }
581
582 foreach ($this->users as $key => $user) {
583 $usersummary = $this->summary->get_taken_sessions_summary_for($user->id);
584 if ($att->pageparams->view != ATT_VIEW_NOTPRESENT ||
585 $usersummary->takensessionspoints < $usersummary->takensessionsmaxpoints ||
586 $usersummary->takensessionsmaxpoints == 0) {
587 $this->usersgroups[$user->id] = groups_get_all_groups($att->course->id, $user->id);
588
589 $this->sessionslog[$user->id] = $att->get_user_filtered_sessions_log($user->id);
590 } else {
591 unset($this->users[$key]);
592 }
593 }
594
595 $this->att = $att;
596 }
597
598 /**
599 * url take helper.
600 * @param int $sessionid
601 * @param int $grouptype
602 * @return mixed
603 */
604 public function url_take($sessionid, $grouptype) {
605 return url_helpers::url_take($this->att, $sessionid, $grouptype);
606 }
607
608 /**
609 * url view helper.
610 * @param array $params
611 * @return mixed
612 */
613 public function url_view($params=array()) {
614 return url_helpers::url_view($this->att, $params);
615 }
616
617 /**
618 * url helper.
619 * @param array $params
620 * @return moodle_url
621 */
622 public function url($params=array()) {
623 $params = array_merge($params, $this->pageparams->get_significant_params());
624
625 return $this->att->url_report($params);
626 }
627
628 }
629
630 /**
631 * Class preferences data.
632 *
633 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
634 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
635 */
636 class attendance_preferences_data implements renderable {
637 /** @var array */
638 public $statuses;
639 /** @var mod_attendance_structure */
640 private $att;
641 /** @var array */
642 public $errors;
643
644 /**
645 * attendance_preferences_data constructor.
646 * @param mod_attendance_structure $att
647 * @param array $errors
648 */
649 public function __construct(mod_attendance_structure $att, $errors) {
650 $this->statuses = $att->get_statuses(false);
651 $this->errors = $errors;
652
653 foreach ($this->statuses as $st) {
654 $st->haslogs = attendance_has_logs_for_status($st->id);
655 }
656
657 $this->att = $att;
658 }
659
660 /**
661 * url helper function
662 * @param array $params
663 * @param bool $significantparams
664 * @return moodle_url
665 */
666 public function url($params=array(), $significantparams=true) {
667 if ($significantparams) {
668 $params = array_merge($this->att->pageparams->get_significant_params(), $params);
669 }
670
671 return $this->att->url_preferences($params);
672 }
673 }
674
675 /**
676 * Default status set
677 *
678 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
679 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
680 */
681 class attendance_default_statusset implements renderable {
682 /** @var array */
683 public $statuses;
684 /** @var array */
685 public $errors;
686
687 /**
688 * attendance_default_statusset constructor.
689 * @param array $statuses
690 * @param array $errors
691 */
692 public function __construct($statuses, $errors) {
693 $this->statuses = $statuses;
694 $this->errors = $errors;
695 }
696
697 /**
698 * url helper.
699 * @param stdClass $params
700 * @return moodle_url
701 */
702 public function url($params) {
703 return new moodle_url('/mod/attendance/defaultstatus.php', $params);
704 }
705 }
706
707 /**
708 * Output a selector to change between status sets.
709 *
710 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
711 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
712 */
713 class attendance_set_selector implements renderable {
714 /** @var int */
715 public $maxstatusset;
716 /** @var mod_attendance_structure */
717 private $att;
718
719 /**
720 * attendance_set_selector constructor.
721 * @param mod_attendance_structure $att
722 * @param int $maxstatusset
723 */
724 public function __construct(mod_attendance_structure $att, $maxstatusset) {
725 $this->att = $att;
726 $this->maxstatusset = $maxstatusset;
727 }
728
729 /**
730 * url helper
731 * @param array $statusset
732 * @return moodle_url
733 */
734 public function url($statusset) {
735 $params = array();
736 $params['statusset'] = $statusset;
737
738 return $this->att->url_preferences($params);
739 }
740
741 /**
742 * get current statusset.
743 * @return int
744 */
745 public function get_current_statusset() {
746 if (isset($this->att->pageparams->statusset)) {
747 return $this->att->pageparams->statusset;
748 }
749 return 0;
750 }
751
752 /**
753 * get statusset name.
754 * @param int $statusset
755 * @return string
756 */
757 public function get_status_name($statusset) {
758 return attendance_get_setname($this->att->id, $statusset, true);
759 }
760 }
761
762 /**
763 * Url helpers
764 *
765 * @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
766 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
767 */
768 class url_helpers {
769 /**
770 * Url take.
771 * @param stdClass $att
772 * @param int $sessionid
773 * @param int $grouptype
774 * @return mixed
775 */
776 public static function url_take($att, $sessionid, $grouptype) {
777 $params = array('sessionid' => $sessionid);
778 if (isset($grouptype)) {
779 $params['grouptype'] = $grouptype;
780 }
781
782 return $att->url_take($params);
783 }
784
785 /**
786 * Must be called without or with both parameters
787 * @param stdClass $att
788 * @param null $sessionid
789 * @param null $action
790 * @return mixed
791 */
792 public static function url_sessions($att, $sessionid=null, $action=null) {
793 if (isset($sessionid) && isset($action)) {
794 $params = array('sessionid' => $sessionid, 'action' => $action);
795 } else {
796 $params = array();
797 }
798
799 return $att->url_sessions($params);
800 }
801
802 /**
803 * Url view helper.
804 * @param stdClass $att
805 * @param array $params
806 * @return mixed
807 */
808 public static function url_view($att, $params=array()) {
809 return $att->url_view($params);
810 }
811 }
812
813 /**
814 * Data structure representing an attendance password icon.
815 *
816 * @copyright 2017 Dan Marsden
817 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
818 */
819 class attendance_password_icon implements renderable, templatable {
820
821 /**
822 * @var string text to show
823 */
824 public $text;
825
826 /**
827 * @var string Extra descriptive text next to the icon
828 */
829 public $linktext = null;
830
831 /**
832 * Constructor
833 *
834 * @param string $text string for help page title,
835 * string with _help suffix is used for the actual help text.
836 * string with _link suffix is used to create a link to further info (if it exists)
837 * @param string $sessionid
838 */
839 public function __construct($text, $sessionid) {
840 $this->text = $text;
841 $this->sessionid = $sessionid;
842 }
843
844 /**
845 * Export this data so it can be used as the context for a mustache template.
846 *
847 * @param renderer_base $output Used to do a final render of any components that need to be rendered for export.
848 * @return array
849 */
850 public function export_for_template(renderer_base $output) {
851
852 $title = get_string('password', 'attendance');
853
854 $data = new stdClass();
855 $data->heading = '';
856 $data->text = $this->text;
857
858 $data->alt = $title;
859 $data->icon = (new pix_icon('key', '', 'attendance'))->export_for_template($output);
860 $data->linktext = '';
861 $data->title = $title;
862 $data->url = (new moodle_url('/mod/attendance/password.php', [
863 'session' => $this->sessionid]))->out(false);
864
865 $data->ltr = !right_to_left();
866 return $data;
867 }
868 }