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 * User profile field created event.
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
27 defined('MOODLE_INTERNAL') ||
die();
30 * User profile info category created event.
32 * @property-read array $other {
33 * Extra information about event.
35 * - string name: the name of the field.
39 * @copyright 2017 Web Courseworks, Ltd. {@link http://www.webcourseworks.com}
41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
43 class user_info_category_created
extends base
{
46 * Initialise the event data.
48 protected function init() {
49 $this->data
['objecttable'] = 'user_info_category';
50 $this->data
['crud'] = 'c';
51 $this->data
['edulevel'] = self
::LEVEL_OTHER
;
55 * Creates an event from a profile info category.
58 * @param \stdClass $category A sna[pshot of the created category.
59 * @return \core\event\base
61 public static function create_from_category($category) {
62 $event = self
::create(array(
63 'objectid' => $category->id
,
64 'context' => \context_system
::instance(),
66 'name' => $category->name
,
70 $event->add_record_snapshot('user_info_category', $category);
76 * Returns localised event name.
80 public static function get_name() {
81 return get_string('eventuserinfocategorycreated');
85 * Returns non-localised event description with id's for admin use only.
89 public function get_description() {
90 $name = s($this->other
['name']);
91 return "The user with id '$this->userid' created the user profile field category '$name' with id '$this->objectid'.";
95 * Returns relevant URL.
99 public function get_url() {
100 return new \
moodle_url('/user/profile/index.php', array(
101 'action' => 'editcategory',
102 'id' => $this->objectid
109 * @throws \coding_exception
112 protected function validate_data() {
113 parent
::validate_data();
115 if (!isset($this->other
['name'])) {
116 throw new \
coding_exception('The \'name\' value must be set in other.');
121 * Get the backup/restore table mapping for this event.
125 public static function get_objectid_mapping() {
126 return base
::NOT_MAPPED
;