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