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
 * Event developer detail.
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
require_once(__DIR__ . '/../../config.php');
25
require_once($CFG->libdir . '/adminlib.php');
26
 
27
// Required parameters.
28
$eventname = required_param('eventname', PARAM_RAW);
29
 
30
admin_externalpage_setup('reporteventlists');
31
 
32
// Retrieve all events in a list.
33
$completelist = report_eventlist_list_generator::get_all_events_list(false);
34
 
35
// Check that $eventname is a valid event.
36
if (!array_key_exists($eventname, $completelist)) {
37
    throw new \moodle_exception('errorinvalidevent', 'report_eventlist');
38
}
39
 
40
// Break up the full event name to usable parts.
41
$component = explode('\\', $eventname);
42
$directory = core_component::get_component_directory($component[1]);
43
 
44
// File and directory information.
45
$directory = $directory . '/classes/event';
46
// Verify that the directory is valid.
47
if (!is_dir($directory)) {
48
    throw new \moodle_exception('errorinvaliddirectory', 'report_eventlist');
49
}
50
$filename = end($component);
51
$eventfiles = $directory . '/' . $filename . '.php';
52
$title = $eventname::get_name_with_info();
53
 
54
// Define event information.
55
$eventinformation = array('title' => $title);
56
$eventcontents = file_get_contents($eventfiles);
57
$eventinformation['filecontents'] = $eventcontents;
58
 
59
$ref = new \ReflectionClass($eventname);
60
$eventinformation['explanation'] = $eventname::get_explanation($eventname);
61
// Get event information nicely if we can.
62
if (!$ref->isAbstract()) {
63
    $eventinformation = array_merge($eventinformation, $eventname::get_static_info());
64
    $eventinformation['crud'] = report_eventlist_list_generator::get_crud_string($eventinformation['crud']);
65
    $eventinformation['edulevel'] = report_eventlist_list_generator::get_edulevel_string($eventinformation['edulevel']);
66
} else {
67
    $eventinformation['abstract'] = true;
68
    if ($eventname != '\core\event\base') {
69
        // No choice but to get information the hard way.
70
        // Strip out CRUD information.
71
        $crudpattern = "/(\['crud'\]\s=\s')(\w)/";
72
        $result = array();
73
        preg_match($crudpattern, $eventcontents, $result);
74
        if (!empty($result[2])) {
75
            $eventinformation['crud'] = report_eventlist_list_generator::get_crud_string($result[2]);
76
        }
77
 
78
        // Strip out edulevel information.
79
        $edulevelpattern = "/(\['edulevel'\]\s=\sself\:\:)(\w*)/";
80
        $result = array();
81
        preg_match($edulevelpattern, $eventcontents, $result);
82
        if (!empty($result[2])) {
83
            $educationlevel = constant('\core\event\base::' . $result[2]);
84
            $eventinformation['edulevel'] = report_eventlist_list_generator::get_edulevel_string($educationlevel);
85
        }
86
 
87
        // Retrieve object table information.
88
        $affectedtablepattern = "/(\['objecttable'\]\s=\s')(\w*)/";
89
        $result = array();
90
        preg_match($affectedtablepattern, $eventcontents, $result);
91
        if (!empty($result[2])) {
92
            $eventinformation['objecttable'] = $result[2];
93
        }
94
    }
95
}
96
 
97
// I can't think of a nice way to get the following information.
98
// Searching to see if @type has been used for the 'other' field in the event.
99
$othertypepattern = "/(@type\s([\w|\s|.]*))+/";
100
$typeparams = array();
101
preg_match_all($othertypepattern, $eventcontents, $typeparams);
102
if (!empty($typeparams[2])) {
103
    $eventinformation['typeparameter'] = array();
104
    foreach ($typeparams[2] as $typeparameter) {
105
        $eventinformation['typeparameter'][] = $typeparameter;
106
    }
107
}
108
 
109
// Retrieving the 'other' event field information.
110
$otherpattern = "/(\*\s{5,}-([\w|\s]*\:[\w|\s|\(|\)|.]*))/";
111
$typeparams = array();
112
preg_match_all($otherpattern, $eventcontents, $typeparams);
113
if (!empty($typeparams[2])) {
114
    $eventinformation['otherparameter'] = array();
115
    foreach ($typeparams[2] as $typeparameter) {
116
        $eventinformation['otherparameter'][] = $typeparameter;
117
    }
118
}
119
 
120
// Get parent class information.
121
if ($parentclass = get_parent_class($eventname)) {
122
    $eventinformation['parentclass'] = '\\' . $parentclass;
123
}
124
 
125
// Fetch all the observers to be matched with this event.
126
$allobserverslist = report_eventlist_list_generator::get_observer_list();
127
$observers = array();
128
 
129
if (isset($allobserverslist['\\core\\event\\base'])) {
130
    $observers = $allobserverslist['\\core\\event\\base'];
131
}
132
if (isset($allobserverslist[$eventname])) {
133
    $observers = array_merge($observers, $allobserverslist[$eventname]);
134
}
135
 
136
$PAGE->set_primary_active_tab('siteadminnode');
137
$PAGE->set_secondary_active_tab('reports');
138
 
139
// OUTPUT.
140
$renderer = $PAGE->get_renderer('report_eventlist');
141
echo $renderer->render_event_detail($observers, $eventinformation);
142