Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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() || user_not_fully_set_up($USER) ||
  38          get_user_preferences('auth_forcepasswordchange') ||
  39          (!$USER->policyagreed && !is_siteadmin() &&
  40              ($manager = new \core_privacy\local\sitepolicy\manager()) && $manager->is_defined())) {
  41          return '';
  42      }
  43  
  44      $output = '';
  45  
  46      // Add the notifications popover.
  47      $enabled = \core_message\api::is_processor_enabled("popup");
  48      if ($enabled) {
  49          $unreadcount = \message_popup\api::count_unread_popup_notifications($USER->id);
  50          $context = [
  51              'userid' => $USER->id,
  52              'unreadcount' => $unreadcount,
  53              'urls' => [
  54                  'seeall' => (new moodle_url('/message/output/popup/notifications.php'))->out(),
  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  
  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  
  72      return $output;
  73  }