Merge branch 'MDL-57742_master' of git://github.com/markn86/moodle
[moodle.git] / lib / classes / event / user_info_category_deleted.php
blob01db25bc94e3d4f92b46c9456d499f442ac6c808
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.
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/>.
17 /**
18 * User profile field deleted event.
20 * @package core
21 * @copyright 2017 Web Courseworks, Ltd. {@link http://www.webcourseworks.com}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 namespace core\event;
26 defined('MOODLE_INTERNAL') || die();
28 /**
29 * User deleted event class.
31 * @property-read array $other {
32 * Extra information about event.
34 * - string name: the name of the field.
35 * }
37 * @package core
38 * @copyright 2017 Web Courseworks, Ltd. {@link http://www.webcourseworks.com}
39 * @since Moodle 3.4
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42 class user_info_category_deleted extends base {
44 /**
45 * Initialise required event data properties.
47 protected function init() {
48 $this->data['objecttable'] = 'user_info_category';
49 $this->data['crud'] = 'd';
50 $this->data['edulevel'] = self::LEVEL_OTHER;
53 /**
54 * Creates an event from a profile info category.
56 * @since Moodle 3.4
57 * @param \stdClass $category A snapshot of the deleted category.
58 * @return \core\event\base
60 public static function create_from_category($category) {
61 $event = self::create(array(
62 'objectid' => $category->id,
63 'context' => \context_system::instance(),
64 'other' => array(
65 'name' => $category->name,
67 ));
69 $event->add_record_snapshot('user_info_category', $category);
71 return $event;
74 /**
75 * Returns localised event name.
77 * @return string
79 public static function get_name() {
80 return get_string('eventuserinfocategorydeleted');
83 /**
84 * Returns non-localised event description with id's for admin use only.
86 * @return string
88 public function get_description() {
89 $name = s($this->other['name']);
90 return "The user with id '$this->userid' deleted the user profile field category '$name' with id '$this->objectid'.";
93 /**
94 * Custom validation.
96 * @throws \coding_exception
97 * @return void
99 protected function validate_data() {
100 parent::validate_data();
102 if (!isset($this->other['name'])) {
103 throw new \coding_exception('The \'name\' value must be set in other.');
108 * Get the backup/restore table mapping for this event.
110 * @return string
112 public static function get_objectid_mapping() {
113 return base::NOT_MAPPED;