Implement data privacy provider.
[moodle-mod_attendance.git] / view.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 * Prints attendance info for particular user
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
26 require_once(dirname(__FILE__).'/../../config.php');
27 require_once(dirname(__FILE__).'/locallib.php');
28
29 $pageparams = new mod_attendance_view_page_params();
30
31 $id = required_param('id', PARAM_INT);
32 $pageparams->studentid = optional_param('studentid', null, PARAM_INT);
33 $pageparams->mode = optional_param('mode', mod_attendance_view_page_params::MODE_THIS_COURSE, PARAM_INT);
34 $pageparams->view = optional_param('view', null, PARAM_INT);
35 $pageparams->curdate = optional_param('curdate', null, PARAM_INT);
36
37 $cm = get_coursemodule_from_id('attendance', $id, 0, false, MUST_EXIST);
38 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
39 $attendance = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
40
41 require_login($course, true, $cm);
42 $context = context_module::instance($cm->id);
43 require_capability('mod/attendance:view', $context);
44
45 $pageparams->init($cm);
46 $att = new mod_attendance_structure($attendance, $cm, $course, $context, $pageparams);
47
48 // Not specified studentid for displaying attendance?
49 // Redirect to appropriate page if can.
50 if (!$pageparams->studentid) {
51 $capabilities = array(
52 'mod/attendance:manageattendances',
53 'mod/attendance:takeattendances',
54 'mod/attendance:changeattendances'
55 );
56 if (has_any_capability($capabilities, $context)) {
57 redirect($att->url_manage());
58 } else if (has_capability('mod/attendance:viewreports', $context)) {
59 redirect($att->url_report());
60 }
61 }
62
63 $PAGE->set_url($att->url_view());
64 $PAGE->set_title($course->shortname. ": ".$att->name);
65 $PAGE->set_heading($course->fullname);
66 $PAGE->set_cacheable(true);
67 $PAGE->navbar->add(get_string('attendancereport', 'attendance'));
68
69 $output = $PAGE->get_renderer('mod_attendance');
70
71 if (isset($pageparams->studentid) && $USER->id != $pageparams->studentid) {
72 // Only users with proper permissions should be able to see any user's individual report.
73 require_capability('mod/attendance:viewreports', $context);
74 $userid = $pageparams->studentid;
75 } else {
76 // A valid request to see another users report has not been sent, show the user's own.
77 $userid = $USER->id;
78 }
79
80 $userdata = new attendance_user_data($att, $userid);
81 $header = new mod_attendance_header($att);
82
83 echo $output->header();
84
85 echo $output->render($header);
86 echo $output->render($userdata);
87
88 echo $output->footer();