1 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
ob_start();
|
|
|
5 |
|
|
|
6 |
require('../../config.php');
|
|
|
7 |
//require('autoload.php');
|
|
|
8 |
|
|
|
9 |
global $DB, $PAGE, $CFG, $OUTPUT;
|
|
|
10 |
|
|
|
11 |
require_once($CFG->libdir . '/adminlib.php');
|
|
|
12 |
require_once $CFG->libdir . '/completionlib.php';
|
|
|
13 |
require_once $CFG->dirroot. '/completion/classes/progress.php';
|
|
|
14 |
|
|
|
15 |
//require_once $CFG->libdir . '/badgeslib.php';
|
|
|
16 |
//require_once $CFG->libdir . '/gradelib.php';
|
|
|
17 |
//require_once $CFG->dirroot . '/grade/querylib.php';
|
|
|
18 |
|
|
|
19 |
require_once(__DIR__ . '/locallib.php');
|
|
|
20 |
|
|
|
21 |
require_login();
|
|
|
22 |
require_capability('local/cesa_reportes:view', context_system::instance());
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
$classname = optional_param('classname', 'dashboard', PARAM_TEXT);
|
|
|
27 |
$page = optional_param('page', 0, PARAM_INT);
|
|
|
28 |
|
|
|
29 |
$PAGE->set_url(new moodle_url('/local/cesa_reportes'));
|
|
|
30 |
$PAGE->set_context(context_system::instance());
|
|
|
31 |
//$PAGE->set_pagetype('admin-setting');
|
|
|
32 |
$PAGE->set_pagelayout('plain');
|
|
|
33 |
$PAGE->set_title('Cesa Reportes');
|
|
|
34 |
$PAGE->set_heading('Cesa Reportes');
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
$filter_userids = [];
|
|
|
38 |
$filter_courseids = [];
|
|
|
39 |
$filter_by_company_active = false;
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
$PAGE->requires->jquery();
|
|
|
43 |
|
|
|
44 |
$PAGE->requires->css(new moodle_url($CFG->wwwroot . '/local/cesa_reportes/assets/pnotify.css'));
|
|
|
45 |
$PAGE->requires->js(new moodle_url($CFG->wwwroot . '/local/cesa_reportes/assets/pnotify.js'));
|
|
|
46 |
|
|
|
47 |
$PAGE->requires->css(new moodle_url($CFG->wwwroot . '/local/cesa_reportes/css/local_cesa_reportes.css'));
|
|
|
48 |
|
|
|
49 |
$PAGE->navbar->add(get_string('modulename', 'local_cesa_reportes'), new moodle_url('/local/cesa_reportes'));
|
|
|
50 |
|
|
|
51 |
$context = [
|
|
|
52 |
'classname_dashboard' => $classname == 'dashboard' ? 1 : 0,
|
|
|
53 |
'classname_one_course' => $classname == 'one_course' ? 1 : 0,
|
|
|
54 |
'classname_one_user' => $classname == 'one_user' ? 1 : 0,
|
|
|
55 |
'classname_all_course' => $classname == 'all_courses' ? 1 : 0,
|
|
|
56 |
'classname_all_course_with_activities' => $classname == 'all_courses_with_activities' ? 1 : 0,
|
|
|
57 |
'classname_custom' => $classname == 'custom' ? 1 : 0,
|
|
|
58 |
'classname_all_files' => $classname == 'all_files' ? 1 : 0,
|
|
|
59 |
];
|
|
|
60 |
|
|
|
61 |
if($classname == 'dashboard')
|
|
|
62 |
{
|
|
|
63 |
$context['graph_serie1_color'] = get_config('local_cesa_reportes', 'graph_serie1_color');
|
|
|
64 |
$context['graph_serie2_color'] = get_config('local_cesa_reportes', 'graph_serie2_color');
|
|
|
65 |
|
|
|
66 |
// $PAGE->requires->js('/local/cesa_reportes/assets/jquery-1.12.2.min.js');
|
|
|
67 |
$PAGE->requires->js(new moodle_url($CFG->wwwroot . '/local/cesa_reportes/assets/Chart.min.js'));
|
|
|
68 |
$PAGE->requires->js(new moodle_url($CFG->wwwroot . '/local/cesa_reportes/js/local_cesa_reportes_charts.js'));
|
|
|
69 |
$PAGE->requires->js(new moodle_url($CFG->wwwroot . '/local/cesa_reportes/js/local_cesa_reportes_dashboard.js'));
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
$data = local_cesa_reportes_get_week_days();
|
|
|
73 |
|
|
|
74 |
$context['last_ten_user_activities'] = (array) local_cesa_reportes_get_last_ten_user_activities($filter_by_company_active, $filter_userids, $data->min, $data->max);
|
|
|
75 |
$context['top_ten_user_activities'] = (array) local_cesa_reportes_get_top_ten_user_activities($filter_by_company_active, $filter_userids, $data->min, $data->max);
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
$context['last_ten_user_modules_completion'] = (array) local_cesa_reportes_get_last_ten_user_modules_completion($filter_by_company_active, $filter_userids, $data->min, $data->max);
|
|
|
80 |
$context['top_ten_user_modules_completion'] = (array) local_cesa_reportes_get_top_ten_user_modules_completion($filter_by_company_active, $filter_userids, $data->min, $data->max);
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
$context['chart'] = [];
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
foreach($data->days as $day)
|
|
|
91 |
{
|
|
|
92 |
|
|
|
93 |
$data1 = local_cesa_reportes_get_count_activities($filter_by_company_active, $filter_userids, $day->min, $day->max);
|
|
|
94 |
$data2 = local_cesa_reportes_get_count_modules_completion($filter_by_company_active, $filter_userids, $day->min, $day->max);
|
|
|
95 |
|
|
|
96 |
array_push($context['chart'], [
|
|
|
97 |
'label' => $day->day,
|
|
|
98 |
'data1' => $data1,
|
|
|
99 |
'data2' => $data2,
|
|
|
100 |
]);
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
} else if($classname == 'one_course') {
|
|
|
108 |
$PAGE->requires->css(new moodle_url($CFG->wwwroot . '/local/cesa_reportes/assets/select2.css'));
|
|
|
109 |
|
|
|
110 |
$PAGE->requires->js(new moodle_url($CFG->wwwroot . '/local/cesa_reportes/js/local_cesa_reportes_report_for_one_course.js'));
|
|
|
111 |
|
|
|
112 |
$context['courses'] = [];
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
$sql = 'SELECT id, fullname FROM {course} ';
|
|
|
116 |
|
|
|
117 |
if($filter_by_company_active) {
|
|
|
118 |
$filter_courseids = empty($filter_courseids) ? [-1] : $filter_courseids;
|
|
|
119 |
$sql .= ' WHERE id IN (' . implode(',', $filter_courseids) . ')';
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
$sql .= ' ORDER BY fullname ';
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
$records = $DB->get_records_sql($sql);
|
|
|
127 |
foreach($records as $record)
|
|
|
128 |
{
|
|
|
129 |
array_push($context['courses'], [
|
|
|
130 |
'id' => $record->id,
|
|
|
131 |
'name' => $record->fullname
|
|
|
132 |
]) ;
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
} else if($classname == 'one_user') {
|
|
|
138 |
$context['users'] = [];
|
|
|
139 |
|
|
|
140 |
$PAGE->requires->css(new moodle_url($CFG->wwwroot . '/local/cesa_reportes/assets/select2.css'));
|
|
|
141 |
|
|
|
142 |
$PAGE->requires->js(new moodle_url($CFG->wwwroot . '/local/cesa_reportes/js/local_cesa_reportes_report_for_one_user.js'));
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
$sql = 'SELECT id, firstname, lastname, email FROM {user} WHERE id > 1 AND deleted = 0 ' .
|
|
|
146 |
' AND suspended = 0 ';
|
|
|
147 |
|
|
|
148 |
if($filter_by_company_active) {
|
|
|
149 |
$filter_userids = empty($filter_userids) ? [-1] : $filter_userids;
|
|
|
150 |
$sql .= ' AND id IN (' . implode(',', $filter_userids) . ')';
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
$sql .= ' ORDER BY lastname, firstname, email ';
|
|
|
154 |
|
|
|
155 |
$records = $DB->get_records_sql($sql);
|
|
|
156 |
foreach($records as $record)
|
|
|
157 |
{
|
|
|
158 |
array_push($context['users'], [
|
|
|
159 |
'id' => $record->id,
|
|
|
160 |
'name' => $record->lastname . ' ' . $record->firstname . ' (' . $record->email . ')'
|
|
|
161 |
]) ;
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
|
|
|
165 |
|
|
|
166 |
} else if($classname == 'all_courses') {
|
|
|
167 |
|
|
|
168 |
$PAGE->requires->js(new moodle_url($CFG->wwwroot . '/local/cesa_reportes/js/local_cesa_reportes_all_courses.js'));
|
|
|
169 |
$extra_fields = local_cesa_reportes_get_user_extra_field_names();
|
|
|
170 |
|
|
|
171 |
|
|
|
172 |
$context['fields'] = [];
|
|
|
173 |
array_push($context['fields'], ['field' => 'Apellido']);
|
|
|
174 |
array_push($context['fields'], ['field' => 'Nombre']);
|
|
|
175 |
array_push($context['fields'], ['field' => 'Email']);
|
|
|
176 |
array_push($context['fields'], ['field' => 'Curso']);
|
|
|
177 |
array_push($context['fields'], ['field' => 'Categoria']);
|
|
|
178 |
array_push($context['fields'], ['field' => 'Matriculación']);
|
|
|
179 |
array_push($context['fields'], ['field' => 'Fecha finalización']);
|
|
|
180 |
array_push($context['fields'], ['field' => 'Actividades asignadas']);
|
|
|
181 |
array_push($context['fields'], ['field' => 'Actividades completadas']);
|
|
|
182 |
array_push($context['fields'], ['field' => 'Progreso %']);
|
|
|
183 |
array_push($context['fields'], ['field' => 'Primera actividad']);
|
|
|
184 |
array_push($context['fields'], ['field' => 'Ultima actividad']);
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
foreach($extra_fields as $extra_field)
|
|
|
188 |
{
|
|
|
189 |
array_push($context['fields'], ['field' => $extra_field->name]);
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
|
|
|
193 |
$context['items'] = [];
|
|
|
194 |
|
|
|
195 |
$page = $page ? $page : 1;
|
|
|
196 |
$include_modules = true;
|
|
|
197 |
$data = local_cesa_reportes_get_data_for_report_or_excel($filter_by_company_active, $filter_userids, $filter_courseids, $include_modules, $page);
|
|
|
198 |
$records = $data['items'];
|
|
|
199 |
|
|
|
200 |
$context['pagination'] = $data['pagination'];
|
|
|
201 |
if($context['pagination']['page'] > 1) {
|
|
|
202 |
$context['pagination']['previous_page'] = $context['pagination']['page'] - 1;
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
}
|
|
|
206 |
if($context['pagination']['page'] < $context['pagination']['max_pages']) {
|
|
|
207 |
$context['pagination']['next_page'] = $context['pagination']['page'] + 1;
|
|
|
208 |
|
|
|
209 |
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
foreach($records as $record)
|
|
|
218 |
{
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
if(!$record->courses) {
|
|
|
222 |
continue;
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
foreach($record->courses as $course)
|
|
|
229 |
{
|
|
|
230 |
|
|
|
231 |
$item = [];
|
|
|
232 |
array_push($item, ['value' => $record->lastname ]);
|
|
|
233 |
array_push($item, ['value' => $record->firstname ]);
|
|
|
234 |
|
|
|
235 |
array_push($item, ['value' => $record->email ]);
|
|
|
236 |
array_push($item, ['value' => $course->name ]);
|
|
|
237 |
array_push($item, ['value' => $course->category ]);
|
|
|
238 |
array_push($item, ['value' => empty($course->timeenrolled) ? '' : date('d/m/Y h:i a', $course->timeenrolled)]);
|
|
|
239 |
array_push($item, ['value' => empty($course->timecompleted) ? '' : date('d/m/Y h:i a', $course->timecompleted)]);
|
|
|
240 |
array_push($item, ['value' => $course->activities_assigned, 'align-right' => true ]);
|
|
|
241 |
array_push($item, ['value' => $course->activities_completed, 'align-right' => true ]);
|
|
|
242 |
array_push($item, ['value' => number_format($course->percentage, 2), 'align-right' => true ]);
|
|
|
243 |
array_push($item, ['value' => empty($course->time_activities_first) ? '' : date('d/m/Y h:i a', $course->time_activities_first) ]);
|
|
|
244 |
array_push($item, ['value' => empty($course->time_activities_last) ? '' : date('d/m/Y h:i a', $course->time_activities_last) ]);
|
|
|
245 |
|
|
|
246 |
foreach($extra_fields as $extra_field)
|
|
|
247 |
{
|
|
|
248 |
$value = '';
|
|
|
249 |
|
|
|
250 |
foreach($record->extras as $extra)
|
|
|
251 |
{
|
|
|
252 |
|
|
|
253 |
|
|
|
254 |
if($extra->id == $extra_field->id) {
|
|
|
255 |
$value = $extra->value;
|
|
|
256 |
}
|
|
|
257 |
}
|
|
|
258 |
array_push($item, ['value' => $value ]);
|
|
|
259 |
}
|
|
|
260 |
|
|
|
261 |
array_push($context['items'], ['item' => $item]);
|
|
|
262 |
}
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
|
|
|
266 |
|
|
|
267 |
|
|
|
268 |
|
|
|
269 |
} else if($classname == 'all_courses_with_activities') {
|
|
|
270 |
$PAGE->requires->js(new moodle_url($CFG->wwwroot . '/local/cesa_reportes/js/local_cesa_reportes_all_courses_with_activites.js'));
|
|
|
271 |
|
|
|
272 |
$extra_fields = local_cesa_reportes_get_user_extra_field_names();
|
|
|
273 |
|
|
|
274 |
$context['fields'] = [];
|
|
|
275 |
array_push($context['fields'], ['field' => 'Apellido']);
|
|
|
276 |
array_push($context['fields'], ['field' => 'Nombre']);
|
|
|
277 |
array_push($context['fields'], ['field' => 'Email']);
|
|
|
278 |
array_push($context['fields'], ['field' => 'Curso']);
|
|
|
279 |
array_push($context['fields'], ['field' => 'Categoria']);
|
|
|
280 |
array_push($context['fields'], ['field' => 'Matriculación']);
|
|
|
281 |
array_push($context['fields'], ['field' => 'Fecha finalización']);
|
|
|
282 |
array_push($context['fields'], ['field' => 'Actividades asignadas']);
|
|
|
283 |
array_push($context['fields'], ['field' => 'Actividades completadas']);
|
|
|
284 |
array_push($context['fields'], ['field' => 'Progreso %']);
|
|
|
285 |
array_push($context['fields'], ['field' => 'Primera actividad']);
|
|
|
286 |
array_push($context['fields'], ['field' => 'Ultima actividad']);
|
|
|
287 |
array_push($context['fields'], ['field' => 'Actividad']);
|
|
|
288 |
array_push($context['fields'], ['field' => 'Completado']);
|
|
|
289 |
|
|
|
290 |
|
|
|
291 |
foreach($extra_fields as $extra_field)
|
|
|
292 |
{
|
|
|
293 |
array_push($context['fields'], ['field' => $extra_field->name]);
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
|
|
|
297 |
$context['items'] = [];
|
|
|
298 |
|
|
|
299 |
|
|
|
300 |
$page = $page ? $page : 1;
|
|
|
301 |
$include_modules = true;
|
|
|
302 |
$data = local_cesa_reportes_get_data_for_report_or_excel($filter_by_company_active, $filter_userids, $filter_courseids, $include_modules, $page);
|
|
|
303 |
$records = $data['items'];
|
|
|
304 |
|
|
|
305 |
$context['pagination'] = $data['pagination'];
|
|
|
306 |
if($context['pagination']['page'] > 1) {
|
|
|
307 |
$context['pagination']['previous_page'] = $context['pagination']['page'] - 1;
|
|
|
308 |
|
|
|
309 |
|
|
|
310 |
}
|
|
|
311 |
if($context['pagination']['page'] < $context['pagination']['max_pages']) {
|
|
|
312 |
$context['pagination']['next_page'] = $context['pagination']['page'] + 1;
|
|
|
313 |
|
|
|
314 |
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
|
319 |
foreach($records as $record)
|
|
|
320 |
{
|
|
|
321 |
if(!$record->courses) {
|
|
|
322 |
continue;
|
|
|
323 |
}
|
|
|
324 |
|
|
|
325 |
foreach($record->courses as $course)
|
|
|
326 |
{
|
|
|
327 |
foreach($course->activities as $activity)
|
|
|
328 |
{
|
|
|
329 |
$item = [];
|
|
|
330 |
array_push($item, ['value' => $record->lastname ]);
|
|
|
331 |
array_push($item, ['value' => $record->firstname ]);
|
|
|
332 |
|
|
|
333 |
array_push($item, ['value' => $record->email ]);
|
|
|
334 |
array_push($item, ['value' => $course->name ]);
|
|
|
335 |
array_push($item, ['value' => $course->category ]);
|
|
|
336 |
array_push($item, ['value' => empty($course->timeenrolled) ? '' : date('d/m/Y h:i a', $course->timeenrolled)]);
|
|
|
337 |
array_push($item, ['value' => empty($course->timecompleted) ? '' : date('d/m/Y h:i a', $course->timecompleted)]);
|
|
|
338 |
array_push($item, ['value' => $course->activities_assigned, 'align-right' => true ]);
|
|
|
339 |
array_push($item, ['value' => $course->activities_completed, 'align-right' => true ]);
|
|
|
340 |
array_push($item, ['value' => number_format($course->percentage, 2), 'align-right' => true ]);
|
|
|
341 |
array_push($item, ['value' => empty($course->time_activities_first) ? '' : date('d/m/Y h:i a', $course->time_activities_first) ]);
|
|
|
342 |
array_push($item, ['value' => empty($course->time_activities_last) ? '' : date('d/m/Y h:i a', $course->time_activities_last) ]);
|
|
|
343 |
|
|
|
344 |
|
|
|
345 |
array_push($item, ['value' => $activity->module ]);
|
|
|
346 |
array_push($item, ['value' => empty($activity->timecompleted) ? '' : date('d/m/Y h:i a', $activity->timecompleted) ]);
|
|
|
347 |
|
|
|
348 |
|
|
|
349 |
foreach($extra_fields as $extra_field)
|
|
|
350 |
{
|
|
|
351 |
$value = '';
|
|
|
352 |
|
|
|
353 |
foreach($record->extras as $extra)
|
|
|
354 |
{
|
|
|
355 |
if($extra->id == $extra_field->id) {
|
|
|
356 |
$value = $extra->value;
|
|
|
357 |
}
|
|
|
358 |
}
|
|
|
359 |
array_push($item, ['value' => $value ]);
|
|
|
360 |
}
|
|
|
361 |
|
|
|
362 |
array_push($context['items'], ['item' => $item]);
|
|
|
363 |
}
|
|
|
364 |
}
|
|
|
365 |
}
|
|
|
366 |
} else if($classname == 'all_files') {
|
|
|
367 |
global $DB;
|
|
|
368 |
|
|
|
369 |
//$PAGE->requires->js(new moodle_url($CFG->wwwroot . '/local/cesa_reportes/assets/moment.min.js'));
|
|
|
370 |
$PAGE->requires->js(new moodle_url($CFG->wwwroot . '/local/cesa_reportes/js/local_cesa_reportes_all_files.js'));
|
|
|
371 |
|
|
|
372 |
|
|
|
373 |
$context['items'] = [];
|
|
|
374 |
$context['fields'] = [];
|
|
|
375 |
array_push($context['fields'], ['field' => 'Solicitado el']);
|
|
|
376 |
array_push($context['fields'], ['field' => 'Solictado por']);
|
|
|
377 |
array_push($context['fields'], ['field' => 'Estado']);
|
|
|
378 |
array_push($context['fields'], ['field' => 'Archivo']);
|
|
|
379 |
array_push($context['fields'], ['field' => 'Generado el']);
|
|
|
380 |
|
|
|
381 |
|
|
|
382 |
|
|
|
383 |
|
|
|
384 |
} else if($classname == 'custom') {
|
|
|
385 |
|
|
|
386 |
global $DB;
|
|
|
387 |
$PAGE->requires->css(new moodle_url($CFG->wwwroot . '/local/cesa_reportes/assets/select2.css'));
|
|
|
388 |
$PAGE->requires->js(new moodle_url($CFG->wwwroot . '/local/cesa_reportes/js/local_cesa_reportes_report_custom.js'));
|
|
|
389 |
|
|
|
390 |
$context['courses'] = [];
|
|
|
391 |
|
|
|
392 |
|
|
|
393 |
$sql = 'SELECT id, fullname FROM {course} ';
|
|
|
394 |
|
|
|
395 |
if($filter_by_company_active) {
|
|
|
396 |
$filter_courseids = empty($filter_courseids) ? [-1] : $filter_courseids;
|
|
|
397 |
$sql .= ' WHERE id IN (' . implode(',', $filter_courseids) . ')';
|
|
|
398 |
}
|
|
|
399 |
|
|
|
400 |
$sql .= ' ORDER BY fullname ';
|
|
|
401 |
|
|
|
402 |
|
|
|
403 |
|
|
|
404 |
$records = $DB->get_records_sql($sql);
|
|
|
405 |
foreach($records as $record)
|
|
|
406 |
{
|
|
|
407 |
array_push($context['courses'], [
|
|
|
408 |
'id' => $record->id,
|
|
|
409 |
'name' => $record->fullname
|
|
|
410 |
]) ;
|
|
|
411 |
}
|
|
|
412 |
|
|
|
413 |
|
|
|
414 |
|
|
|
415 |
|
|
|
416 |
$context['filter_from'] = date('Y-m-d', strtotime('-1 Month'));
|
|
|
417 |
$context['filter_to'] = date('Y-m-d', time());
|
|
|
418 |
|
|
|
419 |
|
|
|
420 |
|
|
|
421 |
|
|
|
422 |
|
|
|
423 |
}
|
|
|
424 |
|
|
|
425 |
echo $OUTPUT->header();
|
|
|
426 |
echo $OUTPUT->render_from_template('local_cesa_reportes/form', $context);
|
|
|
427 |
echo $OUTPUT->footer();
|
|
|
428 |
|