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 page created 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
use mod_customcert\template;
28
 
29
/**
30
 * Certificate template page created event class.
31
 *
32
 * @package   mod_customcert
33
 * @copyright 2023 Mark Nelson <mdjnelson@gmail.com>
34
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class page_deleted extends \core\event\base {
37
 
38
    /**
39
     * Initialises the event.
40
     */
41
    protected function init() {
42
        $this->data['crud'] = 'd';
43
        $this->data['edulevel'] = self::LEVEL_OTHER;
44
        $this->data['objecttable'] = 'customcert_pages';
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' deleted the page 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' deleted the page with id '$this->objectid' in the certificate " .
59
                "in course module '$this->contextinstanceid'.";
60
        }
61
    }
62
 
63
    /**
64
     * {@inheritdoc}
65
     *
66
     * @return string
67
     */
68
    public static function get_name() {
69
        return get_string('eventpagedeleted', 'customcert');
70
    }
71
 
72
    /**
73
     * Create instance of event.
74
     *
75
     * @param \stdClass $page
76
     * @param template $template
77
     * @return page_deleted
78
     */
79
    public static function create_from_page(\stdClass $page, template $template): page_deleted {
80
        $data = [
81
            'context' => $template->get_context(),
82
            'objectid' => $page->id,
83
        ];
84
 
85
        return self::create($data);
86
    }
87
 
88
    /**
89
     * Returns relevant URL.
90
     * @return \moodle_url
91
     */
92
    public function get_url() {
93
        if ($this->contextlevel == \context_system::instance()->contextlevel) {
94
            return new \moodle_url('/mod/customcert/manage_templates.php');
95
        } else {
96
            return new \moodle_url('/mod/customcert/view.php',
97
                ['id' => $this->contextinstanceid]);
98
        }
99
    }
100
 
101
    /**
102
     * {@inheritdoc}
103
     *
104
     * @return string[]
105
     */
106
    public static function get_objectid_mapping() {
107
        return ['db' => 'customcert_pages', 'restore' => 'customcert_pages'];
108
    }
109
 
110
    /**
111
     * {@inheritdoc}
112
     *
113
     * @return bool
114
     */
115
    public static function get_other_mapping() {
116
        // No need to map.
117
        return false;
118
    }
119
}