MDL-62418 tool_policy: Display blocks in user policies and agreements
[moodle.git] / admin / tool / policy / user.php
CommitLineData
cf398020
MG
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 * View user acceptances to the policies
19 *
20 * @package tool_policy
21 * @copyright 2018 Marina Glancy
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25require(__DIR__.'/../../../config.php');
26require_once($CFG->dirroot.'/user/editlib.php');
27
28$userid = optional_param('userid', null, PARAM_INT);
29$returnurl = optional_param('returnurl', null, PARAM_LOCALURL);
30
31require_login();
32$userid = $userid ?: $USER->id;
33if (isguestuser() || isguestuser($userid)) {
34 print_error('noguest');
35}
36$context = context_user::instance($userid);
37if ($userid != $USER->id) {
38 // Check capability to view acceptances. No capability is needed to view your own acceptances.
39 if (!has_capability('tool/policy:acceptbehalf', $context)) {
40 require_capability('tool/policy:viewacceptances', $context);
41 }
42}
43
44$PAGE->set_context($context);
0bffcfcc 45$PAGE->set_pagelayout('standard');
cf398020
MG
46$PAGE->set_url(new moodle_url('/admin/tool/policy/user.php', ['userid' => $userid]));
47
48$output = $PAGE->get_renderer('tool_policy');
49echo $output->header();
50echo $output->heading(get_string('policiesagreements', 'tool_policy'));
51$acceptances = new \tool_policy\output\acceptances($userid, $returnurl);
52echo $output->render($acceptances);
53$PAGE->requires->js_call_amd('tool_policy/acceptmodal', 'getInstance', [context_system::instance()->id]);
54echo $output->footer();