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 * calendar subscription updated event. 19 * 20 * @package core 21 * @copyright 2016 Stephen Bourget 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace core\event; 26 defined('MOODLE_INTERNAL') || die(); 27 28 /** 29 * Event triggered after a calendar subscription is updated. 30 * 31 * @property-read array $other { 32 * Extra information about the event. 33 * 34 * - string eventtype: the type of events (site, course, group, user). 35 * - int courseid: The ID of the course (SITEID, User(0) or actual course) 36 * } 37 * 38 * @package core 39 * @since Moodle 3.2 40 * @copyright 2016 Stephen Bourget 41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 42 */ 43 class calendar_subscription_updated extends base 44 { 45 46 /** 47 * Init method. 48 * 49 * @return void 50 */ 51 protected function init() { 52 $this->data['crud'] = 'u'; 53 $this->data['edulevel'] = self::LEVEL_OTHER; 54 $this->data['objecttable'] = 'event_subscriptions'; 55 } 56 57 /** 58 * Returns localised general event name. 59 * 60 * @return string 61 */ 62 public static function get_name() { 63 return get_string('eventsubscriptionupdated', 'calendar'); 64 } 65 66 /** 67 * Returns description of what happened. 68 * 69 * @return string 70 */ 71 public function get_description() { 72 return "User {$this->userid} has updated a calendar 73 subscription with id {$this->objectid} of event type {$this->other['eventtype']}."; 74 } 75 76 /** 77 * Returns relevant URL. 78 * 79 * @return \moodle_url 80 */ 81 public function get_url() { 82 $params = []; 83 if ($this->other['eventtype'] == 'course' || $this->other['eventtype'] == 'group') { 84 $params['course'] = $this->other['courseid']; 85 if ($this->other['eventtype'] == 'group' && isset($this->other['groupid'])) { 86 $params['group'] = $this->other['groupid']; 87 } 88 } 89 if ($this->other['eventtype'] == 'category' && isset($this->other['categoryid'])) { 90 $params['category'] = $this->other['categoryid']; 91 } 92 return new \moodle_url('/calendar/managesubscriptions.php', $params); 93 } 94 95 /** 96 * Custom validations. 97 * 98 * @throws \coding_exception 99 * @return void 100 */ 101 protected function validate_data() { 102 parent::validate_data(); 103 if (!isset($this->context)) { 104 throw new \coding_exception('The \'context\' must be set.'); 105 } 106 if (!isset($this->objectid)) { 107 throw new \coding_exception('The \'objectid\' must be set.'); 108 } 109 if (!isset($this->other['eventtype'])) { 110 throw new \coding_exception('The \'eventtype\' value must be set in other.'); 111 } 112 if ($this->other['eventtype'] == 'course' || $this->other['eventtype'] == 'group') { 113 if (!isset($this->other['courseid'])) { 114 throw new \coding_exception('The \'courseid\' value must be set in other.'); 115 } 116 if ($this->other['eventtype'] == 'group' && !isset($this->other['groupid'])) { 117 throw new \coding_exception('The \'groupid\' value must be set in other.'); 118 } 119 } 120 if ($this->other['eventtype'] == 'category' && !isset($this->other['categoryid'])) { 121 throw new \coding_exception('The \'categoryid\' value must be set in other.'); 122 } 123 } 124 125 /** 126 * Returns mappings for restore 127 * 128 * @return array 129 */ 130 public static function get_objectid_mapping() { 131 return array('db' => 'event_subscriptions', 'restore' => 'event_subscriptions'); 132 } 133 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body