2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * calendar subscription deleted event.
21 * @copyright 2016 Stephen Bourget
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
29 * Event triggered after a calendar subscription is deleted.
31 * @property-read array $other {
32 * Extra information about the event.
34 * - int courseid: The ID of the course (SITEID, User(0) or actual course)
39 * @copyright 2016 Stephen Bourget
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42 class calendar_subscription_deleted extends base
50 protected function init() {
51 $this->data['crud'] = 'd';
52 $this->data['edulevel'] = self::LEVEL_OTHER;
53 $this->data['objecttable'] = 'event_subscriptions';
57 * Returns localised general event name.
61 public static function get_name() {
62 return get_string('eventsubscriptiondeleted', 'calendar');
66 * Returns description of what happened.
70 public function get_description() {
71 return "User {$this->userid} has deleted a calendar
72 subscription with id {$this->objectid}.";
76 * Returns relevant URL.
80 public function get_url() {
81 if (($this->other['courseid'] == SITEID) || ($this->other['courseid'] == 0)) {
82 return new \moodle_url('calendar/managesubscriptions.php');
84 return new \moodle_url('calendar/managesubscriptions.php', array('course' => $this->other['courseid']));
91 * @throws \coding_exception
94 protected function validate_data() {
95 parent::validate_data();
96 if (!isset($this->context)) {
97 throw new \coding_exception('The \'context\' must be set.');
99 if (!isset($this->objectid)) {
100 throw new \coding_exception('The \'objectid\' must be set.');
102 if (!isset($this->other['courseid'])) {
103 throw new \coding_exception('The \'courseid\' value must be set in other.');
108 * Returns mappings for restore
112 public static function get_objectid_mapping() {
113 return array('db' => 'event_subscriptions', 'restore' => 'event_subscriptions');