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   * Course section created event.
  19   *
  20   * @package    core
  21   * @copyright  2017 Marina Glancy
  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   * Course section created event class.
  31   *
  32   * @property-read array $other {
  33   *      Extra information about event.
  34   *
  35   *      - int sectionnum: section number.
  36   * }
  37   *
  38   * @package    core
  39   * @copyright  2017 Marina Glancy
  40   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class course_section_created extends base {
  43  
  44      /**
  45       * Init method.
  46       *
  47       * @return void
  48       */
  49      protected function init() {
  50          $this->data['objecttable'] = 'course_sections';
  51          $this->data['crud'] = 'c';
  52          $this->data['edulevel'] = self::LEVEL_TEACHING;
  53      }
  54  
  55      /**
  56       * Creates event from the section object
  57       *
  58       * @param \stdClass $section
  59       * @return course_section_created
  60       */
  61      public static function create_from_section($section) {
  62          $event = self::create([
  63              'context' => \context_course::instance($section->course),
  64              'objectid' => $section->id,
  65              'other' => ['sectionnum' => $section->section]
  66          ]);
  67          $event->add_record_snapshot('course_sections', $section);
  68          return $event;
  69      }
  70  
  71      /**
  72       * Return localised event name.
  73       *
  74       * @return string
  75       */
  76      public static function get_name() {
  77          return get_string('eventcoursesectioncreated');
  78      }
  79  
  80      /**
  81       * Returns non-localised event description with id's for admin use only.
  82       *
  83       * @return string
  84       */
  85      public function get_description() {
  86          return "The user with id '$this->userid' created section number '{$this->other['sectionnum']}' for the " .
  87          "course with id '$this->courseid'";
  88      }
  89  
  90      /**
  91       * Get URL related to the action.
  92       *
  93       * @return \moodle_url
  94       */
  95      public function get_url() {
  96          return new \moodle_url('/course/editsection.php', array('id' => $this->objectid));
  97      }
  98  
  99      /**
 100       * Custom validation.
 101       *
 102       * @throws \coding_exception
 103       * @return void
 104       */
 105      protected function validate_data() {
 106          parent::validate_data();
 107  
 108          if (!isset($this->other['sectionnum'])) {
 109              throw new \coding_exception('The \'sectionnum\' value must be set in other.');
 110          }
 111      }
 112  
 113      /**
 114       * Mapping for sections object during restore
 115       *
 116       * @return array
 117       */
 118      public static function get_objectid_mapping() {
 119          return array('db' => 'course_sections', 'restore' => 'course_section');
 120      }
 121  
 122      /**
 123       * Mapping for other fields during restore
 124       *
 125       * @return bool
 126       */
 127      public static function get_other_mapping() {
 128          // Sectionnum does not need mapping because it's relative.
 129          return false;
 130      }
 131  }