Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.
   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 profile info field deleted event.
  19   *
  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
  23   */
  24  namespace core\event;
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * User profile info field deleted event.
  30   *
  31   * @property-read array $other {
  32   *      Extra information about event.
  33   *
  34   *      - string shortname: the shortname of the field.
  35   *      - string name: the name of the field.
  36   *      - string datatype: the data type of the field.
  37   * }
  38   *
  39   * @package    core
  40   * @copyright  2017 Web Courseworks, Ltd. {@link http://www.webcourseworks.com}
  41   * @since      Moodle 3.4
  42   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  43   */
  44  class user_info_field_deleted extends base {
  45  
  46      /**
  47       * Initialise required event data properties.
  48       */
  49      protected function init() {
  50          $this->data['objecttable'] = 'user_info_field';
  51          $this->data['crud'] = 'd';
  52          $this->data['edulevel'] = self::LEVEL_OTHER;
  53      }
  54  
  55      /**
  56       * Creates an event from a profile field.
  57       *
  58       * @since Moodle 3.4
  59       * @param \stdClass $field A snapshot of the deleted field.
  60       * @return \core\event\base
  61       */
  62      public static function create_from_field($field) {
  63          $event = self::create(array(
  64              'objectid' => $field->id,
  65              'context' => \context_system::instance(),
  66              'other' => array(
  67                  'shortname' => $field->shortname,
  68                  'name'      => $field->name,
  69                  'datatype'  => $field->datatype,
  70              )
  71          ));
  72  
  73          $event->add_record_snapshot('user_info_field', $field);
  74  
  75          return $event;
  76      }
  77  
  78      /**
  79       * Returns localised event name.
  80       *
  81       * @return string
  82       */
  83      public static function get_name() {
  84          return get_string('eventuserinfofielddeleted');
  85      }
  86  
  87      /**
  88       * Returns non-localised event description with id's for admin use only.
  89       *
  90       * @return string
  91       */
  92      public function get_description() {
  93          $name = s($this->other['name']);
  94          return "The user with id '$this->userid' deleted the user profile field '$name' with id '$this->objectid'.";
  95      }
  96  
  97      /**
  98       * Custom validation.
  99       *
 100       * @throws \coding_exception
 101       * @return void
 102       */
 103      protected function validate_data() {
 104          parent::validate_data();
 105  
 106          if (!isset($this->other['shortname'])) {
 107              throw new \coding_exception('The \'shortname\' value must be set in other.');
 108          }
 109  
 110          if (!isset($this->other['name'])) {
 111              throw new \coding_exception('The \'name\' value must be set in other.');
 112          }
 113  
 114          if (!isset($this->other['datatype'])) {
 115              throw new \coding_exception('The \'datatype\' value must be set in other.');
 116          }
 117      }
 118  
 119      /**
 120       * Get the backup/restore table mapping for this event.
 121       *
 122       * @return string
 123       */
 124      public static function get_objectid_mapping() {
 125          return base::NOT_MAPPED;
 126      }
 127  }