Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 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   * Abstract event for content viewing.
  18   *
  19   * This class has been deprecated, please extend base event or other relevent abstract class.
  20   *
  21   * @package    core
  22   * @copyright  2013 Ankit Agarwal
  23   * @deprecated since Moodle 2.7
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  namespace core\event;
  28  
  29  defined('MOODLE_INTERNAL') || die();
  30  
  31  debugging('core\event\content_viewed has been deprecated. Please extend base event or other relevant abstract class.',
  32          DEBUG_DEVELOPER);
  33  
  34  /**
  35   * Class content_viewed.
  36   *
  37   * This class has been deprecated, please extend base event or other relevent abstract class.
  38   *
  39   * @property-read array $other {
  40   *      Extra information about the event.
  41   *
  42   *      - string content: name of the content viewed.
  43   * }
  44   *
  45   * @package    core
  46   * @since      Moodle 2.6
  47   * @copyright  2013 Ankit Agarwal
  48   * @deprecated since Moodle 2.7
  49   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  50   */
  51  abstract class content_viewed extends base {
  52  
  53      /** @var null|array $legacylogdata  Legacy log data */
  54      protected $legacylogdata = null;
  55  
  56      /**
  57       * Set basic properties of the event.
  58       */
  59      protected function init() {
  60          global $PAGE;
  61  
  62          $this->data['crud'] = 'r';
  63          $this->data['edulevel'] = self::LEVEL_OTHER;
  64          $this->context = $PAGE->context;
  65      }
  66  
  67      /**
  68       * Set basic page properties.
  69       */
  70      public function set_page_detail() {
  71          global $PAGE;
  72          if (!isset($this->data['other'])) {
  73              $this->data['other'] = array();
  74          }
  75          $this->data['other'] = array_merge(array('url'     => $PAGE->url->out_as_local_url(false),
  76                                               'heading'     => $PAGE->heading,
  77                                               'title'       => $PAGE->title), $this->data['other']);
  78      }
  79  
  80      /**
  81       * Returns localised general event name.
  82       *
  83       * @return string
  84       */
  85      public static function get_name() {
  86          return get_string('eventcontentviewed', 'moodle');
  87      }
  88  
  89      /**
  90       * Returns non-localised description of what happened.
  91       *
  92       * @return string
  93       */
  94      public function get_description() {
  95          return "The user with id '$this->userid' viewed content.";
  96      }
  97  
  98      /**
  99       * Custom validation.
 100       *
 101       * @throws \coding_exception when validation does not pass.
 102       * @return void
 103       */
 104      protected function validate_data() {
 105          parent::validate_data();
 106          // Make sure this class is never used without a content identifier.
 107          if (empty($this->other['content'])) {
 108              throw new \coding_exception('The \'content\' value must be set in other.');
 109          }
 110      }
 111  
 112      public static function get_other_mapping() {
 113          return false;
 114      }
 115  
 116      /**
 117       * This event has been deprected.
 118       *
 119       * @return boolean
 120       */
 121      public static function is_deprecated() {
 122          return true;
 123      }
 124  }