-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathoverview.php
More file actions
154 lines (134 loc) · 6.41 KB
/
overview.php
File metadata and controls
154 lines (134 loc) · 6.41 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?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/>.
/**
* Completion Progress block overview page
*
* @package block_completion_progress
* @copyright 2018 Michael de Raadt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// Needed for progress bar output when sorting by percentage.
define('NO_OUTPUT_BUFFERING', true);
require_once(dirname(__DIR__, 2) . '/config.php');
require_once($CFG->dirroot . '/notes/lib.php');
use block_completion_progress\completion_progress;
use block_completion_progress\output\overview_filter;
use block_completion_progress\table\overview;
use block_completion_progress\table\overview_filterset;
use core_table\local\filter\filter;
use core_table\local\filter\integer_filter;
// Gather form data.
$instanceid = required_param('instanceid', PARAM_INT);
$courseid = required_param('courseid', PARAM_INT);
$perpage = optional_param('perpage', 20, PARAM_INT);
$download = optional_param('download', '', PARAM_ALPHA);
// Determine course and contexts.
$course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST);
$blockinstance = $DB->get_record('block_instances', ['id' => $instanceid], '*', MUST_EXIST);
$context = context_course::instance($courseid);
$blockcontext = context_block::instance($instanceid);
// Set up page parameters.
$strtitle = get_string('overview', 'block_completion_progress');
$PAGE->set_course($course);
$PAGE->set_url('/blocks/completion_progress/overview.php', ['instanceid' => $instanceid, 'courseid' => $courseid]);
$PAGE->set_context($context);
$PAGE->set_title("$course->shortname: $strtitle");
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($strtitle, $PAGE->url);
$PAGE->set_pagelayout('report');
// Check user is logged in and capable of accessing the Overview.
require_login($course, false);
require_capability('block/completion_progress:overview', $blockcontext);
$cachevalue = debugging() ? -1 : (int)get_config('block_completion_progress', 'cachevalue');
$PAGE->requires->css('/blocks/completion_progress/css.php?v=' . $cachevalue);
$PAGE->requires->js_call_amd('block_completion_progress/progressbar', 'init');
$PAGE->requires->js_call_amd('block_completion_progress/overview', 'init', [$course->id, note_get_state_names()]);
$output = $PAGE->get_renderer('block_completion_progress');
$progress = (new completion_progress($course))->for_overview()->for_block_instance($blockinstance);
$studentroles = $DB->get_fieldset_select('role', 'id', 'archetype = ?', ['student']);
$usedstudentroles = array_intersect_key(get_roles_used_in_context($context, false), array_flip($studentroles));
$studentroleid = $usedstudentroles ? array_key_first($usedstudentroles) : 0;
$filterset = new overview_filterset();
$filterset->add_filter(new integer_filter('courseid', filter::JOINTYPE_DEFAULT, [(int)$courseid]));
$filterset->add_filter(new integer_filter('blockinstanceid', filter::JOINTYPE_DEFAULT, [(int)$instanceid]));
if (($filtersetparam = optional_param('filterset', null, PARAM_RAW)) !== null) {
// We've been passed a filter configuration to apply.
try {
$tablefilter = json_decode($filtersetparam, true, 10, JSON_THROW_ON_ERROR);
if (isset($tablefilter['jointype'], $tablefilter['filters'])) {
$filterset->set_join_type($tablefilter['jointype']);
unset($tablefilter['filters']['courseid']);
unset($tablefilter['filters']['blockinstanceid']);
foreach ($tablefilter['filters'] as $fname => $fargs) {
$filterset->add_filter_from_params(
clean_param($fargs['name'], PARAM_RAW),
clean_param($fargs['jointype'], PARAM_INT),
clean_param_array($fargs['values'], PARAM_RAW)
);
}
}
} catch (JsonException $e) {
debugging("invalid filterset JSON: {$e->getMessage()}", DEBUG_DEVELOPER);
}
} else {
if ($studentroleid) {
// Default student role filter.
$filterset->add_filter(new integer_filter('roles', filter::JOINTYPE_DEFAULT, [$studentroleid]));
}
if (
!has_capability('moodle/site:accessallgroups', $context) &&
($groupids = array_keys(groups_get_all_groups($course->id, $USER->id)))
) {
// Default groups filter to show members of own groups for people without access to all groups.
$filterset->add_filter(new integer_filter('groups', filter::JOINTYPE_ANY, $groupids));
}
}
$table = new overview('block_completion_progress-overview-' . $instanceid);
$table->set_filterset($filterset);
$filter = new overview_filter(
$context,
(object) ['jointype' => $filterset->get_join_type(), 'filters' => $filterset->get_filters()],
$table->uniqueid
);
if ($table->is_downloading($download, 'completion_progress-' . $course->shortname)) {
$table->out(0, false);
exit;
}
echo $output->header();
echo $output->heading($strtitle);
if (!$progress->has_activities()) {
echo get_string('no_activities_message', 'block_completion_progress');
echo $output->footer();
exit;
}
if ($table->needs_percentages_computed()) {
// Compute percentages with a friendly progress indicator if sorting on initial load.
// If sorting happens on dynamic load, sucks to be the user watching the spinner.
core_php_time_limit::raise(0);
$computeprogress = new progress_bar('', 500, true);
$strcomputeprogress = get_string('computeprogress', 'block_completion_progress');
$progress->compute_overview_percentages(fn($pct) => $computeprogress->update_full($pct, $strcomputeprogress));
// Delete the progress bar from the page.
echo html_writer::script(
js_writer::function_call(
'(function(id){document.getElementById(id).remove();})',
[$computeprogress->get_id()]
)
);
}
echo $output->render($filter);
echo $output->render($table);
echo $output->footer();