Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   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   * 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  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Renders the popup.
  29   *
  30   * @param renderer_base $renderer
  31   * @return string The HTML
  32   */
  33  function message_popup_render_navbar_output(\renderer_base $renderer) {
  34      global $USER, $CFG;
  35  
  36      // Early bail out conditions.
  37      if (!isloggedin() || isguestuser() || \core_user::awaiting_action()) {
  38          return '';
  39      }
  40  
  41      $output = '';
  42  
  43      // Add the notifications popover.
  44      $enabled = \core_message\api::is_processor_enabled("popup");
  45      if ($enabled) {
  46          $unreadcount = \message_popup\api::count_unread_popup_notifications($USER->id);
  47          $caneditownmessageprofile = has_capability('moodle/user:editownmessageprofile', context_system::instance());
  48          $preferencesurl = $caneditownmessageprofile ? new moodle_url('/message/notificationpreferences.php') : null;
  49          $context = [
  50              'userid' => $USER->id,
  51              'unreadcount' => $unreadcount,
  52              'urls' => [
  53                  'seeall' => (new moodle_url('/message/output/popup/notifications.php'))->out(),
  54                  'preferences' => $preferencesurl ? $preferencesurl->out() : null,
  55              ],
  56          ];
  57          $output .= $renderer->render_from_template('message_popup/notification_popover', $context);
  58      }
  59  
  60      // Add the messages popover.
  61      if (!empty($CFG->messaging)) {
  62          $unreadcount = \core_message\api::count_unread_conversations($USER);
  63          $requestcount = \core_message\api::get_received_contact_requests_count($USER->id);
  64          $context = [
  65              'userid' => $USER->id,
  66              'unreadcount' => $unreadcount + $requestcount
  67          ];
  68          $output .= $renderer->render_from_template('core_message/message_popover', $context);
  69      }
  70  
  71      return $output;
  72  }