-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadminlist.php
More file actions
192 lines (168 loc) · 6.28 KB
/
adminlist.php
File metadata and controls
192 lines (168 loc) · 6.28 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?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/>.
/**
* Simultaneous report administration recorrds view.
*
* @package report_simultaneous
* @subpackage simultaneous
* @copyright 2023 Juan Pablo de Castro <juan.pablo.de.castro@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
require_once($CFG->dirroot . '/report/simultaneous/locallib.php');
require_once($CFG->dirroot . '/lib/tablelib.php');
$id = required_param('id', PARAM_INT); // Course id.
if (!$course = $DB->get_record('course', ['id' => $id])) {
throw new moodle_exception('invalidcourse');
}
require_login($course);
$context = context_course::instance($course->id);
require_capability('report/simultaneous:adminlisting', $context);
$v = required_param('v', PARAM_ALPHANUM);
$userid = required_param('userid', PARAM_INT);
$startdate = required_param('startdate', PARAM_INT);
$enddate = required_param('enddate', PARAM_INT);
$refmodules = optional_param_array('refmodules', [], PARAM_INT);
$filtertext = optional_param('filtertext', '', PARAM_TEXT);
$download = optional_param('download', '', PARAM_ALPHA);
$baseparams = [
'id' => $id,
'v' => $v,
'userid' => $userid,
'startdate' => $startdate,
'enddate' => $enddate,
];
$url = new moodle_url('/report/simultaneous/adminlist.php', $baseparams);
if (!empty($filtertext)) {
$url->param('filtertext', $filtertext);
}
foreach ($refmodules as $mod) {
$url->param('refmodules[]', $mod);
}
$PAGE->set_pagelayout('report');
$PAGE->set_url($url);
$PAGE->set_context($context);
$PAGE->set_title(get_string('adminlisttitle', 'report_simultaneous'));
$PAGE->set_heading(format_string($course->fullname, true, ['context' => $context]));
// Get enrolled users in course.
$users = get_enrolled_users($context, '', 0, 'u.*', null, 0, 0, false);
if (empty($refmodules)) {
$userstoanalyse = array_keys($users);
} else {
$userstoanalyse = report_simultaneous_get_users_with_activity($course, $refmodules, $startdate, $enddate);
}
// Export as csv the records.
$data = report_simultaneous_get_indicator($v, $course, $refmodules, $userstoanalyse, [$userid], $startdate, $enddate, false);
if (!empty($filtertext)) {
$needle = core_text::strtolower($filtertext);
foreach ($data as $index => $row) {
$rowmatch = false;
foreach ((array)$row as $value) {
$cellvalue = core_text::strtolower((string)$value);
if (strpos($cellvalue, $needle) !== false) {
$rowmatch = true;
break;
}
}
if (!$rowmatch) {
unset($data[$index]);
}
}
}
if (!empty($download)) {
if (!empty($data)) {
$first = reset($data);
$columns = array_keys((array)$first);
$headers = $columns;
$rows = [];
foreach ($data as $row) {
$record = [];
foreach ($columns as $column) {
$record[] = (string)($row->{$column} ?? '');
}
$rows[] = $record;
}
} else {
$rows = [[get_string('nothingtodisplay')]];
$headers = ['results'];
}
\core\dataformat::download_data(
'simultaneous-adminlist-' . $course->id . '-' . core_text::strtolower($v),
$download,
$headers,
$rows
);
die();
}
$table = new flexible_table('report-simultaneous-adminlist-' . $course->id . '-' . $v . '-' . $userid);
$table->is_downloading(
$download,
'simultaneous-adminlist-' . $course->id . '-' . core_text::strtolower($v),
'simultaneous-adminlist'
);
$table->show_download_buttons_at([TABLE_P_TOP, TABLE_P_BOTTOM]);
$table->define_baseurl($url);
$table->set_attribute('class', 'generaltable generalbox reporttable');
$table->sortable(false);
if (!empty($data)) {
$first = reset($data);
$columns = array_keys((array)$first);
$headers = $columns;
} else {
$columns = ['empty'];
$headers = ['results'];
}
$table->define_columns($columns);
$table->define_headers($headers);
$table->setup();
if (!$table->is_downloading()) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('adminlisttitle', 'report_simultaneous'));
$filterformurl = new moodle_url('/report/simultaneous/adminlist.php', $baseparams);
echo html_writer::start_tag('form', ['method' => 'get', 'action' => $filterformurl->out(false), 'class' => 'mb-3']);
foreach ($baseparams as $param => $value) {
echo html_writer::empty_tag('input', ['type' => 'hidden', 'name' => $param, 'value' => $value]);
}
foreach ($refmodules as $mod) {
echo html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'refmodules[]', 'value' => $mod]);
}
echo html_writer::label(get_string('filtertext', 'report_simultaneous'), 'id_filtertext', false, ['class' => 'mr-2']);
echo html_writer::empty_tag('input', [
'type' => 'text',
'name' => 'filtertext',
'id' => 'id_filtertext',
'value' => $filtertext,
'class' => 'mr-2',
]);
echo html_writer::empty_tag('input', ['type' => 'submit', 'value' => get_string('filterresults', 'report_simultaneous')]);
$clearurl = new moodle_url('/report/simultaneous/adminlist.php', $baseparams);
foreach ($refmodules as $mod) {
$clearurl->param('refmodules[]', $mod);
}
echo html_writer::link($clearurl, get_string('clearfilterresults', 'report_simultaneous'), ['class' => 'ml-2']);
echo html_writer::end_tag('form');
}
if (!empty($data)) {
foreach ($data as $row) {
$table->add_data(array_values((array)$row));
}
} else {
$table->add_data([get_string('nothingtodisplay')]);
}
$table->finish_output();
if (!$table->is_downloading()) {
echo $OUTPUT->footer();
}