| 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 | /**
 | 
        
           |  |  | 18 |  * Event for when a template is updated.
 | 
        
           |  |  | 19 |  *
 | 
        
           |  |  | 20 |  * @package    quizaccess_seb
 | 
        
           |  |  | 21 |  * @author     Nicholas Hoobin <nicholashoobin@catalyst-au.net>
 | 
        
           |  |  | 22 |  * @copyright  2020 Catalyst IT
 | 
        
           |  |  | 23 |  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 24 |  */
 | 
        
           |  |  | 25 |   | 
        
           |  |  | 26 | namespace quizaccess_seb\event;
 | 
        
           |  |  | 27 |   | 
        
           |  |  | 28 | use context_system;
 | 
        
           |  |  | 29 | use core\event\base;
 | 
        
           |  |  | 30 | use quizaccess_seb\template;
 | 
        
           |  |  | 31 |   | 
        
           |  |  | 32 | defined('MOODLE_INTERNAL') || die();
 | 
        
           |  |  | 33 |   | 
        
           |  |  | 34 | /**
 | 
        
           |  |  | 35 |  * Event for when a template is updated.
 | 
        
           |  |  | 36 |  *
 | 
        
           |  |  | 37 |  * @copyright  2020 Catalyst IT
 | 
        
           |  |  | 38 |  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 39 |  */
 | 
        
           |  |  | 40 | class template_updated extends base {
 | 
        
           |  |  | 41 |   | 
        
           |  |  | 42 |     /**
 | 
        
           |  |  | 43 |      * Create event with strict parameters.
 | 
        
           |  |  | 44 |      *
 | 
        
           |  |  | 45 |      * Define strict parameters to create event with instead of relying on internal validation of array. Better code practice.
 | 
        
           |  |  | 46 |      * Easier for consumers of this class to know what data must be supplied and observers can have more trust in event data.
 | 
        
           |  |  | 47 |      *
 | 
        
           |  |  | 48 |      * @param template $template SEB template.
 | 
        
           |  |  | 49 |      * @param context_system $context Context system.
 | 
        
           |  |  | 50 |      * @return base
 | 
        
           |  |  | 51 |      */
 | 
        
           |  |  | 52 |     public static function create_strict(template $template, context_system $context): base {
 | 
        
           |  |  | 53 |         global $USER;
 | 
        
           |  |  | 54 |         $tid = $template->get('id');
 | 
        
           |  |  | 55 |   | 
        
           |  |  | 56 |         return self::create([
 | 
        
           |  |  | 57 |             'userid' => $USER->id,
 | 
        
           |  |  | 58 |             'objectid' => $tid,
 | 
        
           |  |  | 59 |             'context' => $context,
 | 
        
           |  |  | 60 |         ]);
 | 
        
           |  |  | 61 |     }
 | 
        
           |  |  | 62 |   | 
        
           |  |  | 63 |     /**
 | 
        
           |  |  | 64 |      * Initialize the event data.
 | 
        
           |  |  | 65 |      */
 | 
        
           |  |  | 66 |     protected function init() {
 | 
        
           |  |  | 67 |         $this->data['objecttable'] = 'quizaccess_seb_template';
 | 
        
           |  |  | 68 |         $this->data['crud'] = 'u';
 | 
        
           |  |  | 69 |         $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
 | 
        
           |  |  | 70 |     }
 | 
        
           |  |  | 71 |   | 
        
           |  |  | 72 |     /**
 | 
        
           |  |  | 73 |      * Get the name of the event.
 | 
        
           |  |  | 74 |      *
 | 
        
           |  |  | 75 |      * @return string Name of event.
 | 
        
           |  |  | 76 |      */
 | 
        
           |  |  | 77 |     public static function get_name() {
 | 
        
           |  |  | 78 |         return get_string('event:templateupdated', 'quizaccess_seb');
 | 
        
           |  |  | 79 |     }
 | 
        
           |  |  | 80 |   | 
        
           |  |  | 81 |     /**
 | 
        
           |  |  | 82 |      * Returns relevant URL.
 | 
        
           |  |  | 83 |      * @return \moodle_url
 | 
        
           |  |  | 84 |      */
 | 
        
           |  |  | 85 |     public function get_url() {
 | 
        
           |  |  | 86 |         $params = [
 | 
        
           |  |  | 87 |             'id' => $this->objectid,
 | 
        
           |  |  | 88 |             'action' => 'edit',
 | 
        
           |  |  | 89 |         ];
 | 
        
           |  |  | 90 |         return new \moodle_url('/mod/quiz/accessrule/seb/template.php', $params);
 | 
        
           |  |  | 91 |     }
 | 
        
           |  |  | 92 |   | 
        
           |  |  | 93 |     /**
 | 
        
           |  |  | 94 |      * Returns non-localised event description with id's for admin use only.
 | 
        
           |  |  | 95 |      *
 | 
        
           |  |  | 96 |      * @return string Description.
 | 
        
           |  |  | 97 |      */
 | 
        
           |  |  | 98 |     public function get_description() {
 | 
        
           |  |  | 99 |         return "The user with id '$this->userid' has updated a template with id '$this->objectid'.";
 | 
        
           |  |  | 100 |     }
 | 
        
           |  |  | 101 |   | 
        
           |  |  | 102 |     /**
 | 
        
           |  |  | 103 |      * This is used when restoring course logs where it is required that we
 | 
        
           |  |  | 104 |      * map the objectid to it's new value in the new course.
 | 
        
           |  |  | 105 |      *
 | 
        
           |  |  | 106 |      * @return array Mapping of object id.
 | 
        
           |  |  | 107 |      */
 | 
        
           |  |  | 108 |     public static function get_objectid_mapping(): array {
 | 
        
           |  |  | 109 |         return ['db' => 'quizaccess_seb_template', 'restore' => 'quizaccess_seb_template'];
 | 
        
           |  |  | 110 |     }
 | 
        
           |  |  | 111 |   | 
        
           |  |  | 112 |     /**
 | 
        
           |  |  | 113 |      * This is used when restoring course logs where it is required that we
 | 
        
           |  |  | 114 |      * map the information in 'other' to it's new value in the new course.
 | 
        
           |  |  | 115 |      *
 | 
        
           |  |  | 116 |      * @return array List of mapping of other ids.
 | 
        
           |  |  | 117 |      */
 | 
        
           |  |  | 118 |     public static function get_other_mapping(): array {
 | 
        
           |  |  | 119 |         return [];
 | 
        
           |  |  | 120 |     }
 | 
        
           |  |  | 121 | }
 |