Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.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   * Enrol instance updated event.
  19   *
  20   * @package    core
  21   * @copyright  2015 Marina Glancy
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core\event;
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * Enrol instance updated event class.
  30   *
  31   * @property-read array $other {
  32   *      Extra information about event.
  33   *
  34   *      - string enrol: name of enrol method
  35   * }
  36   *
  37   * @package    core
  38   * @since      Moodle 2.9
  39   * @copyright  2015 Marina Glancy
  40   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class enrol_instance_updated extends base {
  43  
  44      /**
  45       * Api to Create new event from enrol object.
  46       *
  47       * @param \stdClass $enrol record from DB table 'enrol'
  48       * @return \core\event\base returns instance of new event
  49       */
  50      public static final function create_from_record($enrol) {
  51          $event = static::create(array(
  52              'context'  => \context_course::instance($enrol->courseid),
  53              'objectid' => $enrol->id,
  54              'other'    => array('enrol' => $enrol->enrol)
  55          ));
  56          $event->add_record_snapshot('enrol', $enrol);
  57          return $event;
  58      }
  59  
  60      /**
  61       * Returns description of what happened.
  62       *
  63       * @return string
  64       */
  65      public function get_description() {
  66          return "The user with id '$this->userid' updated the instance of enrolment method '" .
  67                  $this->other['enrol'] . "' with id '$this->objectid'.";
  68      }
  69  
  70      /**
  71       * Return localised event name.
  72       *
  73       * @return string
  74       */
  75      public static function get_name() {
  76          return get_string('eventenrolinstanceupdated', 'enrol');
  77      }
  78  
  79      /**
  80       * Get URL related to the action
  81       *
  82       * @return \moodle_url
  83       */
  84      public function get_url() {
  85          return new \moodle_url('/enrol/instances.php', array('id' => $this->courseid));
  86      }
  87  
  88      /**
  89       * Init method.
  90       *
  91       * @return void
  92       */
  93      protected function init() {
  94          $this->data['crud'] = 'u';
  95          $this->data['edulevel'] = self::LEVEL_OTHER;
  96          $this->data['objecttable'] = 'enrol';
  97      }
  98  
  99      /**
 100       * custom validations
 101       *
 102       * Throw \coding_exception notice in case of any problems.
 103       */
 104      protected function validate_data() {
 105          parent::validate_data();
 106          if (!isset($this->other['enrol'])) {
 107              throw new \coding_exception('The \'enrol\' value must be set in other.');
 108          }
 109      }
 110  
 111      public static function get_objectid_mapping() {
 112          return array('db' => 'enrol', 'restore' => 'enrol');
 113      }
 114  
 115      public static function get_other_mapping() {
 116          // Nothing to map.
 117          return false;
 118      }
 119  }