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 mod_workshop\event; 18 19 /** 20 * This event is triggered when a phase is automatically switched, usually from cron_task. 21 * 22 * @property-read array $other { 23 * Extra information about the event. 24 * 25 * - int previousworkshopphase: Previous workshop phase. 26 * - int targetworkshopphase: Target workshop phase. 27 * } 28 * 29 * @package mod_workshop 30 * @copyright 2020 Universitat Jaume I <https://www.uji.es/> 31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 32 */ 33 class phase_automatically_switched extends \core\event\base { 34 35 /** 36 * Init method. 37 * 38 * @return void 39 */ 40 protected function init() { 41 $this->data['crud'] = 'u'; 42 $this->data['edulevel'] = self::LEVEL_TEACHING; 43 $this->data['objecttable'] = 'workshop'; 44 } 45 46 /** 47 * Returns description of what happened. 48 * 49 * @return string 50 */ 51 public function get_description() { 52 return "The phase of the workshop with course module id " . 53 "'$this->contextinstanceid' has been automatically switched from " . 54 "'{$this->other['previousworkshopphase']} to '{$this->other['currentworkshopphase']}'."; 55 } 56 57 /** 58 * Return localised event name. 59 * 60 * @return string 61 */ 62 public static function get_name() { 63 return get_string('eventphaseautomaticallyswitched', 'mod_workshop'); 64 } 65 66 /** 67 * Get URL related to the action. 68 * 69 * @return \moodle_url 70 */ 71 public function get_url() { 72 return new \moodle_url('/mod/workshop/view.php', array('id' => $this->contextinstanceid)); 73 } 74 75 /** 76 * Custom validation. 77 * 78 * @return void 79 * @throws \coding_exception 80 */ 81 protected function validate_data() { 82 parent::validate_data(); 83 84 if (!isset($this->other['previousworkshopphase'])) { 85 throw new \coding_exception('The \'previousworkshopphase\' value must be set in other.'); 86 } 87 if (!isset($this->other['targetworkshopphase'])) { 88 throw new \coding_exception('The \'targetworkshopphase\' value must be set in other.'); 89 } 90 } 91 92 /** 93 * Map the objectid information in order to restore the event accurately. In this event 94 * objectid is the workshop id. 95 * 96 * @return array 97 */ 98 public static function get_objectid_mapping() { 99 return array('db' => 'workshop', 'restore' => 'workshop'); 100 } 101 102 /** 103 * No need to map the 'other' field as it only stores phases and they don't need to be mapped. 104 * 105 * @return bool 106 */ 107 public static function get_other_mapping() { 108 return false; 109 } 110 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body