Merge branch 'master_MDL-69848' of https://github.com/golenkovm/moodle
[moodle.git] / message / output / popup / notifications.php
CommitLineData
a038fcf5
RW
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 a user's notifications.
19 *
641b36e2 20 * @package message_popup
a038fcf5
RW
21 * @copyright 2016 Ryan Wyllie <ryan@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
641b36e2 25require_once(__DIR__ . '/../../../config.php');
a038fcf5
RW
26
27$notificationid = optional_param('notificationid', 0, PARAM_INT);
28$offset = optional_param('offset', 0, PARAM_INT);
29$limit = optional_param('limit', 0, PARAM_INT);
30$userid = $USER->id;
31
641b36e2 32$url = new moodle_url('/message/output/popup/notifications.php');
a038fcf5
RW
33$url->param('id', $notificationid);
34
35$PAGE->set_url($url);
36
37require_login();
38
39if (isguestuser()) {
40 print_error('guestnoeditmessage', 'message');
41}
42
43if (!$user = $DB->get_record('user', ['id' => $userid])) {
44 print_error('invaliduserid');
45}
46
47$personalcontext = context_user::instance($user->id);
48
49$PAGE->set_context($personalcontext);
50$PAGE->set_pagelayout('admin');
51
52// Display page header.
53$title = get_string('notifications', 'message');
54$PAGE->set_title("{$SITE->shortname}: " . $title);
55$PAGE->set_heading(fullname($user));
56
57// Grab the renderer.
58$renderer = $PAGE->get_renderer('core', 'message');
59$context = [
60 'notificationid' => $notificationid,
61 'userid' => $userid,
62 'limit' => $limit,
63 'offset' => $offset,
64];
65
66echo $OUTPUT->header();
67echo $OUTPUT->heading(get_string('notifications', 'message'));
23de6f3a
MN
68
69// Display a message if the notifications have not been migrated yet.
70if (!get_user_preferences('core_message_migrate_data', false, $userid)) {
71 $notify = new \core\output\notification(get_string('notificationdatahasnotbeenmigrated', 'message'),
72 \core\output\notification::NOTIFY_WARNING);
73 echo $OUTPUT->render($notify);
74}
75
641b36e2 76echo $renderer->render_from_template('message_popup/notification_area', $context);
a038fcf5
RW
77echo $OUTPUT->footer();
78