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 |
* Class for returning system event information.
|
|
|
19 |
*
|
|
|
20 |
* @package report_eventlist
|
|
|
21 |
* @copyright 2014 Adrian Greeve <adrian@moodle.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
class report_eventlist_list_generator {
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Convenience method. Returns all of the core events either with or without details.
|
|
|
28 |
*
|
|
|
29 |
* @param bool $detail True will return details, but no abstract classes, False will return all events, but no details.
|
|
|
30 |
* @return array All events.
|
|
|
31 |
*/
|
|
|
32 |
public static function get_all_events_list($detail = true) {
|
|
|
33 |
global $CFG;
|
|
|
34 |
|
|
|
35 |
// Disable developer debugging as deprecated events will fire warnings.
|
|
|
36 |
// Setup backup variables to restore the following settings back to what they were when we are finished.
|
|
|
37 |
$debuglevel = $CFG->debug;
|
|
|
38 |
$debugdisplay = $CFG->debugdisplay;
|
|
|
39 |
$debugdeveloper = $CFG->debugdeveloper;
|
|
|
40 |
$CFG->debug = 0;
|
|
|
41 |
$CFG->debugdisplay = false;
|
|
|
42 |
$CFG->debugdeveloper = false;
|
|
|
43 |
|
|
|
44 |
// List of exceptional events that will cause problems if displayed.
|
|
|
45 |
$eventsignore = [
|
|
|
46 |
\core\event\unknown_logged::class,
|
|
|
47 |
];
|
|
|
48 |
|
|
|
49 |
$eventinformation = [];
|
|
|
50 |
|
|
|
51 |
$events = core_component::get_component_classes_in_namespace(null, 'event');
|
|
|
52 |
foreach (array_keys($events) as $event) {
|
|
|
53 |
// We need to filter all classes that extend event base, or the base class itself.
|
|
|
54 |
if (is_a($event, \core\event\base::class, true) && !in_array($event, $eventsignore)) {
|
|
|
55 |
if ($detail) {
|
|
|
56 |
$reflectionclass = new ReflectionClass($event);
|
|
|
57 |
if (!$reflectionclass->isAbstract()) {
|
|
|
58 |
$eventinformation = self::format_data($eventinformation, "\\{$event}");
|
|
|
59 |
}
|
|
|
60 |
} else {
|
|
|
61 |
$parts = explode('\\', $event);
|
|
|
62 |
$eventinformation["\\{$event}"] = array_shift($parts);
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
// Now enable developer debugging as event information has been retrieved.
|
|
|
68 |
$CFG->debug = $debuglevel;
|
|
|
69 |
$CFG->debugdisplay = $debugdisplay;
|
|
|
70 |
$CFG->debugdeveloper = $debugdeveloper;
|
|
|
71 |
|
|
|
72 |
return $eventinformation;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
/**
|
|
|
76 |
* @deprecated since 4.0 use {@see get_all_events_list} instead
|
|
|
77 |
*/
|
1441 |
ariadna |
78 |
#[\core\attribute\deprecated('::get_all_events_list', since: '4.0', mdl: 'MDL-72498', final: true)]
|
|
|
79 |
public static function get_core_events_list() {
|
|
|
80 |
\core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
|
1 |
efrain |
81 |
}
|
|
|
82 |
|
|
|
83 |
/**
|
|
|
84 |
* Returns the appropriate string for the CRUD character.
|
|
|
85 |
*
|
|
|
86 |
* @param string $crudcharacter The CRUD character.
|
|
|
87 |
* @return string get_string for the specific CRUD character.
|
|
|
88 |
*/
|
|
|
89 |
public static function get_crud_string($crudcharacter) {
|
|
|
90 |
switch ($crudcharacter) {
|
|
|
91 |
case 'c':
|
|
|
92 |
return get_string('create', 'report_eventlist');
|
|
|
93 |
break;
|
|
|
94 |
|
|
|
95 |
case 'u':
|
|
|
96 |
return get_string('update', 'report_eventlist');
|
|
|
97 |
break;
|
|
|
98 |
|
|
|
99 |
case 'd':
|
|
|
100 |
return get_string('delete', 'report_eventlist');
|
|
|
101 |
break;
|
|
|
102 |
|
|
|
103 |
case 'r':
|
|
|
104 |
default:
|
|
|
105 |
return get_string('read', 'report_eventlist');
|
|
|
106 |
break;
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/**
|
|
|
111 |
* Returns the appropriate string for the event education level.
|
|
|
112 |
*
|
|
|
113 |
* @param int $edulevel Takes either the edulevel constant or string.
|
|
|
114 |
* @return string get_string for the specific education level.
|
|
|
115 |
*/
|
|
|
116 |
public static function get_edulevel_string($edulevel) {
|
|
|
117 |
switch ($edulevel) {
|
|
|
118 |
case \core\event\base::LEVEL_PARTICIPATING:
|
|
|
119 |
return get_string('participating', 'report_eventlist');
|
|
|
120 |
break;
|
|
|
121 |
|
|
|
122 |
case \core\event\base::LEVEL_TEACHING:
|
|
|
123 |
return get_string('teaching', 'report_eventlist');
|
|
|
124 |
break;
|
|
|
125 |
|
|
|
126 |
case \core\event\base::LEVEL_OTHER:
|
|
|
127 |
default:
|
|
|
128 |
return get_string('other', 'report_eventlist');
|
|
|
129 |
break;
|
|
|
130 |
}
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
/**
|
|
|
134 |
* @deprecated since 4.0 use {@see get_all_events_list} instead
|
|
|
135 |
*/
|
1441 |
ariadna |
136 |
#[\core\attribute\deprecated('::get_all_events_list', since: '4.0', mdl: 'MDL-72498', final: true)]
|
|
|
137 |
public static function get_non_core_event_list() {
|
|
|
138 |
\core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
|
1 |
efrain |
139 |
}
|
|
|
140 |
|
|
|
141 |
/**
|
|
|
142 |
* Get the full list of observers for the system.
|
|
|
143 |
*
|
|
|
144 |
* @return array An array of observers in the system.
|
|
|
145 |
*/
|
|
|
146 |
public static function get_observer_list() {
|
|
|
147 |
$events = \core\event\manager::get_all_observers();
|
|
|
148 |
foreach ($events as $key => $observers) {
|
|
|
149 |
foreach ($observers as $observerskey => $observer) {
|
|
|
150 |
$events[$key][$observerskey]->parentplugin =
|
|
|
151 |
\core_plugin_manager::instance()->get_parent_of_subplugin($observer->plugintype);
|
|
|
152 |
}
|
|
|
153 |
}
|
|
|
154 |
return $events;
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
/**
|
|
|
158 |
* Returns the event data list section with url links and other formatting.
|
|
|
159 |
*
|
|
|
160 |
* @param array $eventdata The event data list section.
|
|
|
161 |
* @param string $eventfullpath Full path to the events for this plugin / subplugin.
|
|
|
162 |
* @return array The event data list section with additional formatting.
|
|
|
163 |
*/
|
|
|
164 |
private static function format_data($eventdata, $eventfullpath) {
|
|
|
165 |
// Get general event information.
|
|
|
166 |
$eventdata[$eventfullpath] = $eventfullpath::get_static_info();
|
|
|
167 |
// Create a link for further event detail.
|
|
|
168 |
$url = new \moodle_url('eventdetail.php', array('eventname' => $eventfullpath));
|
|
|
169 |
$link = \html_writer::link($url, $eventfullpath::get_name_with_info());
|
|
|
170 |
$eventdata[$eventfullpath]['fulleventname'] = \html_writer::span($link);
|
|
|
171 |
$eventdata[$eventfullpath]['fulleventname'] .= \html_writer::empty_tag('br');
|
|
|
172 |
$eventdata[$eventfullpath]['fulleventname'] .= \html_writer::span($eventdata[$eventfullpath]['eventname'],
|
|
|
173 |
'report-eventlist-name');
|
|
|
174 |
|
|
|
175 |
$eventdata[$eventfullpath]['crud'] = self::get_crud_string($eventdata[$eventfullpath]['crud']);
|
|
|
176 |
$eventdata[$eventfullpath]['edulevel'] = self::get_edulevel_string($eventdata[$eventfullpath]['edulevel']);
|
|
|
177 |
|
|
|
178 |
// Mess around getting since information.
|
|
|
179 |
$ref = new \ReflectionClass($eventdata[$eventfullpath]['eventname']);
|
|
|
180 |
$eventdocbloc = $ref->getDocComment();
|
|
|
181 |
$sincepattern = "/since\s*Moodle\s([0-9]+.[0-9]+)/i";
|
|
|
182 |
preg_match($sincepattern, $eventdocbloc, $result);
|
|
|
183 |
if (isset($result[1])) {
|
|
|
184 |
$eventdata[$eventfullpath]['since'] = $result[1];
|
|
|
185 |
} else {
|
|
|
186 |
$eventdata[$eventfullpath]['since'] = null;
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
// Human readable plugin information to go with the component.
|
|
|
190 |
$pluginstring = explode('\\', $eventfullpath);
|
|
|
191 |
if ($pluginstring[1] !== 'core') {
|
|
|
192 |
$component = $eventdata[$eventfullpath]['component'];
|
|
|
193 |
$manager = get_string_manager();
|
|
|
194 |
if ($manager->string_exists('pluginname', $pluginstring[1])) {
|
|
|
195 |
$eventdata[$eventfullpath]['component'] = \html_writer::span(get_string('pluginname', $pluginstring[1]));
|
|
|
196 |
}
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
// Raw event data to be used to sort the "Event name" column.
|
|
|
200 |
$eventdata[$eventfullpath]['raweventname'] = $eventfullpath::get_name_with_info() . ' ' . $eventdata[$eventfullpath]['eventname'];
|
|
|
201 |
|
|
|
202 |
// Unset information that is not currently required.
|
|
|
203 |
unset($eventdata[$eventfullpath]['action']);
|
|
|
204 |
unset($eventdata[$eventfullpath]['target']);
|
|
|
205 |
return $eventdata;
|
|
|
206 |
}
|
|
|
207 |
}
|