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.
   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 tool_usertours step_shown event.
  19   *
  20   * @package    tool_usertours
  21   * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace tool_usertours\event;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * The tool_usertours step_shown event.
  31   *
  32   * @package    tool_usertours
  33   * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   *
  36   * @property-read array $other {
  37   *      Extra information about the event.
  38   *
  39   *      - int       tourid:     The id of the tour
  40   *      - string    pageurl:    The URL of the page viewing the tour
  41   * }
  42   */
  43  class step_shown extends \core\event\base {
  44  
  45      /**
  46       * Init method.
  47       */
  48      protected function init() {
  49          $this->data['crud'] = 'r';
  50          $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
  51          $this->data['objecttable'] = 'tool_usertours_steps';
  52      }
  53  
  54      /**
  55       * Returns localised general event name.
  56       *
  57       * @return string
  58       */
  59      public static function get_name() {
  60          return get_string('event_step_shown', 'tool_usertours');
  61      }
  62  
  63      /**
  64       * Custom validation.
  65       *
  66       * @throws \coding_exception
  67       * @return void
  68       */
  69      protected function validate_data() {
  70          parent::validate_data();
  71  
  72          if (!isset($this->other['tourid'])) {
  73              throw new \coding_exception('The \'tourid\' value must be set in other.');
  74          }
  75  
  76          if (!isset($this->other['stepindex'])) {
  77              throw new \coding_exception('The \'stepindex\' value must be set in other.');
  78          }
  79  
  80          if (!isset($this->other['pageurl'])) {
  81              throw new \coding_exception('The \'pageurl\' value must be set in other.');
  82          }
  83      }
  84  
  85  
  86      /**
  87       * This is used when restoring course logs where it is required that we
  88       * map the information in 'other' to it's new value in the new course.
  89       *
  90       * Does nothing in the base class except display a debugging message warning
  91       * the user that the event does not contain the required functionality to
  92       * map this information. For events that do not store any other information this
  93       * won't be called, so no debugging message will be displayed.
  94       *
  95       * @return array an array of other values and their corresponding mapping
  96       */
  97      public static function get_other_mapping() {
  98          return [
  99              'pageurl'   => \core\event\base::NOT_MAPPED,
 100              'tourid'    => [
 101                  'db'        => 'tool_usertours_tours',
 102                  'restore'   => \core\event\base::NOT_MAPPED,
 103              ],
 104              'stepindex' => \core\event\base::NOT_MAPPED,
 105          ];
 106      }
 107  
 108      /**
 109       * This is used when restoring course logs where it is required that we
 110       * map the objectid to it's new value in the new course.
 111       *
 112       * Does nothing in the base class except display a debugging message warning
 113       * the user that the event does not contain the required functionality to
 114       * map this information. For events that do not store an objectid this won't
 115       * be called, so no debugging message will be displayed.
 116       *
 117       * @return string the name of the restore mapping the objectid links to
 118       */
 119      public static function get_objectid_mapping() {
 120          return [
 121              'db'        => 'tool_usertours_steps',
 122              'restore'   => \core\event\base::NOT_MAPPED,
 123          ];
 124      }
 125  
 126      /**
 127       * Returns non-localised event description with id's for admin use only.
 128       *
 129       * @return string
 130       */
 131      public function get_description() {
 132          return "The user with id '{$this->userid}' has viewed the tour with id " .
 133              "'{$this->other['tourid']}' at step index " .
 134              "'{$this->other['stepindex']}' (id '{$this->objectid}') on the page with URL " .
 135              "'{$this->other['pageurl']}'.";
 136      }
 137  
 138      /**
 139       * Returns relevant URL.
 140       *
 141       * @return \moodle_url
 142       */
 143      public function get_url() {
 144          return \tool_usertours\helper::get_edit_step_link($this->other['tourid'], $this->objectid);
 145      }
 146  }