forked from WisdmLabs/moodle-local_edwiserreports-free
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_handler.php
87 lines (71 loc) · 2.84 KB
/
request_handler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require('../../config.php');
use local_edwiserreports\controller\edwiserReportKernel;
use local_edwiserreports\controller\edwiserReportRouter;
// Define ajax script based on action value.
$action = filter_input(INPUT_GET, 'action', FILTER_SANITIZE_STRIPPED);
if (!isset($action) || empty($action)) {
return;
}
// Only make ajax true if action has ajax in name.
$actionpattern = '/_ajax$/i';
// Include Moodle config
// This code is to run or include file at developer end
// It is because we use symlink for theme from local_gitrepo.
if (!@include_once(__DIR__.'/../../config.php')) {
include_once('/var/www/html/elucid/v37/config.php');
}
require_sesskey();
$systemcontext = context_system::instance();
$contextid = optional_param('contextid', $systemcontext->id, PARAM_INT);
list($context, $course, $cm) = get_context_info_array($contextid);
$nologinactions = ['get_loginstatus', 'read_page', 'get_courses_ajax']; // Actions which do not require login checks.
if (!in_array($action, $nologinactions)) {
$courseactions = ['get_media', 'get_page'];
if (in_array($action, $courseactions)) {
require_login($course, false, $cm, false, true);
} else {
require_login();
}
}
$PAGE->set_context($context);
if ($course !== null) {
$PAGE->set_course($course);
}
$PAGE->set_url('/local/edwiserreports/request_handler.php', array('action' => $action, 'contextid' => $context->id));
if ($cm !== null) {
$PAGE->set_cm($cm);
}
$router = new edwiserReportRouter();
// Add controllers automatically.
$controllerdir = __DIR__.'/classes/controller';
$contfiles = scandir($controllerdir);
foreach ($contfiles as $contfile) {
// Include controllers.
$pattern = '/Controller.php$/i';
if (preg_match($pattern, $contfile)) {
$classname = '\\local_edwiserreports\\controller\\'.str_ireplace('.php', '', $contfile);
if (class_exists($classname)) {
$rc = new ReflectionClass($classname);
if ($rc->isSubclassOf('\\local_edwiserreports\\controller\\controllerAbstract')) {
$router->add_controller(new $classname());
}
}
}
}
$kernel = new edwiserReportKernel($router);
$kernel->handle($action);