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
/**
18
 * Certificate template element updated event.
19
 *
20
 * @package   mod_customcert
21
 * @copyright 2023 Mark Nelson <mdjnelson@gmail.com>
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace mod_customcert\event;
26
 
27
/**
28
 * Certificate template element updated event class.
29
 *
30
 * @package   mod_customcert
31
 * @copyright 2023 Mark Nelson <mdjnelson@gmail.com>
32
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 */
34
class element_updated extends \core\event\base {
35
 
36
    /**
37
     * Initialises the event.
38
     */
39
    protected function init() {
40
        $this->data['crud'] = 'u';
41
        $this->data['edulevel'] = self::LEVEL_OTHER;
42
        $this->data['objecttable'] = 'customcert_elements';
43
    }
44
 
45
    /**
46
     * Returns non-localised description of what happened.
47
     *
48
     * @return string
49
     */
50
    public function get_description() {
51
        if ($this->contextlevel == \context_system::instance()->contextlevel) {
52
            // If CONTEXT_SYSTEM assume it's a template.
53
            return "The user with id '$this->userid' updated the element with id '$this->objectid'.";
54
        } else {
55
            // Else assume it's a module instance in a course.
56
            return "The user with id '$this->userid' updated the element with id '$this->objectid' in the certificate " .
57
                "in course module '$this->contextinstanceid'.";
58
        }
59
    }
60
 
61
    /**
62
     * {@inheritdoc}
63
     *
64
     * @return string
65
     */
66
    public static function get_name() {
67
        return get_string('eventelementupdated', 'customcert');
68
    }
69
 
70
    /**
71
     * Create instance of event.
72
     *
73
     * @param \mod_customcert\element $element
74
     * @return element_updated
75
     */
76
    public static function create_from_element(\mod_customcert\element $element): element_updated {
77
        global $DB;
78
 
79
        $page = $DB->get_record('customcert_pages', ['id' => $element->get_pageid()]);
80
        $template = $DB->get_record('customcert_templates', ['id' => $page->templateid]);
81
 
82
        $data = [
83
            'contextid' => $template->contextid,
84
            'objectid' => $element->get_id(),
85
        ];
86
 
87
        return self::create($data);
88
    }
89
 
90
    /**
91
     * Create instance of event for the specified element.
92
     *
93
     * @param int $elementid ID of the element.
94
     * @param \mod_customcert\template $template Template containing the above
95
     * element.
96
     * @return element_updated
97
     */
98
    public static function create_from_id(int $elementid, \mod_customcert\template $template): element_updated {
99
        $data = [
100
            'contextid' => $template->get_contextid(),
101
            'objectid' => $elementid,
102
        ];
103
 
104
        return self::create($data);
105
    }
106
 
107
    /**
108
     * Returns relevant URL.
109
     * @return \moodle_url
110
     */
111
    public function get_url() {
112
        if ($this->contextlevel == \context_system::instance()->contextlevel) {
113
            return new \moodle_url('/mod/customcert/manage_templates.php');
114
        } else {
115
            return new \moodle_url('/mod/customcert/view.php',
116
                ['id' => $this->contextinstanceid]);
117
        }
118
    }
119
 
120
    /**
121
     * {@inheritdoc}
122
     *
123
     * @return string[]
124
     */
125
    public static function get_objectid_mapping() {
126
        return ['db' => 'customcert_elements', 'restore' => 'customcert_elements'];
127
    }
128
 
129
    /**
130
     * {@inheritdoc}
131
     *
132
     * @return bool
133
     */
134
    public static function get_other_mapping() {
135
        // No need to map.
136
        return false;
137
    }
138
}