Search moodle.org's
Developer Documentation

See Release Notes

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