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.
   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 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 deleted event class.
  30   *
  31   * @property-read array $other {
  32   *      Extra information about event.
  33   *
  34   *      - string name: the name of the field.
  35   * }
  36   *
  37   * @package    core
  38   * @copyright  2017 Web Courseworks, Ltd. {@link http://www.webcourseworks.com}
  39   * @since      Moodle 3.4
  40   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class user_info_category_deleted extends base {
  43  
  44      /**
  45       * Initialise required event data properties.
  46       */
  47      protected function init() {
  48          $this->data['objecttable'] = 'user_info_category';
  49          $this->data['crud'] = 'd';
  50          $this->data['edulevel'] = self::LEVEL_OTHER;
  51      }
  52  
  53      /**
  54       * Creates an event from a profile info category.
  55       *
  56       * @since Moodle 3.4
  57       * @param \stdClass $category A snapshot of the deleted category.
  58       * @return \core\event\base
  59       */
  60      public static function create_from_category($category) {
  61          $event = self::create(array(
  62              'objectid' => $category->id,
  63              'context' => \context_system::instance(),
  64              'other' => array(
  65                  'name' => $category->name,
  66              )
  67          ));
  68  
  69          $event->add_record_snapshot('user_info_category', $category);
  70  
  71          return $event;
  72      }
  73  
  74      /**
  75       * Returns localised event name.
  76       *
  77       * @return string
  78       */
  79      public static function get_name() {
  80          return get_string('eventuserinfocategorydeleted');
  81      }
  82  
  83      /**
  84       * Returns non-localised event description with id's for admin use only.
  85       *
  86       * @return string
  87       */
  88      public function get_description() {
  89          $name = s($this->other['name']);
  90          return "The user with id '$this->userid' deleted the user profile field category '$name' with id '$this->objectid'.";
  91      }
  92  
  93      /**
  94       * Custom validation.
  95       *
  96       * @throws \coding_exception
  97       * @return void
  98       */
  99      protected function validate_data() {
 100          parent::validate_data();
 101  
 102          if (!isset($this->other['name'])) {
 103              throw new \coding_exception('The \'name\' value must be set in other.');
 104          }
 105      }
 106  
 107      /**
 108       * Get the backup/restore table mapping for this event.
 109       *
 110       * @return string
 111       */
 112      public static function get_objectid_mapping() {
 113          return base::NOT_MAPPED;
 114      }
 115  }