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] [Versions 400 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   * View a user's notifications.
  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  require_once(__DIR__ . '/../../../config.php');
  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  
  32  $url = new moodle_url('/message/output/popup/notifications.php');
  33  $url->param('id', $notificationid);
  34  
  35  $PAGE->set_url($url);
  36  
  37  require_login();
  38  
  39  if (isguestuser()) {
  40      throw new \moodle_exception('guestnoeditmessage', 'message');
  41  }
  42  
  43  if (!$user = $DB->get_record('user', ['id' => $userid])) {
  44      throw new \moodle_exception('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($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  
  66  echo $OUTPUT->header();
  67  echo $OUTPUT->heading(get_string('notifications', 'message'));
  68  
  69  // Display a message if the notifications have not been migrated yet.
  70  if (!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  
  76  echo $renderer->render_from_template('message_popup/notification_area', $context);
  77  echo $OUTPUT->footer();
  78