Merge branch 'MDL-57742_master' of git://github.com/markn86/moodle
[moodle.git] / lib / classes / event / course_section_created.php
blob9c1e789575d43f2aea1e99b33aa907b44f699443
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.
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/>.
17 /**
18 * Course section created event.
20 * @package core
21 * @copyright 2017 Marina Glancy
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace core\event;
27 defined('MOODLE_INTERNAL') || die();
29 /**
30 * Course section created event class.
32 * @property-read array $other {
33 * Extra information about event.
35 * - int sectionnum: section number.
36 * }
38 * @package core
39 * @copyright 2017 Marina Glancy
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42 class course_section_created extends base {
44 /**
45 * Init method.
47 * @return void
49 protected function init() {
50 $this->data['objecttable'] = 'course_sections';
51 $this->data['crud'] = 'c';
52 $this->data['edulevel'] = self::LEVEL_TEACHING;
55 /**
56 * Creates event from the section object
58 * @param \stdClass $section
59 * @return course_section_created
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;
71 /**
72 * Return localised event name.
74 * @return string
76 public static function get_name() {
77 return get_string('eventcoursesectioncreated');
80 /**
81 * Returns non-localised event description with id's for admin use only.
83 * @return string
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'";
90 /**
91 * Get URL related to the action.
93 * @return \moodle_url
95 public function get_url() {
96 return new \moodle_url('/course/editsection.php', array('id' => $this->objectid));
99 /**
100 * Custom validation.
102 * @throws \coding_exception
103 * @return void
105 protected function validate_data() {
106 parent::validate_data();
108 if (!isset($this->other['sectionnum'])) {
109 throw new \coding_exception('The \'sectionnum\' value must be set in other.');
114 * Mapping for sections object during restore
116 * @return array
118 public static function get_objectid_mapping() {
119 return array('db' => 'course_sections', 'restore' => 'course_section');
123 * Mapping for other fields during restore
125 * @return bool
127 public static function get_other_mapping() {
128 // Sectionnum does not need mapping because it's relative.
129 return false;