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 |
* Log report renderer.
|
|
|
19 |
*
|
|
|
20 |
* @package report_log
|
|
|
21 |
* @copyright 2014 Rajesh Taneja <rajesh.taneja@gmail.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
defined('MOODLE_INTERNAL') || die;
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Report log renderer's for printing reports.
|
|
|
28 |
*
|
|
|
29 |
* @package report_log
|
|
|
30 |
* @copyright 2014 Rajesh Taneja <rajesh.taneja@gmail.com>
|
|
|
31 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
32 |
*/
|
|
|
33 |
class report_log_renderer extends plugin_renderer_base {
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* This method should never be manually called, it should only be called by process.
|
|
|
37 |
*
|
|
|
38 |
* @deprecated since 2.8, to be removed in 2.9
|
|
|
39 |
* @param report_log_renderable $reportlog
|
|
|
40 |
* @return string
|
|
|
41 |
*/
|
|
|
42 |
public function render_report_log_renderable(report_log_renderable $reportlog) {
|
|
|
43 |
debugging('Do not call this method. Please call $renderer->render($reportlog) instead.', DEBUG_DEVELOPER);
|
|
|
44 |
return $this->render($reportlog);
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* Render log report page.
|
|
|
49 |
*
|
|
|
50 |
* @param report_log_renderable $reportlog object of report_log.
|
|
|
51 |
*/
|
|
|
52 |
protected function render_report_log(report_log_renderable $reportlog) {
|
|
|
53 |
if (empty($reportlog->selectedlogreader)) {
|
|
|
54 |
echo $this->output->notification(get_string('nologreaderenabled', 'report_log'), 'notifyproblem');
|
|
|
55 |
return;
|
|
|
56 |
}
|
|
|
57 |
if ($reportlog->showselectorform) {
|
|
|
58 |
$this->report_selector_form($reportlog);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
if ($reportlog->showreport) {
|
|
|
62 |
$reportlog->tablelog->out($reportlog->perpage, true);
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
* Prints/return reader selector
|
|
|
68 |
*
|
|
|
69 |
* @param report_log_renderable $reportlog log report.
|
|
|
70 |
*/
|
|
|
71 |
public function reader_selector(report_log_renderable $reportlog) {
|
|
|
72 |
$readers = $reportlog->get_readers(true);
|
|
|
73 |
if (empty($readers)) {
|
|
|
74 |
$readers = array(get_string('nologreaderenabled', 'report_log'));
|
|
|
75 |
}
|
|
|
76 |
$url = fullclone ($reportlog->url);
|
|
|
77 |
$url->remove_params(array('logreader'));
|
|
|
78 |
$select = new single_select($url, 'logreader', $readers, $reportlog->selectedlogreader, null);
|
|
|
79 |
$select->set_label(get_string('selectlogreader', 'report_log'));
|
|
|
80 |
echo $this->output->render($select);
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
/**
|
|
|
84 |
* This function is used to generate and display selector form
|
|
|
85 |
*
|
|
|
86 |
* @param report_log_renderable $reportlog log report.
|
|
|
87 |
*/
|
|
|
88 |
public function report_selector_form(report_log_renderable $reportlog) {
|
|
|
89 |
echo html_writer::start_tag('form', array('class' => 'logselecform', 'action' => $reportlog->url, 'method' => 'get'));
|
1441 |
ariadna |
90 |
echo html_writer::start_div('d-flex flex-wrap align-items-center gap-2');
|
1 |
efrain |
91 |
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'chooselog', 'value' => '1'));
|
|
|
92 |
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'showusers', 'value' => $reportlog->showusers));
|
|
|
93 |
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'showcourses',
|
|
|
94 |
'value' => $reportlog->showcourses));
|
|
|
95 |
|
1441 |
ariadna |
96 |
$selectedcourseid = empty($reportlog->sitecoursefilter)
|
|
|
97 |
? (empty($reportlog->course) ? 0 : $reportlog->course->id)
|
|
|
98 |
: $reportlog->sitecoursefilter;
|
1 |
efrain |
99 |
|
1441 |
ariadna |
100 |
echo $this->get_course_selector_field($reportlog, $selectedcourseid);
|
1 |
efrain |
101 |
|
|
|
102 |
// Add group selector.
|
|
|
103 |
$groups = $reportlog->get_group_list();
|
|
|
104 |
if (!empty($groups)) {
|
|
|
105 |
echo html_writer::label(get_string('selectagroup'), 'menugroup', false, array('class' => 'accesshide'));
|
1441 |
ariadna |
106 |
echo html_writer::select($groups, "group", $reportlog->groupid, get_string("allgroups"));
|
1 |
efrain |
107 |
}
|
|
|
108 |
|
|
|
109 |
// Add user selector.
|
|
|
110 |
$users = $reportlog->get_user_list();
|
|
|
111 |
|
|
|
112 |
if ($reportlog->showusers) {
|
|
|
113 |
echo html_writer::label(get_string('selctauser'), 'menuuser', false, array('class' => 'accesshide'));
|
1441 |
ariadna |
114 |
echo html_writer::select($users, "user", $reportlog->userid, get_string("allparticipants"));
|
1 |
efrain |
115 |
} else {
|
|
|
116 |
$users = array();
|
|
|
117 |
if (!empty($reportlog->userid)) {
|
|
|
118 |
$users[$reportlog->userid] = $reportlog->get_selected_user_fullname();
|
|
|
119 |
} else {
|
|
|
120 |
$users[0] = get_string('allparticipants');
|
|
|
121 |
}
|
|
|
122 |
echo html_writer::label(get_string('selctauser'), 'menuuser', false, array('class' => 'accesshide'));
|
1441 |
ariadna |
123 |
echo html_writer::select($users, "user", $reportlog->userid, false);
|
1 |
efrain |
124 |
$a = new stdClass();
|
|
|
125 |
$a->url = new moodle_url('/report/log/index.php', array('chooselog' => 0,
|
|
|
126 |
'group' => $reportlog->get_selected_group(), 'user' => $reportlog->userid,
|
|
|
127 |
'id' => $selectedcourseid, 'date' => $reportlog->date, 'modid' => $reportlog->modid,
|
|
|
128 |
'showusers' => 1, 'showcourses' => $reportlog->showcourses));
|
|
|
129 |
$a->url = $a->url->out(false);
|
|
|
130 |
echo html_writer::start_span('mx-1');
|
|
|
131 |
print_string('logtoomanyusers', 'moodle', $a);
|
|
|
132 |
echo html_writer::end_span();
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
// Add date selector.
|
|
|
136 |
$dates = $reportlog->get_date_options();
|
|
|
137 |
echo html_writer::label(get_string('date'), 'menudate', false, array('class' => 'accesshide'));
|
1441 |
ariadna |
138 |
echo html_writer::select($dates, "date", $reportlog->date, get_string("alldays"));
|
1 |
efrain |
139 |
|
|
|
140 |
// Add activity selector.
|
1441 |
ariadna |
141 |
echo $this->get_activity_selector_field($reportlog);
|
1 |
efrain |
142 |
|
|
|
143 |
// Add actions selector.
|
|
|
144 |
echo html_writer::label(get_string('actions'), 'menumodaction', false, array('class' => 'accesshide'));
|
|
|
145 |
echo html_writer::select($reportlog->get_actions(), 'modaction', $reportlog->action,
|
1441 |
ariadna |
146 |
get_string("allactions"));
|
1 |
efrain |
147 |
|
|
|
148 |
// Add origin.
|
|
|
149 |
$origin = $reportlog->get_origin_options();
|
|
|
150 |
echo html_writer::label(get_string('origin', 'report_log'), 'menuorigin', false, array('class' => 'accesshide'));
|
1441 |
ariadna |
151 |
echo html_writer::select($origin, 'origin', $reportlog->origin, false);
|
1 |
efrain |
152 |
|
|
|
153 |
// Add edulevel.
|
|
|
154 |
$edulevel = $reportlog->get_edulevel_options();
|
|
|
155 |
echo html_writer::label(get_string('edulevel'), 'menuedulevel', false, array('class' => 'accesshide'));
|
1441 |
ariadna |
156 |
echo html_writer::select($edulevel, 'edulevel', $reportlog->edulevel, false) .$this->help_icon('edulevel');
|
1 |
efrain |
157 |
|
|
|
158 |
// Add reader option.
|
|
|
159 |
// If there is some reader available then only show submit button.
|
|
|
160 |
$readers = $reportlog->get_readers(true);
|
|
|
161 |
if (!empty($readers)) {
|
|
|
162 |
if (count($readers) == 1) {
|
|
|
163 |
$attributes = array('type' => 'hidden', 'name' => 'logreader', 'value' => key($readers));
|
|
|
164 |
echo html_writer::empty_tag('input', $attributes);
|
|
|
165 |
} else {
|
|
|
166 |
echo html_writer::label(get_string('selectlogreader', 'report_log'), 'menureader', false,
|
|
|
167 |
array('class' => 'accesshide'));
|
1441 |
ariadna |
168 |
echo html_writer::select($readers, 'logreader', $reportlog->selectedlogreader, false);
|
1 |
efrain |
169 |
}
|
1441 |
ariadna |
170 |
echo html_writer::end_div();
|
|
|
171 |
echo html_writer::start_div('mt-2');
|
1 |
efrain |
172 |
echo html_writer::empty_tag('input', array('type' => 'submit',
|
|
|
173 |
'value' => get_string('gettheselogs'), 'class' => 'btn btn-primary'));
|
|
|
174 |
echo html_writer::end_div();
|
|
|
175 |
}
|
|
|
176 |
echo html_writer::end_tag('form');
|
|
|
177 |
}
|
1441 |
ariadna |
178 |
|
|
|
179 |
/**
|
|
|
180 |
* Generates the course selector field for the log report.
|
|
|
181 |
*
|
|
|
182 |
* @param report_log_renderable $reportlog The output instance.
|
|
|
183 |
* @param int $selectedcourseid
|
|
|
184 |
* @return string
|
|
|
185 |
*/
|
|
|
186 |
private function get_course_selector_field(report_log_renderable $reportlog, int $selectedcourseid): string {
|
|
|
187 |
// When the log report is accessed vie an activity, we do not need a course selector.
|
|
|
188 |
if ($reportlog->isactivitypage) {
|
|
|
189 |
return html_writer::empty_tag(
|
|
|
190 |
'input',
|
|
|
191 |
['type' => 'hidden', 'name' => 'id', 'value' => $selectedcourseid]
|
|
|
192 |
);
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
$result = '';
|
|
|
196 |
$sitecontext = context_system::instance();
|
|
|
197 |
$courses = $reportlog->get_course_list();
|
|
|
198 |
|
|
|
199 |
if (!empty($courses) && $reportlog->showcourses) {
|
|
|
200 |
$result .= html_writer::label(get_string('selectacourse'), 'menuid', false, ['class' => 'accesshide']);
|
|
|
201 |
$result .= html_writer::select($courses, "id", $selectedcourseid, null);
|
|
|
202 |
return $result;
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
$courses = [];
|
|
|
206 |
$courseinfo = ($selectedcourseid == SITEID) ? ' (' . get_string('site') . ') ' : '';
|
|
|
207 |
$courses[$selectedcourseid] = get_course_display_name_for_list($reportlog->course) . $courseinfo;
|
|
|
208 |
|
|
|
209 |
$result .= html_writer::label(get_string('selectacourse'), 'menuid', false, ['class' => 'accesshide']);
|
|
|
210 |
$result .= html_writer::select($courses, "id", $selectedcourseid, false);
|
|
|
211 |
|
|
|
212 |
// Check if user is admin and this came because of limitation on number of courses to show in dropdown.
|
|
|
213 |
if (has_capability('report/log:view', $sitecontext)) {
|
|
|
214 |
$a = new stdClass();
|
|
|
215 |
$a->url = new moodle_url(
|
|
|
216 |
'/report/log/index.php',
|
|
|
217 |
[
|
|
|
218 |
'chooselog' => 0,
|
|
|
219 |
'group' => $reportlog->get_selected_group(),
|
|
|
220 |
'user' => $reportlog->userid,
|
|
|
221 |
'id' => $selectedcourseid,
|
|
|
222 |
'date' => $reportlog->date,
|
|
|
223 |
'modid' => $reportlog->modid,
|
|
|
224 |
'showcourses' => 1, 'showusers' => $reportlog->showusers,
|
|
|
225 |
]
|
|
|
226 |
);
|
|
|
227 |
$a->url = $a->url->out(false);
|
|
|
228 |
$result .= get_string('logtoomanycourses', 'moodle', $a);
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
return $result;
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
/**
|
|
|
235 |
* Generates the activity selector field for the log report.
|
|
|
236 |
*
|
|
|
237 |
* @param report_log_renderable $reportlog The output instance.
|
|
|
238 |
* @return string
|
|
|
239 |
*/
|
|
|
240 |
private function get_activity_selector_field(report_log_renderable $reportlog): string {
|
|
|
241 |
$result = '';
|
|
|
242 |
// When the log report is accessed vie an activity, we do not need an activity selector.
|
|
|
243 |
if ($reportlog->isactivitypage) {
|
|
|
244 |
$result .= html_writer::empty_tag(
|
|
|
245 |
'input',
|
|
|
246 |
['type' => 'hidden', 'name' => 'isactivitypage', 'value' => $reportlog->isactivitypage]
|
|
|
247 |
);
|
|
|
248 |
$result .= html_writer::empty_tag(
|
|
|
249 |
'input',
|
|
|
250 |
['type' => 'hidden', 'name' => 'modid', 'value' => $reportlog->modid]
|
|
|
251 |
);
|
|
|
252 |
return $result;
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
[$activities, $disabled] = $reportlog->get_activities_list();
|
|
|
256 |
|
|
|
257 |
$result .= html_writer::label(
|
|
|
258 |
text: get_string('activities'),
|
|
|
259 |
for: 'menumodid',
|
|
|
260 |
colonize: false,
|
|
|
261 |
attributes: ['class' => 'accesshide'],
|
|
|
262 |
);
|
|
|
263 |
$result .= html_writer::select(
|
|
|
264 |
options: $activities,
|
|
|
265 |
name: "modid",
|
|
|
266 |
selected: $reportlog->modid,
|
|
|
267 |
nothing: get_string("allactivities"),
|
|
|
268 |
attributes: [],
|
|
|
269 |
disabled: $disabled,
|
|
|
270 |
);
|
|
|
271 |
return $result;
|
|
|
272 |
}
|
1 |
efrain |
273 |
}
|