2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * Course section created event.
21 * @copyright 2017 Marina Glancy
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') ||
die();
30 * Course section created event class.
32 * @property-read array $other {
33 * Extra information about event.
35 * - int sectionnum: section number.
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
{
49 protected function init() {
50 $this->data
['objecttable'] = 'course_sections';
51 $this->data
['crud'] = 'c';
52 $this->data
['edulevel'] = self
::LEVEL_TEACHING
;
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
]
67 $event->add_record_snapshot('course_sections', $section);
72 * Return localised event name.
76 public static function get_name() {
77 return get_string('eventcoursesectioncreated');
81 * Returns non-localised event description with id's for admin use only.
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'";
91 * Get URL related to the action.
95 public function get_url() {
96 return new \
moodle_url('/course/editsection.php', array('id' => $this->objectid
));
102 * @throws \coding_exception
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
118 public static function get_objectid_mapping() {
119 return array('db' => 'course_sections', 'restore' => 'course_section');
123 * Mapping for other fields during restore
127 public static function get_other_mapping() {
128 // Sectionnum does not need mapping because it's relative.