Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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) {
1441 ariadna 90
        require_sesskey();
1 efrain 91
        scheduler::request_course_analysis($courseid);
92
        if ($courseid == SITEID) {
93
            redirect(accessibility::get_plugin_url());
94
        } else {
95
            redirect(new \moodle_url('/course/view.php', ['id' => $courseid]), analysis::redirect_message());
96
        }
97
    }
98
}
99
 
100
// We need all of the tools available for various functions in the renderers.
101
$tools = tool::build_all_accessibilitytools();
102
if (isset($tools[$tab])) {
103
    $tool = $tools[$tab];
104
} else {
105
    throw new moodle_exception('invalidaccessibilitytool', manager::PLUGINNAME);
106
}
107
 
108
$perpagedefault = $config->perpage;
109
$perpage = optional_param('perpage', $perpagedefault, PARAM_INT);
110
$navurl = new moodle_url(accessibility::get_plugin_url(), ['courseid' => $courseid]);
111
$url = new moodle_url($navurl, ['tab' => $tab, 'perpage' => $perpage]);
112
 
113
$tool->set_filter(new filter($courseid, $categoryid, $tab, $page, $perpage, $url, $target));
114
 
115
// Course and site require different navigation setups.
116
if ($courseid > SITEID) {
117
    $PAGE->navigation->override_active_url($navurl);
118
} else {
119
    admin_externalpage_setup('tool_brickfield_reports', '', null, '', ['pagelayout' => 'report']);
120
}
121
$PAGE->set_context($context);
122
$PAGE->set_url($url);
123
$PAGE->set_pagelayout($layout);
124
$straccessibility = get_string('accessibilityreport', manager::PLUGINNAME);
125
$output = $PAGE->get_renderer(manager::PLUGINNAME);
126
$toolname = $tool->get_toolshortname();
127
$PAGE->set_title($toolname.' '.$straccessibility);
128
$PAGE->set_heading($straccessibility);
129
 
130
if ($tool->data_is_valid() && ($tool->get_output_target() == 'pdf')) {
131
    // PDF output doesn't return.
132
    $tool->get_output();
133
} else {
134
    echo $output->header();
135
    $courseid = ($courseid == 0) ? SITEID : $courseid;
136
    if (analysis::is_course_analyzed($courseid)) {
137
        echo $output->tabs($tool->get_filter(), $tools);
138
        echo $output->cachealert();
139
 
140
        if ($registration->validation_pending()) {
141
            echo $output->notvalidatedalert();
142
        }
143
 
144
        if (!$tool->data_is_valid()) {
145
            echo($tool->data_error());
146
        } else {
147
            echo $tool->get_output();
148
        }
149
    } else {
150
        $analysisdisabled = $output->cachealert();
151
        if (!empty($analysisdisabled)) {
152
            echo $analysisdisabled;
153
        } else {
154
            echo $output->analysisalert($courseid);
155
        }
156
    }
157
 
158
    echo $output->footer();
159
}