MDL-69848 upgrade: Delete notifications in chunks
[moodle.git] / message / output / popup / lib.php
CommitLineData
7d69958e
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
7d69958e
RW
17/**
18 * Contains standard functions for message_popup.
19 *
20 * @package message_popup
21 * @copyright 2016 Ryan Wyllie <ryan@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
84e03ed8 25defined('MOODLE_INTERNAL') || die();
26
7d69958e
RW
27/**
28 * Renders the popup.
29 *
30 * @param renderer_base $renderer
31 * @return string The HTML
32 */
33function message_popup_render_navbar_output(\renderer_base $renderer) {
3c1cdac6 34 global $USER, $CFG;
7d69958e
RW
35
36 // Early bail out conditions.
fd9a64a3 37 if (!isloggedin() || isguestuser() || user_not_fully_set_up($USER) ||
b5b7af96 38 get_user_preferences('auth_forcepasswordchange') ||
1727c939
MG
39 (!$USER->policyagreed && !is_siteadmin() &&
40 ($manager = new \core_privacy\local\sitepolicy\manager()) && $manager->is_defined())) {
7d69958e
RW
41 return '';
42 }
43
44 $output = '';
45
7d69958e 46 // Add the notifications popover.
20ab51fd
AA
47 $enabled = \core_message\api::is_processor_enabled("popup");
48 if ($enabled) {
84e03ed8 49 $unreadcount = \message_popup\api::count_unread_popup_notifications($USER->id);
7d69958e
RW
50 $context = [
51 'userid' => $USER->id,
84e03ed8 52 'unreadcount' => $unreadcount,
7d69958e 53 'urls' => [
a6a277f0 54 'seeall' => (new moodle_url('/message/output/popup/notifications.php'))->out(),
7d69958e
RW
55 'preferences' => (new moodle_url('/message/notificationpreferences.php', ['userid' => $USER->id]))->out(),
56 ],
57 ];
58 $output .= $renderer->render_from_template('message_popup/notification_popover', $context);
59 }
60
77e5b446
BB
61 // Add the messages popover.
62 if (!empty($CFG->messaging)) {
63 $unreadcount = \core_message\api::count_unread_conversations($USER);
64 $requestcount = \core_message\api::get_received_contact_requests_count($USER->id);
65 $context = [
66 'userid' => $USER->id,
67 'unreadcount' => $unreadcount + $requestcount
68 ];
69 $output .= $renderer->render_from_template('core_message/message_popover', $context);
70 }
71
7d69958e
RW
72 return $output;
73}