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 updated event.
19
 *
20
 * @package   mod_customcert
21
 * @copyright 2023 Leon Stringer <leon.stringer@ntlworld.com>
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace mod_customcert\event;
26
 
27
use mod_customcert\template;
28
 
29
/**
30
 * Certificate template updated event class.
31
 *
32
 * @package   mod_customcert
33
 * @copyright 2023 Leon Stringer <leon.stringer@ntlworld.com>
34
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class template_updated extends \core\event\base {
37
 
38
    /**
39
     * Initialises the event.
40
     */
41
    protected function init() {
42
        $this->data['crud'] = 'u';
43
        $this->data['edulevel'] = self::LEVEL_OTHER;
44
        $this->data['objecttable'] = 'customcert_templates';
45
    }
46
 
47
    /**
48
     * Returns non-localised description of what happened.
49
     *
50
     * @return string
51
     */
52
    public function get_description() {
53
        if ($this->contextlevel == \context_system::instance()->contextlevel) {
54
            // If CONTEXT_SYSTEM assume it's a template.
55
            return "The user with id '$this->userid' updated the certificate template with id '$this->objectid'.";
56
        } else {
57
            // Else assume it's a module instance in a course.
58
            return "The user with id '$this->userid' updated the certificate template for course module "
59
                . "'$this->contextinstanceid'.";
60
        }
61
    }
62
 
63
    /**
64
     * {@inheritdoc}
65
     *
66
     * @return string
67
     */
68
    public static function get_name() {
69
        return get_string('eventtemplateupdated', 'customcert');
70
    }
71
 
72
    /**
73
     * Create instance of event.
74
     *
75
     * @param template $template
76
     * @return template_updated
77
     */
78
    public static function create_from_template(template $template): template_updated {
79
        $data = [
80
            'context' => $template->get_context(),
81
            'objectid' => $template->get_id(),
82
        ];
83
        $event = self::create($data);
84
        return $event;
85
    }
86
 
87
    /**
88
     * Returns relevant URL.
89
     * @return \moodle_url
90
     */
91
    public function get_url() {
92
        if ($this->contextlevel == \context_system::instance()->contextlevel) {
93
            return new \moodle_url('/mod/customcert/manage_templates.php');
94
        } else {
95
            return new \moodle_url('/mod/customcert/view.php',
96
                    ['id' => $this->contextinstanceid]);
97
        }
98
    }
99
 
100
    /**
101
     * {@inheritdoc}
102
     *
103
     * @return string[]
104
     */
105
    public static function get_objectid_mapping() {
106
        return ['db' => 'customcert_templates', 'restore' => 'customcert_templates'];
107
    }
108
 
109
    /**
110
     * {@inheritdoc}
111
     *
112
     * @return bool
113
     */
114
    public static function get_other_mapping() {
115
        // No need to map.
116
        return false;
117
    }
118
}