Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
namespace core\event;
18
 
19
/**
20
 * Section viewed event class.
21
 *
22
 * @package    core
23
 * @copyright  2023 Amaia Anabitarte <amaia@moodle.com>
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
class section_viewed extends base {
27
 
28
    /**
29
     * Init method.
30
     *
31
     * @return void
32
     */
33
    protected function init() {
34
        $this->data['objecttable'] = 'course_sections';
35
        $this->data['crud'] = 'r';
36
        $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
37
    }
38
 
39
    /**
40
     * Returns non-localised description of what happened.
41
     *
42
     * @return string
43
     */
44
    public function get_description() {
45
        return "The user with id '$this->userid' viewed the section with id '$this->objectid'.";
46
    }
47
 
48
    /**
49
     * Return localised event name.
50
     *
51
     * @return string
52
     */
53
    public static function get_name() {
54
        return get_string('eventsectionviewed', 'core');
55
    }
56
 
57
    /**
58
     * Get URL related to the action.
59
     *
60
     * @return \moodle_url|null
61
     */
62
    public function get_url() {
63
        global $CFG, $DB;
64
        require_once($CFG->dirroot . '/course/lib.php');
65
        try {
66
            $section = $DB->get_record($this->objecttable, ['id' => $this->objectid], '*', MUST_EXIST);
67
            return course_get_url($this->courseid, $section, ['navigation' => true]);
68
        } catch (\Exception $e) {
69
            return null;
70
        }
71
    }
72
 
73
    /**
74
     * Custom validation.
75
     *
76
     * @throws \coding_exception
77
     * @return void
78
     */
79
    protected function validate_data() {
80
        parent::validate_data();
81
 
82
        if ($this->contextlevel != CONTEXT_COURSE) {
83
            throw new \coding_exception('Context level must be CONTEXT_COURSE.');
84
        }
85
    }
86
 
87
    /**
88
     * Used for mapping events on restore
89
     *
90
     * @return bool
91
     */
92
    public static function get_other_mapping() {
93
        // No mapping required.
94
        return false;
95
    }
96
}