Merge branch 'MDL-57742_master' of git://github.com/markn86/moodle
[moodle.git] / lib / classes / event / user_deleted.php
blobfc3fb85f772c9cd8d9ec87e943c1f6aea98b5328
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 deleted event.
20 * @package core
21 * @copyright 2013 Rajesh Taneja <rajesh@moodle.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 username: name of user.
35 * - string email: user email.
36 * - string idnumber: user idnumber.
37 * - string picture: user picture.
38 * - int mnethostid: mnet host id.
39 * }
41 * @package core
42 * @since Moodle 2.6
43 * @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
44 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
46 class user_deleted extends base {
48 /**
49 * Initialise required event data properties.
51 protected function init() {
52 $this->data['objecttable'] = 'user';
53 $this->data['crud'] = 'd';
54 $this->data['edulevel'] = self::LEVEL_OTHER;
57 /**
58 * Returns localised event name.
60 * @return string
62 public static function get_name() {
63 return get_string('eventuserdeleted');
66 /**
67 * Returns non-localised event description with id's for admin use only.
69 * @return string
71 public function get_description() {
72 return "The user with id '$this->userid' deleted the user with id '$this->objectid'.";
75 /**
76 * Return name of the legacy event, which is replaced by this event.
78 * @return string legacy event name
80 public static function get_legacy_eventname() {
81 return 'user_deleted';
84 /**
85 * Return user_deleted legacy event data.
87 * @return \stdClass user data.
89 protected function get_legacy_eventdata() {
90 $user = $this->get_record_snapshot('user', $this->objectid);
91 $user->deleted = 0;
92 $user->username = $this->other['username'];
93 $user->email = $this->other['email'];
94 $user->idnumber = $this->other['idnumber'];
95 $user->picture = $this->other['picture'];
97 return $user;
101 * Returns array of parameters to be passed to legacy add_to_log() function.
103 * @return array
105 protected function get_legacy_logdata() {
106 $user = $this->get_record_snapshot('user', $this->objectid);
107 return array(SITEID, 'user', 'delete', 'view.php?id=' . $user->id, $user->firstname . ' ' . $user->lastname);
111 * Custom validation.
113 * @throws \coding_exception
114 * @return void
116 protected function validate_data() {
117 parent::validate_data();
119 if (!isset($this->relateduserid)) {
120 debugging('The \'relateduserid\' value must be specified in the event.', DEBUG_DEVELOPER);
121 $this->relateduserid = $this->objectid;
124 if (!isset($this->other['username'])) {
125 throw new \coding_exception('The \'username\' value must be set in other.');
128 if (!isset($this->other['email'])) {
129 throw new \coding_exception('The \'email\' value must be set in other.');
132 if (!isset($this->other['idnumber'])) {
133 throw new \coding_exception('The \'idnumber\' value must be set in other.');
136 if (!isset($this->other['picture'])) {
137 throw new \coding_exception('The \'picture\' value must be set in other.');
140 if (!isset($this->other['mnethostid'])) {
141 throw new \coding_exception('The \'mnethostid\' value must be set in other.');
145 public static function get_objectid_mapping() {
146 return array('db' => 'user', 'restore' => 'user');
149 public static function get_other_mapping() {
150 $othermapped = array();
151 $othermapped['mnethostid'] = array('db' => 'mnet_host', 'restore' => base::NOT_MAPPED);
153 return $othermapped;