Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   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   * The forum summary report viewed event.
  19   *
  20   * @package forumreport_summary
  21   * @copyright  2019 Michael Hawkins <michaelh@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace forumreport_summary\event;
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * The forum summary report viewed event class.
  30   *
  31   * @package forumreport_summary
  32   * @since      Moodle 3.8
  33   * @copyright  2019 Michael Hawkins <michaelh@moodle.com>
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class report_viewed extends \core\event\base {
  37  
  38      /**
  39       * Set basic properties for the event.
  40       */
  41      protected function init() {
  42          $this->data['crud'] = 'r';
  43          $this->data['edulevel'] = self::LEVEL_TEACHING;
  44      }
  45  
  46      /**
  47       * Returns localised general event name.
  48       *
  49       * @return string
  50       */
  51      public static function get_name() {
  52          return get_string('eventreportviewed', 'forumreport_summary');
  53      }
  54  
  55      /**
  56       * Returns non-localised event description with ids for admin use only.
  57       *
  58       * @return string
  59       */
  60      public function get_description() {
  61          $whose = $this->other['hasviewall'] ? 'the' : 'their own';
  62          $description = "The user with id '{$this->userid}' viewed {$whose} summary report for ";
  63  
  64          if ($this->other['forumid']) {
  65              $description .= "the forum with course module id '{$this->contextinstanceid}'.";
  66          } else {
  67              $description .= "the course with id '{$this->contextinstanceid}'.";
  68          }
  69  
  70          return $description;
  71      }
  72  
  73      /**
  74       * Returns relevant URL.
  75       *
  76       * @return \moodle_url
  77       */
  78      public function get_url() {
  79          $params = ['courseid' => $this->courseid];
  80  
  81          if (!empty($this->other['forumid'])) {
  82              $params['forumid'] = $this->other['forumid'];
  83          }
  84  
  85          return new \moodle_url('/mod/forum/report/summary/index.php', $params);
  86      }
  87  
  88      /**
  89       * Custom validation.
  90       *
  91       * @throws \coding_exception
  92       */
  93      protected function validate_data() {
  94          parent::validate_data();
  95  
  96          if (!isset($this->other['hasviewall'])) {
  97              throw new \coding_exception('The \'hasviewall\' value must be set');
  98          }
  99      }
 100  }