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/>.
21 * @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') ||
die();
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.
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
{
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
;
58 * Returns localised event name.
62 public static function get_name() {
63 return get_string('eventuserdeleted');
67 * Returns non-localised event description with id's for admin use only.
71 public function get_description() {
72 return "The user with id '$this->userid' deleted the user with id '$this->objectid'.";
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';
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
);
92 $user->username
= $this->other
['username'];
93 $user->email
= $this->other
['email'];
94 $user->idnumber
= $this->other
['idnumber'];
95 $user->picture
= $this->other
['picture'];
101 * Returns array of parameters to be passed to legacy add_to_log() function.
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
);
113 * @throws \coding_exception
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
);