Merge branch 'MDL-57742_master' of git://github.com/markn86/moodle
[moodle.git] / lib / classes / event / user_info_category_created.php
blobe8d2692ee742a97771ff396a7731ed9f7f059d93
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 created 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
25 namespace core\event;
27 defined('MOODLE_INTERNAL') || die();
29 /**
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.
36 * }
38 * @package core
39 * @copyright 2017 Web Courseworks, Ltd. {@link http://www.webcourseworks.com}
40 * @since Moodle 3.4
41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
43 class user_info_category_created extends base {
45 /**
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;
54 /**
55 * Creates an event from a profile info category.
57 * @since Moodle 3.4
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(),
65 'other' => array(
66 'name' => $category->name,
68 ));
70 $event->add_record_snapshot('user_info_category', $category);
72 return $event;
75 /**
76 * Returns localised event name.
78 * @return string
80 public static function get_name() {
81 return get_string('eventuserinfocategorycreated');
84 /**
85 * Returns non-localised event description with id's for admin use only.
87 * @return string
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'.";
94 /**
95 * Returns relevant URL.
97 * @return \moodle_url
99 public function get_url() {
100 return new \moodle_url('/user/profile/index.php', array(
101 'action' => 'editcategory',
102 'id' => $this->objectid
107 * Custom validation.
109 * @throws \coding_exception
110 * @return void
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.
123 * @return string
125 public static function get_objectid_mapping() {
126 return base::NOT_MAPPED;