Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 402] [Versions 311 and 403]

   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.
  13  //
  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/>.
  16  
  17  /**
  18   * User deleted event.
  19   *
  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
  23   */
  24  namespace core\event;
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * User deleted event class.
  30   *
  31   * @property-read array $other {
  32   *      Extra information about event.
  33   *
  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   * }
  40   *
  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
  45   */
  46  class user_deleted extends base {
  47  
  48      /**
  49       * Initialise required event data properties.
  50       */
  51      protected function init() {
  52          $this->data['objecttable'] = 'user';
  53          $this->data['crud'] = 'd';
  54          $this->data['edulevel'] = self::LEVEL_OTHER;
  55      }
  56  
  57      /**
  58       * Returns localised event name.
  59       *
  60       * @return string
  61       */
  62      public static function get_name() {
  63          return get_string('eventuserdeleted');
  64      }
  65  
  66      /**
  67       * Returns non-localised event description with id's for admin use only.
  68       *
  69       * @return string
  70       */
  71      public function get_description() {
  72          return "The user with id '$this->userid' deleted the user with id '$this->objectid'.";
  73      }
  74  
  75      /**
  76       * Return name of the legacy event, which is replaced by this event.
  77       *
  78       * @return string legacy event name
  79       */
  80      public static function get_legacy_eventname() {
  81          return 'user_deleted';
  82      }
  83  
  84      /**
  85       * Return user_deleted legacy event data.
  86       *
  87       * @return \stdClass user data.
  88       */
  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'];
  96  
  97          return $user;
  98      }
  99  
 100      /**
 101       * Returns array of parameters to be passed to legacy add_to_log() function.
 102       *
 103       * @return array
 104       */
 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);
 108      }
 109  
 110      /**
 111       * Custom validation.
 112       *
 113       * @throws \coding_exception
 114       * @return void
 115       */
 116      protected function validate_data() {
 117          parent::validate_data();
 118  
 119          if (!isset($this->relateduserid)) {
 120              debugging('The \'relateduserid\' value must be specified in the event.', DEBUG_DEVELOPER);
 121              $this->relateduserid = $this->objectid;
 122          }
 123  
 124          if (!isset($this->other['username'])) {
 125              throw new \coding_exception('The \'username\' value must be set in other.');
 126          }
 127  
 128          if (!isset($this->other['email'])) {
 129              throw new \coding_exception('The \'email\' value must be set in other.');
 130          }
 131  
 132          if (!isset($this->other['idnumber'])) {
 133              throw new \coding_exception('The \'idnumber\' value must be set in other.');
 134          }
 135  
 136          if (!isset($this->other['picture'])) {
 137              throw new \coding_exception('The \'picture\' value must be set in other.');
 138          }
 139  
 140          if (!isset($this->other['mnethostid'])) {
 141              throw new \coding_exception('The \'mnethostid\' value must be set in other.');
 142          }
 143      }
 144  
 145      public static function get_objectid_mapping() {
 146          return array('db' => 'user', 'restore' => 'user');
 147      }
 148  
 149      public static function get_other_mapping() {
 150          $othermapped = array();
 151          $othermapped['mnethostid'] = array('db' => 'mnet_host', 'restore' => base::NOT_MAPPED);
 152  
 153          return $othermapped;
 154      }
 155  }