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 deleted 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 deleted 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_deleted extends \core\event\base {
35
 
36
    /**
37
     * Initialises the event.
38
     */
39
    protected function init() {
40
        $this->data['crud'] = 'd';
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' deleted 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' deleted 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('eventelementdeleted', 'customcert');
68
    }
69
 
70
    /**
71
     * Create instance of event.
72
     *
73
     * @param \mod_customcert\element $element
74
     * @return element_deleted
75
     */
76
    public static function create_from_element(\mod_customcert\element $element): element_deleted {
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
     * Returns relevant URL.
92
     * @return \moodle_url
93
     */
94
    public function get_url() {
95
        if ($this->contextlevel == \context_system::instance()->contextlevel) {
96
            return new \moodle_url('/mod/customcert/manage_templates.php');
97
        } else {
98
            return new \moodle_url('/mod/customcert/view.php',
99
                ['id' => $this->contextinstanceid]);
100
        }
101
    }
102
 
103
    /**
104
     * {@inheritdoc}
105
     *
106
     * @return string[]
107
     */
108
    public static function get_objectid_mapping() {
109
        return ['db' => 'customcert_elements', 'restore' => 'customcert_elements'];
110
    }
111
 
112
    /**
113
     * {@inheritdoc}
114
     *
115
     * @return bool
116
     */
117
    public static function get_other_mapping() {
118
        // No need to map.
119
        return false;
120
    }
121
}