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
 * Accessibility report
19
 *
20
 * @package    tool_brickfield
21
 * @copyright  2020 Brickfield Education Labs, www.brickfield.ie
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
use tool_brickfield\event\report_downloaded;
26
use tool_brickfield\event\report_viewed;
27
use tool_brickfield\accessibility;
28
use tool_brickfield\analysis;
29
use tool_brickfield\local\tool\filter;
30
use tool_brickfield\local\tool\tool;
31
use tool_brickfield\manager;
32
use tool_brickfield\output\renderer;
33
use tool_brickfield\registration;
34
use tool_brickfield\scheduler;
35
use tool_brickfield\task\process_analysis_requests;
36
 
37
require('../../../config.php');
38
require_once($CFG->libdir.'/adminlib.php');
39
 
40
// If this feature has been disabled, do nothing.
41
accessibility::require_accessibility_enabled();
42
 
43
// Check for valid registration.
44
$registration = new registration();
45
if (!$registration->toolkit_is_active()) {
46
    $urlregistration = manager::registration_url();
47
    redirect($urlregistration->out());
48
}
49
 
50
$config = get_config(manager::PLUGINNAME);
51
$courseid = optional_param('courseid', 0, PARAM_INT);
52
$categoryid = optional_param('categoryid', 0, PARAM_INT);
53
$tab = optional_param('tab', 'errors', PARAM_ALPHA);
54
$page = optional_param('page', 0, PARAM_INT);
55
$target = optional_param('target', '', PARAM_ALPHA);
56
$layout = optional_param('layout', 'admin', PARAM_ALPHA);
57
 
58
if ($courseid != 0) {
59
    // If accessing a course, check that the user has capability to use toolkit at course level.
60
    if (!$course = $DB->get_record('course', ['id' => $courseid], '*')) {
61
        throw new moodle_exception('invalidcourseid', manager::PLUGINNAME);
62
    }
63
    require_login($course);
64
    $context = context_course::instance($courseid);
65
    require_capability(accessibility::get_capability_name('viewcoursetools'), $context);
66
} else if ($categoryid != 0) {
67
    require_login();
68
    $context = context_coursecat::instance($categoryid);
69
    require_capability(accessibility::get_capability_name('viewcoursetools'), $context);
70
} else {
71
    require_login();
72
    // If accessing system level, check that the user has capability to use toolkit at system level.
73
    $context = context_system::instance();
74
    require_capability(accessibility::get_capability_name('viewsystemtools'), $context);
75
}
76
 
77
// Event logging of page view or summary download.
78
if ($target == 'pdf') {
79
    $event = report_downloaded::create(['context' => $context]);
80
} else {
81
    $event = report_viewed::create(['context' => $context,
82
        'other' => ['course' => $courseid, 'category' => $categoryid, 'tab' => $tab, 'target' => $target]]);
83
}
84
$event->trigger();
85
 
86
$action = optional_param('action', '', PARAM_ALPHA);
87
// Handle any single operation actions.
88
if ($action == 'requestanalysis') {
89
    if ($courseid != 0) {
90
        scheduler::request_course_analysis($courseid);
91
        if ($courseid == SITEID) {
92
            redirect(accessibility::get_plugin_url());
93
        } else {
94
            redirect(new \moodle_url('/course/view.php', ['id' => $courseid]), analysis::redirect_message());
95
        }
96
    }
97
}
98
 
99
// We need all of the tools available for various functions in the renderers.
100
$tools = tool::build_all_accessibilitytools();
101
if (isset($tools[$tab])) {
102
    $tool = $tools[$tab];
103
} else {
104
    throw new moodle_exception('invalidaccessibilitytool', manager::PLUGINNAME);
105
}
106
 
107
$perpagedefault = $config->perpage;
108
$perpage = optional_param('perpage', $perpagedefault, PARAM_INT);
109
$navurl = new moodle_url(accessibility::get_plugin_url(), ['courseid' => $courseid]);
110
$url = new moodle_url($navurl, ['tab' => $tab, 'perpage' => $perpage]);
111
 
112
$tool->set_filter(new filter($courseid, $categoryid, $tab, $page, $perpage, $url, $target));
113
 
114
// Course and site require different navigation setups.
115
if ($courseid > SITEID) {
116
    $PAGE->navigation->override_active_url($navurl);
117
} else {
118
    admin_externalpage_setup('tool_brickfield_reports', '', null, '', ['pagelayout' => 'report']);
119
}
120
$PAGE->set_context($context);
121
$PAGE->set_url($url);
122
$PAGE->set_pagelayout($layout);
123
$straccessibility = get_string('accessibilityreport', manager::PLUGINNAME);
124
$output = $PAGE->get_renderer(manager::PLUGINNAME);
125
$toolname = $tool->get_toolshortname();
126
$PAGE->set_title($toolname.' '.$straccessibility);
127
$PAGE->set_heading($straccessibility);
128
 
129
if ($tool->data_is_valid() && ($tool->get_output_target() == 'pdf')) {
130
    // PDF output doesn't return.
131
    $tool->get_output();
132
} else {
133
    echo $output->header();
134
    $courseid = ($courseid == 0) ? SITEID : $courseid;
135
    if (analysis::is_course_analyzed($courseid)) {
136
        echo $output->tabs($tool->get_filter(), $tools);
137
        echo $output->cachealert();
138
 
139
        if ($registration->validation_pending()) {
140
            echo $output->notvalidatedalert();
141
        }
142
 
143
        if (!$tool->data_is_valid()) {
144
            echo($tool->data_error());
145
        } else {
146
            echo $tool->get_output();
147
        }
148
    } else {
149
        $analysisdisabled = $output->cachealert();
150
        if (!empty($analysisdisabled)) {
151
            echo $analysisdisabled;
152
        } else {
153
            echo $output->analysisalert($courseid);
154
        }
155
    }
156
 
157
    echo $output->footer();
158
}