1 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
function local_cesa_reportes_get_week_days()
|
|
|
4 |
{
|
|
|
5 |
$data = new \stdClass();
|
|
|
6 |
$data->min = 0;
|
|
|
7 |
$data->max = 0;
|
|
|
8 |
$data->days = [];
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
$dt = new \DateTime();
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
for($i = 0; $i < 7; $i++)
|
|
|
15 |
{
|
|
|
16 |
if($i > 0) {
|
|
|
17 |
$dt->sub(new \DateInterval('P1D'));
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
$dt->setTime(23, 59, 59);
|
|
|
22 |
$max = $dt->getTimestamp();
|
|
|
23 |
|
|
|
24 |
if(!$data->max) {
|
|
|
25 |
$data->max = $max;
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
$dt->setTime(0, 0, 0);
|
|
|
31 |
$min = $dt->getTimestamp();
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
$item = new \stdClass();
|
|
|
35 |
$item->min = $min;
|
|
|
36 |
$item->max = $max;
|
|
|
37 |
$item->day = $dt->format('d/m/Y');
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
array_push($data->days, $item);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
$data->min = $min;
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
return $data;
|
|
|
47 |
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
*
|
|
|
52 |
* @param int $courseid
|
|
|
53 |
* @param int $userid
|
|
|
54 |
* @return int
|
|
|
55 |
*/
|
|
|
56 |
function local_cesa_reportes_get_timecompleted_for_course_and_userid($courseid, $userid)
|
|
|
57 |
{
|
|
|
58 |
global $DB;
|
|
|
59 |
|
|
|
60 |
$sql = 'SELECT COALESCE(timecompleted, 0) AS timecompleted ' .
|
|
|
61 |
' FROM {course_completions} ' .
|
|
|
62 |
' WHERE COURSE = :courseid AND userid = :userid ';
|
|
|
63 |
|
|
|
64 |
return $DB->get_field_sql($sql, ['courseid' => $courseid, 'userid' => $userid]);
|
|
|
65 |
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
*
|
|
|
70 |
* @param int $courseid
|
|
|
71 |
* @param int $userid
|
|
|
72 |
* @param int $from
|
|
|
73 |
* @param int $to
|
|
|
74 |
* @return int
|
|
|
75 |
*/
|
|
|
76 |
function local_cesa_reportes_get_timecompleted_for_course_and_userid_range($courseid, $userid, $from, $to)
|
|
|
77 |
{
|
|
|
78 |
global $DB;
|
|
|
79 |
|
|
|
80 |
$sql = 'SELECT COALESCE(timecompleted, 0) AS timecompleted ' .
|
|
|
81 |
' FROM {course_completions} ' .
|
|
|
82 |
' WHERE COURSE = :courseid AND userid = :userid ' .
|
|
|
83 |
' AND COALESCE(timecompleted, 0) >= :from AND COALESCE(timecompleted, 0) <= :to';
|
|
|
84 |
|
|
|
85 |
return $DB->get_field_sql($sql, ['courseid' => $courseid, 'userid' => $userid, 'from' => $from, 'to' => $to]);
|
|
|
86 |
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
*
|
|
|
93 |
* @param int $from
|
|
|
94 |
* @param int $to
|
|
|
95 |
* @return int[]
|
|
|
96 |
*/
|
|
|
97 |
function local_cesa_reportes_get_course_with_activites_range($from, $to)
|
|
|
98 |
{
|
|
|
99 |
global $DB;
|
|
|
100 |
|
|
|
101 |
$sql = 'SELECT DISTINCT(course) AS course FROM {course_modules} ' .
|
|
|
102 |
' WHERE visible = 1 AND completion > 0 AND deletioninprogress = 0 and added >= :from ' .
|
|
|
103 |
' AND added <= :to';
|
|
|
104 |
|
|
|
105 |
$courses = [];
|
|
|
106 |
$records = $DB->get_records_sql($sql, ['from' => $from, 'to' => $to]);
|
|
|
107 |
foreach($records as $record)
|
|
|
108 |
{
|
|
|
109 |
array_push($courses, $record->course);
|
|
|
110 |
}
|
|
|
111 |
return $courses;
|
|
|
112 |
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
/**
|
|
|
119 |
*
|
|
|
120 |
* @param int $courseid
|
|
|
121 |
* @param int $userid
|
|
|
122 |
* @return int
|
|
|
123 |
*/
|
|
|
124 |
function local_cesa_reportes_get_enroll_for_course_and_userid($courseid, $userid)
|
|
|
125 |
{
|
|
|
126 |
global $DB;
|
|
|
127 |
|
|
|
128 |
$sql = 'SELECT ue.timecreated FROM {user_enrolments} AS ue, {enrol} AS e ' .
|
|
|
129 |
' WHERE ue.enrolid = e.id AND ue.userid = :userid AND e.courseid = :courseid LIMIT 1' ;
|
|
|
130 |
|
|
|
131 |
$timestart = $DB->get_field_sql($sql, ['courseid' => $courseid, 'userid' => $userid]);
|
|
|
132 |
|
|
|
133 |
return $timestart;
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
|
138 |
/**
|
|
|
139 |
*
|
|
|
140 |
* @param int $courseid
|
|
|
141 |
* @param int $from
|
|
|
142 |
* @param int $to
|
|
|
143 |
* @return array
|
|
|
144 |
*/
|
|
|
145 |
function local_cesa_reportes_get_activities_assigned_range($courseid, $from, $to)
|
|
|
146 |
{
|
|
|
147 |
global $DB;
|
|
|
148 |
|
|
|
149 |
$sql = 'SELECT id FROM {course_modules} ' .
|
|
|
150 |
' WHERE course = :courseid AND visible = 1 AND completion > 0 AND deletioninprogress = 0 ' .
|
|
|
151 |
' AND added >= :from AND added <= :to';
|
|
|
152 |
|
|
|
153 |
$ids = [];
|
|
|
154 |
$records = $DB->get_records_sql($sql, ['courseid' => $courseid, 'from' => $from, 'to' => $to ]);
|
|
|
155 |
foreach($records as $record)
|
|
|
156 |
{
|
|
|
157 |
array_push($ids, $record->id);
|
|
|
158 |
}
|
|
|
159 |
return $ids;
|
|
|
160 |
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
/**
|
|
|
164 |
*
|
|
|
165 |
* @param int $courseid
|
|
|
166 |
* @return array
|
|
|
167 |
*/
|
|
|
168 |
function local_cesa_reportes_get_activities_assigned($courseid)
|
|
|
169 |
{
|
|
|
170 |
global $DB;
|
|
|
171 |
|
|
|
172 |
$sql = 'SELECT id FROM {course_modules} ' .
|
|
|
173 |
' WHERE course = :courseid AND visible = 1 AND completion > 0 AND deletioninprogress = 0 ' ;
|
|
|
174 |
|
|
|
175 |
$ids = [];
|
|
|
176 |
$records = $DB->get_records_sql($sql, ['courseid' => $courseid ]);
|
|
|
177 |
foreach($records as $record)
|
|
|
178 |
{
|
|
|
179 |
array_push($ids, $record->id);
|
|
|
180 |
}
|
|
|
181 |
return $ids;
|
|
|
182 |
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
/**
|
|
|
186 |
*
|
|
|
187 |
* @param boolean $filter_by_company_active
|
|
|
188 |
* @param int $start
|
|
|
189 |
* @param int $end
|
|
|
190 |
* @param array $filter_userids
|
|
|
191 |
* @return array
|
|
|
192 |
*/
|
|
|
193 |
function local_cesa_reportes_get_last_ten_user_activities($filter_by_company_active, $filter_userids, $start, $end)
|
|
|
194 |
{
|
|
|
195 |
global $DB;
|
|
|
196 |
|
|
|
197 |
$filterUser = '';
|
|
|
198 |
if($filter_by_company_active) {
|
|
|
199 |
$filter_userids = empty($filter_userids) ? [-1] : $filter_userids;
|
|
|
200 |
$filterUser .= ' AND u.id IN (' . implode(',', $filter_userids) . ')';
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
$sql = <<<EOT
|
|
|
204 |
SELECT l.userid, l.timecreated, u.firstname, u.lastname, u.email, l.courseid, c.fullname as course
|
|
|
205 |
FROM {logstore_standard_log} as l, {user} as u, {course} as c
|
|
|
206 |
WHERE
|
|
|
207 |
l.userid > 1
|
|
|
208 |
AND l.userid = u.id
|
|
|
209 |
AND l.courseid = c.id
|
|
|
210 |
$filterUser
|
|
|
211 |
AND
|
|
|
212 |
l.timecreated >= :start
|
|
|
213 |
AND
|
|
|
214 |
l.timecreated <= :end
|
|
|
215 |
AND
|
|
|
216 |
l.eventname IN (
|
|
|
217 |
'\\\\core\\\\event\\\\course_completed',
|
|
|
218 |
'\\\\core\\\\event\\\\course_viewed',
|
|
|
219 |
'\\\\core\\\\event\\\\course_module_viewed',
|
|
|
220 |
'\\\\mod_book\\\\event\\\\course_module_viewed',
|
|
|
221 |
'\\\\mod_choice\\\\event\\\\course_module_viewed',
|
|
|
222 |
'\\\\mod_customcert\\\\event\\\\course_module_viewed',
|
|
|
223 |
'\\\\mod_data\\\\event\\\\course_module_viewed',
|
|
|
224 |
'\\\\mod_feedback\\\\event\\\\course_module_viewed',
|
|
|
225 |
'\\\\mod_folder\\\\event\\\\course_module_viewed',
|
|
|
226 |
'\\\\mod_forum\\\\event\\\\course_module_viewed',
|
|
|
227 |
'\\\\mod_h5pactivity\\\\event\\\\course_module_viewed',
|
|
|
228 |
'\\\\mod_hvp\\\\event\\\\course_module_viewed',
|
|
|
229 |
'\\\\mod_lesson\\\\event\\\\course_module_viewed',
|
|
|
230 |
'\\\\mod_lti\\\\event\\\\course_module_viewed',
|
|
|
231 |
'\\\\mod_page\\\\event\\\\course_module_viewed',
|
|
|
232 |
'\\\\mod_questionnaire\\\\event\\\\course_module_viewed',
|
|
|
233 |
'\\\\mod_quiz\\\\event\\\\course_module_viewed',
|
|
|
234 |
'\\\\mod_resource\\\\event\\\\course_module_viewed',
|
|
|
235 |
'\\\\mod_scorm\\\\event\\\\course_module_viewed',
|
|
|
236 |
'\\\\mod_subcourse\\\\event\\\\course_module_viewed',
|
|
|
237 |
'\\\\mod_survey\\\\event\\\\course_module_viewed',
|
|
|
238 |
'\\\\mod_url\\\\event\\\\course_module_viewed',
|
|
|
239 |
'\\\\mod_wiki\\\\event\\\\course_module_viewed',
|
|
|
240 |
'\\\\mod_workshop\\\\event\\\\course_module_viewed',
|
|
|
241 |
'\\\\mod_zoom\\\\event\\\\course_module_viewed'
|
|
|
242 |
)
|
|
|
243 |
GROUP BY l.userid
|
|
|
244 |
ORDER BY
|
|
|
245 |
l.timecreated DESC LIMIT 10;
|
|
|
246 |
EOT;
|
|
|
247 |
|
|
|
248 |
$items = [];
|
|
|
249 |
$records = $DB->get_records_sql($sql, ['start' => $start, 'end' => $end]);
|
|
|
250 |
foreach($records as $record)
|
|
|
251 |
{
|
|
|
252 |
$record->timecreated = date('d/m/Y h:i a', $record->timecreated);
|
|
|
253 |
|
|
|
254 |
array_push($items, (array) $record);
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
return $items;
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
|
|
|
261 |
/**
|
|
|
262 |
*
|
|
|
263 |
* @param boolean $filter_by_company_active
|
|
|
264 |
* @param int $start
|
|
|
265 |
* @param int $end
|
|
|
266 |
* @param array $filter_userids
|
|
|
267 |
* @return array
|
|
|
268 |
*/
|
|
|
269 |
function local_cesa_reportes_get_top_ten_user_activities($filter_by_company_active, $filter_userids, $start, $end)
|
|
|
270 |
{
|
|
|
271 |
global $DB;
|
|
|
272 |
|
|
|
273 |
$filterUser = '';
|
|
|
274 |
if($filter_by_company_active) {
|
|
|
275 |
$filter_userids = empty($filter_userids) ? [-1] : $filter_userids;
|
|
|
276 |
$filterUser .= ' AND u.id IN (' . implode(',', $filter_userids) . ')';
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
$sql = <<<EOT
|
|
|
280 |
SELECT l.userid, COUNT(*) AS activities, u.firstname, u.lastname, u.email
|
|
|
281 |
FROM {logstore_standard_log} AS l, {user} AS u
|
|
|
282 |
WHERE
|
|
|
283 |
l.userid = u.id
|
|
|
284 |
AND
|
|
|
285 |
l.userid > 1 $filterUser
|
|
|
286 |
AND
|
|
|
287 |
l.timecreated >= $start
|
|
|
288 |
AND
|
|
|
289 |
l.timecreated <= $end
|
|
|
290 |
AND
|
|
|
291 |
l.eventname IN (
|
|
|
292 |
'\\\\core\\\\event\\\\course_completed',
|
|
|
293 |
'\\\\core\\\\event\\\\course_viewed',
|
|
|
294 |
'\\\\core\\\\event\\\\course_module_viewed',
|
|
|
295 |
'\\\\mod_book\\\\event\\\\course_module_viewed',
|
|
|
296 |
'\\\\mod_choice\\\\event\\\\course_module_viewed',
|
|
|
297 |
'\\\\mod_customcert\\\\event\\\\course_module_viewed',
|
|
|
298 |
'\\\\mod_data\\\\event\\\\course_module_viewed',
|
|
|
299 |
'\\\\mod_feedback\\\\event\\\\course_module_viewed',
|
|
|
300 |
'\\\\mod_folder\\\\event\\\\course_module_viewed',
|
|
|
301 |
'\\\\mod_forum\\\\event\\\\course_module_viewed',
|
|
|
302 |
'\\\\mod_h5pactivity\\\\event\\\\course_module_viewed',
|
|
|
303 |
'\\\\mod_hvp\\\\event\\\\course_module_viewed',
|
|
|
304 |
'\\\\mod_lesson\\\\event\\\\course_module_viewed',
|
|
|
305 |
'\\\\mod_lti\\\\event\\\\course_module_viewed',
|
|
|
306 |
'\\\\mod_page\\\\event\\\\course_module_viewed',
|
|
|
307 |
'\\\\mod_questionnaire\\\\event\\\\course_module_viewed',
|
|
|
308 |
'\\\\mod_quiz\\\\event\\\\course_module_viewed',
|
|
|
309 |
'\\\\mod_resource\\\\event\\\\course_module_viewed',
|
|
|
310 |
'\\\\mod_scorm\\\\event\\\\course_module_viewed',
|
|
|
311 |
'\\\\mod_subcourse\\\\event\\\\course_module_viewed',
|
|
|
312 |
'\\\\mod_survey\\\\event\\\\course_module_viewed',
|
|
|
313 |
'\\\\mod_url\\\\event\\\\course_module_viewed',
|
|
|
314 |
'\\\\mod_wiki\\\\event\\\\course_module_viewed',
|
|
|
315 |
'\\\\mod_workshop\\\\event\\\\course_module_viewed',
|
|
|
316 |
'\\\\mod_zoom\\\\event\\\\course_module_viewed'
|
|
|
317 |
)
|
|
|
318 |
GROUP BY l.userid
|
|
|
319 |
ORDER BY activities DESC LIMIT 10;
|
|
|
320 |
EOT;
|
|
|
321 |
|
|
|
322 |
$items = [];
|
|
|
323 |
$records = $DB->get_records_sql($sql, ['start' => $start, 'end' => $end]);
|
|
|
324 |
foreach($records as $record)
|
|
|
325 |
{
|
|
|
326 |
array_push($items, (array) $record);
|
|
|
327 |
}
|
|
|
328 |
|
|
|
329 |
return $items;
|
|
|
330 |
|
|
|
331 |
}
|
|
|
332 |
|
|
|
333 |
|
|
|
334 |
/**
|
|
|
335 |
*
|
|
|
336 |
* @param boolean $filter_by_company_active
|
|
|
337 |
* @param int $start
|
|
|
338 |
* @param int $end
|
|
|
339 |
* @param array $filter_userids
|
|
|
340 |
* @return int
|
|
|
341 |
*/
|
|
|
342 |
function local_cesa_reportes_get_count_activities($filter_by_company_active, $filter_userids, $start, $end)
|
|
|
343 |
{
|
|
|
344 |
global $DB;
|
|
|
345 |
|
|
|
346 |
$filterUser = '';
|
|
|
347 |
if($filter_by_company_active) {
|
|
|
348 |
$filter_userids = empty($filter_userids) ? [-1] : $filter_userids;
|
|
|
349 |
$filterUser .= ' AND l.userid IN (' . implode(',', $filter_userids) . ')';
|
|
|
350 |
}
|
|
|
351 |
|
|
|
352 |
$sql = <<<EOT
|
|
|
353 |
SELECT COUNT(*) FROM {logstore_standard_log} AS l
|
|
|
354 |
WHERE
|
|
|
355 |
l.userid > 1 $filterUser
|
|
|
356 |
AND
|
|
|
357 |
l.timecreated >= $start
|
|
|
358 |
AND
|
|
|
359 |
l.timecreated <= $end
|
|
|
360 |
AND
|
|
|
361 |
l.eventname IN (
|
|
|
362 |
'\\\\core\\\\event\\\\course_completed',
|
|
|
363 |
'\\\\core\\\\event\\\\course_viewed',
|
|
|
364 |
'\\\\core\\\\event\\\\course_module_viewed',
|
|
|
365 |
'\\\\mod_book\\\\event\\\\course_module_viewed',
|
|
|
366 |
'\\\\mod_choice\\\\event\\\\course_module_viewed',
|
|
|
367 |
'\\\\mod_customcert\\\\event\\\\course_module_viewed',
|
|
|
368 |
'\\\\mod_data\\\\event\\\\course_module_viewed',
|
|
|
369 |
'\\\\mod_feedback\\\\event\\\\course_module_viewed',
|
|
|
370 |
'\\\\mod_folder\\\\event\\\\course_module_viewed',
|
|
|
371 |
'\\\\mod_forum\\\\event\\\\course_module_viewed',
|
|
|
372 |
'\\\\mod_h5pactivity\\\\event\\\\course_module_viewed',
|
|
|
373 |
'\\\\mod_hvp\\\\event\\\\course_module_viewed',
|
|
|
374 |
'\\\\mod_lesson\\\\event\\\\course_module_viewed',
|
|
|
375 |
'\\\\mod_lti\\\\event\\\\course_module_viewed',
|
|
|
376 |
'\\\\mod_page\\\\event\\\\course_module_viewed',
|
|
|
377 |
'\\\\mod_questionnaire\\\\event\\\\course_module_viewed',
|
|
|
378 |
'\\\\mod_quiz\\\\event\\\\course_module_viewed',
|
|
|
379 |
'\\\\mod_resource\\\\event\\\\course_module_viewed',
|
|
|
380 |
'\\\\mod_scorm\\\\event\\\\course_module_viewed',
|
|
|
381 |
'\\\\mod_subcourse\\\\event\\\\course_module_viewed',
|
|
|
382 |
'\\\\mod_survey\\\\event\\\\course_module_viewed',
|
|
|
383 |
'\\\\mod_url\\\\event\\\\course_module_viewed',
|
|
|
384 |
'\\\\mod_wiki\\\\event\\\\course_module_viewed',
|
|
|
385 |
'\\\\mod_workshop\\\\event\\\\course_module_viewed',
|
|
|
386 |
'\\\\mod_zoom\\\\event\\\\course_module_viewed'
|
|
|
387 |
)
|
|
|
388 |
EOT;
|
|
|
389 |
|
|
|
390 |
|
|
|
391 |
return $DB->get_field_sql($sql);
|
|
|
392 |
}
|
|
|
393 |
|
|
|
394 |
|
|
|
395 |
|
|
|
396 |
/**
|
|
|
397 |
*
|
|
|
398 |
* @param boolean $filter_by_company_active
|
|
|
399 |
* @param int $start
|
|
|
400 |
* @param int $end
|
|
|
401 |
* @param array $filter_userids
|
|
|
402 |
* @return int
|
|
|
403 |
*/
|
|
|
404 |
function local_cesa_reportes_get_count_modules_completion($filter_by_company_active, $filter_userids, $start, $end)
|
|
|
405 |
{
|
|
|
406 |
global $DB;
|
|
|
407 |
|
|
|
408 |
$sql = 'SELECT count(*) AS completion ' .
|
|
|
409 |
' FROM {course_modules_completion} AS cmc ' .
|
|
|
410 |
' WHERE cmc.completionstate IN (1,2) '.
|
|
|
411 |
' AND cmc.timemodified >= :start AND cmc.timemodified <= :end ';
|
|
|
412 |
|
|
|
413 |
if($filter_by_company_active) {
|
|
|
414 |
$filter_userids = empty($filter_userids) ? [-1] : $filter_userids;
|
|
|
415 |
$sql .= ' AND cmc.userid IN (' . implode(',', $filter_userids) . ')';
|
|
|
416 |
}
|
|
|
417 |
|
|
|
418 |
|
|
|
419 |
return $DB->get_field_sql($sql, ['start' => $start, 'end' => $end]);
|
|
|
420 |
}
|
|
|
421 |
|
|
|
422 |
|
|
|
423 |
|
|
|
424 |
/**
|
|
|
425 |
*
|
|
|
426 |
* @param boolean $filter_by_company_active
|
|
|
427 |
* @param int $start
|
|
|
428 |
* @param int $end
|
|
|
429 |
* @param array $filter_userids
|
|
|
430 |
* @return array
|
|
|
431 |
*/
|
|
|
432 |
function local_cesa_reportes_get_top_ten_user_modules_completion($filter_by_company_active, $filter_userids, $start, $end)
|
|
|
433 |
{
|
|
|
434 |
global $DB;
|
|
|
435 |
|
|
|
436 |
|
|
|
437 |
|
|
|
438 |
$sql = 'SELECT cmc.userid, count(*) AS completion, u.firstname, u.lastname, u.email ' .
|
|
|
439 |
' FROM {course_modules_completion} AS cmc, {user} AS u ' .
|
|
|
440 |
' WHERE cmc.userid = u.id AND cmc.completionstate IN (1,2) '.
|
|
|
441 |
' AND cmc.timemodified >= :start AND cmc.timemodified <= :end ';
|
|
|
442 |
|
|
|
443 |
if($filter_by_company_active) {
|
|
|
444 |
$filter_userids = empty($filter_userids) ? [-1] : $filter_userids;
|
|
|
445 |
$sql .= ' AND u.id IN (' . implode(',', $filter_userids) . ')';
|
|
|
446 |
}
|
|
|
447 |
|
|
|
448 |
$sql .= ' GROUP BY cmc.userid ' .
|
|
|
449 |
' ORDER BY completion DESC ' .
|
|
|
450 |
' LIMIT 10 ';
|
|
|
451 |
|
|
|
452 |
|
|
|
453 |
$items = [];
|
|
|
454 |
$records = $DB->get_records_sql($sql, ['start' => $start, 'end' => $end]);
|
|
|
455 |
foreach($records as $record)
|
|
|
456 |
{
|
|
|
457 |
array_push($items, (array) $record);
|
|
|
458 |
}
|
|
|
459 |
|
|
|
460 |
return $items;
|
|
|
461 |
|
|
|
462 |
|
|
|
463 |
}
|
|
|
464 |
|
|
|
465 |
/**
|
|
|
466 |
*
|
|
|
467 |
* @param boolean $filter_by_company_active
|
|
|
468 |
* @param int $start
|
|
|
469 |
* @param int $end
|
|
|
470 |
* @param array $filter_userids
|
|
|
471 |
* @return array
|
|
|
472 |
*/
|
|
|
473 |
function local_cesa_reportes_get_last_ten_user_modules_completion($filter_by_company_active, $filter_userids, $start, $end)
|
|
|
474 |
{
|
|
|
475 |
global $DB;
|
|
|
476 |
|
|
|
477 |
/*
|
|
|
478 |
SELECT c.fullname FROM mdl_course_modules_completion as cmc, mdl_course_modules as cm, mdl_course as c
|
|
|
479 |
where cm.id = cmc.coursemoduleid and cm.course = c.id ;
|
|
|
480 |
*/
|
|
|
481 |
|
|
|
482 |
$sql = 'SELECT cmc.userid, cmc.timemodified, u.firstname, u.lastname, u.email, cm.course as courseid, c.fullname as course ' .
|
|
|
483 |
' FROM {course_modules_completion} AS cmc, {user} AS u, {course_modules} AS cm, {course} AS c ' .
|
|
|
484 |
' WHERE cmc.userid = u.id AND completionstate IN (1,2) '.
|
|
|
485 |
' AND cm.id = cmc.coursemoduleid and cm.course = c.id ' .
|
|
|
486 |
' AND cmc.timemodified >= :start AND cmc.timemodified <= :end ';
|
|
|
487 |
|
|
|
488 |
if($filter_by_company_active) {
|
|
|
489 |
$filter_userids = empty($filter_userids) ? [-1] : $filter_userids;
|
|
|
490 |
$sql .= ' AND u.id IN (' . implode(',', $filter_userids) . ')';
|
|
|
491 |
}
|
|
|
492 |
|
|
|
493 |
$sql .= ' GROUP BY cmc.userid ' .
|
|
|
494 |
' ORDER BY cmc.timemodified DESC LIMIT 10 ';
|
|
|
495 |
|
|
|
496 |
|
|
|
497 |
$items = [];
|
|
|
498 |
$records = $DB->get_records_sql($sql, ['start' => $start, 'end' => $end]);
|
|
|
499 |
foreach($records as $record)
|
|
|
500 |
{
|
|
|
501 |
$record->timemodified = date('d/m/Y h:i a', $record->timemodified);
|
|
|
502 |
|
|
|
503 |
array_push($items, (array) $record);
|
|
|
504 |
}
|
|
|
505 |
|
|
|
506 |
return $items;
|
|
|
507 |
}
|
|
|
508 |
|
|
|
509 |
|
|
|
510 |
|
|
|
511 |
/**
|
|
|
512 |
*
|
|
|
513 |
* @param int $courseid
|
|
|
514 |
* @param int $userid
|
|
|
515 |
* @param int $from
|
|
|
516 |
* @param int $to
|
|
|
517 |
* @return array
|
|
|
518 |
*/
|
|
|
519 |
function local_cesa_reportes_get_activities_completed_range($courseid, $userid, $from, $to)
|
|
|
520 |
{
|
|
|
521 |
global $DB;
|
|
|
522 |
|
|
|
523 |
|
|
|
524 |
$sql = 'SELECT cm_i.id, cmc_i.timemodified FROM {course_modules} AS cm_i, ' .
|
|
|
525 |
' {course_modules_completion} AS cmc_i WHERE cmc_i.coursemoduleid = cm_i.id '.
|
|
|
526 |
' AND cm_i.visible = 1 AND cmc_i.completionstate IN (1, 2) ' .
|
|
|
527 |
' AND cm_i.deletioninprogress = 0 AND cm_i.course = :courseid AND cmc_i.userid = :userid ' .
|
|
|
528 |
' AND added >= :from AND added <= :to ' .
|
|
|
529 |
' GROUP BY cm_i.id ';
|
|
|
530 |
|
|
|
531 |
$data = [];
|
|
|
532 |
$records = $DB->get_records_sql($sql, ['courseid' => $courseid, 'userid' => $userid, 'from' => $from, 'to' => $to ]);
|
|
|
533 |
foreach($records as $record)
|
|
|
534 |
{
|
|
|
535 |
$data[$record->id] = $record->timemodified;
|
|
|
536 |
}
|
|
|
537 |
return $data;
|
|
|
538 |
}
|
|
|
539 |
|
|
|
540 |
|
|
|
541 |
|
|
|
542 |
|
|
|
543 |
|
|
|
544 |
/**
|
|
|
545 |
*
|
|
|
546 |
* @param int $courseid
|
|
|
547 |
* @param int $userid
|
|
|
548 |
* @return array
|
|
|
549 |
*/
|
|
|
550 |
function local_cesa_reportes_get_activities_completed($courseid, $userid)
|
|
|
551 |
{
|
|
|
552 |
global $DB;
|
|
|
553 |
|
|
|
554 |
|
|
|
555 |
$sql = 'SELECT cm_i.id, cmc_i.timemodified FROM {course_modules} AS cm_i, ' .
|
|
|
556 |
' {course_modules_completion} AS cmc_i WHERE cmc_i.coursemoduleid = cm_i.id '.
|
|
|
557 |
' AND cm_i.visible = 1 AND cmc_i.completionstate IN (1, 2) ' .
|
|
|
558 |
' AND cm_i.deletioninprogress = 0 AND cm_i.course = :courseid AND cmc_i.userid = :userid ' .
|
|
|
559 |
' GROUP BY cm_i.id ';
|
|
|
560 |
|
|
|
561 |
$data = [];
|
|
|
562 |
$records = $DB->get_records_sql($sql, ['courseid' => $courseid, 'userid' => $userid ]);
|
|
|
563 |
foreach($records as $record)
|
|
|
564 |
{
|
|
|
565 |
$data[$record->id] = $record->timemodified;
|
|
|
566 |
}
|
|
|
567 |
return $data;
|
|
|
568 |
}
|
|
|
569 |
|
|
|
570 |
/**
|
|
|
571 |
*
|
|
|
572 |
* @param int $courseid
|
|
|
573 |
* @return int
|
|
|
574 |
*/
|
|
|
575 |
function local_cesa_reportes_get_num_activities_assigned($courseid)
|
|
|
576 |
{
|
|
|
577 |
global $DB;
|
|
|
578 |
|
|
|
579 |
$sql = 'SELECT COUNT(id) AS modules FROM {course_modules} ' .
|
|
|
580 |
' WHERE course = :courseid AND visible = 1 AND completion > 0 AND deletioninprogress = 0 ' ;
|
|
|
581 |
|
|
|
582 |
return $DB->get_field_sql($sql, ['courseid' => $courseid ]);
|
|
|
583 |
}
|
|
|
584 |
|
|
|
585 |
/**
|
|
|
586 |
*
|
|
|
587 |
* @param int $courseid
|
|
|
588 |
* @param int $userid
|
|
|
589 |
* @return int
|
|
|
590 |
*/
|
|
|
591 |
function local_cesa_reportes_get_num_activities_completed($courseid, $userid)
|
|
|
592 |
{
|
|
|
593 |
global $DB;
|
|
|
594 |
|
|
|
595 |
|
|
|
596 |
$sql = 'SELECT COUNT(DISTINCT(cmc_i.id)) AS completed FROM {course_modules} cm_i, {course_modules_completion} cmc_i ' .
|
|
|
597 |
' WHERE cmc_i.coursemoduleid = cm_i.id AND cm_i.visible = 1 AND cmc_i.completionstate IN (1, 2) ' .
|
|
|
598 |
' AND cm_i.deletioninprogress = 0 AND cm_i.course = :courseid AND cmc_i.userid = :userid ';
|
|
|
599 |
return $DB->get_field_sql($sql, ['courseid' => $courseid, 'userid' => $userid ]);
|
|
|
600 |
}
|
|
|
601 |
|
|
|
602 |
|
|
|
603 |
/**
|
|
|
604 |
*
|
|
|
605 |
* @param int $courseid
|
|
|
606 |
* @param int $from
|
|
|
607 |
* @param int $to
|
|
|
608 |
* @return int
|
|
|
609 |
*/
|
|
|
610 |
function local_cesa_reportes_get_num_activities_assigned_range($courseid, $from, $to)
|
|
|
611 |
{
|
|
|
612 |
global $DB;
|
|
|
613 |
|
|
|
614 |
$sql = 'SELECT COUNT(id) AS modules FROM {course_modules} ' .
|
|
|
615 |
' WHERE course = :courseid AND visible = 1 AND completion > 0 AND deletioninprogress = 0 ' .
|
|
|
616 |
' AND added >= :from AND added <= :to ';
|
|
|
617 |
|
|
|
618 |
return $DB->get_field_sql($sql, ['courseid' => $courseid, 'from' => $from, 'to' => $to ]);
|
|
|
619 |
}
|
|
|
620 |
|
|
|
621 |
/**
|
|
|
622 |
*
|
|
|
623 |
* @param int $courseid
|
|
|
624 |
* @param int $userid
|
|
|
625 |
* @param int $from
|
|
|
626 |
* @param int $to
|
|
|
627 |
* @return int
|
|
|
628 |
*/
|
|
|
629 |
function local_cesa_reportes_get_num_activities_completed_range($courseid, $userid, $from, $to)
|
|
|
630 |
{
|
|
|
631 |
global $DB;
|
|
|
632 |
|
|
|
633 |
|
|
|
634 |
$sql = 'SELECT COUNT(DISTINCT(cmc_i.id)) AS completed FROM {course_modules} cm_i, {course_modules_completion} cmc_i ' .
|
|
|
635 |
' WHERE cmc_i.coursemoduleid = cm_i.id AND cm_i.visible = 1 AND cmc_i.completionstate IN (1, 2) ' .
|
|
|
636 |
' AND cm_i.deletioninprogress = 0 AND cm_i.course = :courseid AND cmc_i.userid = :userid ' .
|
|
|
637 |
' AND cmc_i.timemodified >= :from AND cmc_i.timemodified <= :to';
|
|
|
638 |
return $DB->get_field_sql($sql, ['courseid' => $courseid, 'userid' => $userid, 'from' => $from, 'to' => $to ]);
|
|
|
639 |
}
|
|
|
640 |
|
|
|
641 |
|
|
|
642 |
/**
|
|
|
643 |
*
|
|
|
644 |
* @param int $courseid
|
|
|
645 |
* @param int $userid
|
|
|
646 |
* @param int $from
|
|
|
647 |
* @param int $to
|
|
|
648 |
* @return \stdClass
|
|
|
649 |
*/
|
|
|
650 |
function local_cesa_reportes_get_min_and_max_date_events_range($courseid, $userid, $from, $to)
|
|
|
651 |
{
|
|
|
652 |
global $DB;
|
|
|
653 |
|
|
|
654 |
$sql = <<<EOT
|
|
|
655 |
select
|
|
|
656 |
userid,
|
|
|
657 |
min(timecreated) as min,
|
|
|
658 |
max(timecreated) as max
|
|
|
659 |
from {logstore_standard_log}
|
|
|
660 |
where
|
|
|
661 |
userid = :userid
|
|
|
662 |
and
|
|
|
663 |
courseid = :courseid
|
|
|
664 |
and
|
|
|
665 |
eventname in (
|
|
|
666 |
'\\\\core\\\\event\\\\course_completed',
|
|
|
667 |
'\\\\core\\\\event\\\\course_viewed',
|
|
|
668 |
'\\\\core\\\\event\\\\course_module_viewed',
|
|
|
669 |
'\\\\mod_book\\\\event\\\\course_module_viewed',
|
|
|
670 |
'\\\\mod_choice\\\\event\\\\course_module_viewed',
|
|
|
671 |
'\\\\mod_customcert\\\\event\\\\course_module_viewed',
|
|
|
672 |
'\\\\mod_data\\\\event\\\\course_module_viewed',
|
|
|
673 |
'\\\\mod_feedback\\\\event\\\\course_module_viewed',
|
|
|
674 |
'\\\\mod_folder\\\\event\\\\course_module_viewed',
|
|
|
675 |
'\\\\mod_forum\\\\event\\\\course_module_viewed',
|
|
|
676 |
'\\\\mod_h5pactivity\\\\event\\\\course_module_viewed',
|
|
|
677 |
'\\\\mod_hvp\\\\event\\\\course_module_viewed',
|
|
|
678 |
'\\\\mod_lesson\\\\event\\\\course_module_viewed',
|
|
|
679 |
'\\\\mod_lti\\\\event\\\\course_module_viewed',
|
|
|
680 |
'\\\\mod_page\\\\event\\\\course_module_viewed',
|
|
|
681 |
'\\\\mod_questionnaire\\\\event\\\\course_module_viewed',
|
|
|
682 |
'\\\\mod_quiz\\\\event\\\\course_module_viewed',
|
|
|
683 |
'\\\\mod_resource\\\\event\\\\course_module_viewed',
|
|
|
684 |
'\\\\mod_scorm\\\\event\\\\course_module_viewed',
|
|
|
685 |
'\\\\mod_subcourse\\\\event\\\\course_module_viewed',
|
|
|
686 |
'\\\\mod_survey\\\\event\\\\course_module_viewed',
|
|
|
687 |
'\\\\mod_url\\\\event\\\\course_module_viewed',
|
|
|
688 |
'\\\\mod_wiki\\\\event\\\\course_module_viewed',
|
|
|
689 |
'\\\\mod_workshop\\\\event\\\\course_module_viewed',
|
|
|
690 |
'\\\\mod_zoom\\\\event\\\\course_module_viewed'
|
|
|
691 |
)
|
|
|
692 |
and
|
|
|
693 |
timecreated >= :from
|
|
|
694 |
and
|
|
|
695 |
timecreated <= :to
|
|
|
696 |
group by userid
|
|
|
697 |
|
|
|
698 |
EOT;
|
|
|
699 |
|
|
|
700 |
$data = new \stdClass();
|
|
|
701 |
$data->min = '';
|
|
|
702 |
$data->max = '';
|
|
|
703 |
|
|
|
704 |
$sql = trim($sql);
|
|
|
705 |
$record = $DB->get_record_sql($sql, ['courseid' => $courseid, 'userid' => $userid, 'from' => $from, 'to' => $to]);
|
|
|
706 |
|
|
|
707 |
|
|
|
708 |
|
|
|
709 |
if($record) {
|
|
|
710 |
$data->min = $record->min;
|
|
|
711 |
$data->max = $record->max;
|
|
|
712 |
}
|
|
|
713 |
|
|
|
714 |
|
|
|
715 |
return $data;
|
|
|
716 |
|
|
|
717 |
|
|
|
718 |
}
|
|
|
719 |
|
|
|
720 |
|
|
|
721 |
/**
|
|
|
722 |
*
|
|
|
723 |
* @param int $courseid
|
|
|
724 |
* @param int $userid
|
|
|
725 |
* @return \stdClass
|
|
|
726 |
*/
|
|
|
727 |
function local_cesa_reportes_get_min_and_max_date_events($courseid, $userid)
|
|
|
728 |
{
|
|
|
729 |
global $DB;
|
|
|
730 |
|
|
|
731 |
$sql = <<<EOT
|
|
|
732 |
select
|
|
|
733 |
userid,
|
|
|
734 |
min(timecreated) as min,
|
|
|
735 |
max(timecreated) as max
|
|
|
736 |
from {logstore_standard_log}
|
|
|
737 |
where
|
|
|
738 |
userid = :userid
|
|
|
739 |
and
|
|
|
740 |
courseid = :courseid
|
|
|
741 |
and
|
|
|
742 |
eventname in (
|
|
|
743 |
'\\\\core\\\\event\\\\course_completed',
|
|
|
744 |
'\\\\core\\\\event\\\\course_viewed',
|
|
|
745 |
'\\\\core\\\\event\\\\course_module_viewed',
|
|
|
746 |
'\\\\mod_book\\\\event\\\\course_module_viewed',
|
|
|
747 |
'\\\\mod_choice\\\\event\\\\course_module_viewed',
|
|
|
748 |
'\\\\mod_customcert\\\\event\\\\course_module_viewed',
|
|
|
749 |
'\\\\mod_data\\\\event\\\\course_module_viewed',
|
|
|
750 |
'\\\\mod_feedback\\\\event\\\\course_module_viewed',
|
|
|
751 |
'\\\\mod_folder\\\\event\\\\course_module_viewed',
|
|
|
752 |
'\\\\mod_forum\\\\event\\\\course_module_viewed',
|
|
|
753 |
'\\\\mod_h5pactivity\\\\event\\\\course_module_viewed',
|
|
|
754 |
'\\\\mod_hvp\\\\event\\\\course_module_viewed',
|
|
|
755 |
'\\\\mod_lesson\\\\event\\\\course_module_viewed',
|
|
|
756 |
'\\\\mod_lti\\\\event\\\\course_module_viewed',
|
|
|
757 |
'\\\\mod_page\\\\event\\\\course_module_viewed',
|
|
|
758 |
'\\\\mod_questionnaire\\\\event\\\\course_module_viewed',
|
|
|
759 |
'\\\\mod_quiz\\\\event\\\\course_module_viewed',
|
|
|
760 |
'\\\\mod_resource\\\\event\\\\course_module_viewed',
|
|
|
761 |
'\\\\mod_scorm\\\\event\\\\course_module_viewed',
|
|
|
762 |
'\\\\mod_subcourse\\\\event\\\\course_module_viewed',
|
|
|
763 |
'\\\\mod_survey\\\\event\\\\course_module_viewed',
|
|
|
764 |
'\\\\mod_url\\\\event\\\\course_module_viewed',
|
|
|
765 |
'\\\\mod_wiki\\\\event\\\\course_module_viewed',
|
|
|
766 |
'\\\\mod_workshop\\\\event\\\\course_module_viewed',
|
|
|
767 |
'\\\\mod_zoom\\\\event\\\\course_module_viewed'
|
|
|
768 |
)
|
|
|
769 |
group by userid
|
|
|
770 |
|
|
|
771 |
EOT;
|
|
|
772 |
|
|
|
773 |
$data = new \stdClass();
|
|
|
774 |
$data->min = '';
|
|
|
775 |
$data->max = '';
|
|
|
776 |
|
|
|
777 |
$sql = trim($sql);
|
|
|
778 |
$record = $DB->get_record_sql($sql, ['courseid' => $courseid, 'userid' => $userid]);
|
|
|
779 |
|
|
|
780 |
|
|
|
781 |
|
|
|
782 |
if($record) {
|
|
|
783 |
$data->min = $record->min;
|
|
|
784 |
$data->max = $record->max;
|
|
|
785 |
}
|
|
|
786 |
|
|
|
787 |
|
|
|
788 |
return $data;
|
|
|
789 |
|
|
|
790 |
|
|
|
791 |
}
|
|
|
792 |
|
|
|
793 |
|
|
|
794 |
|
|
|
795 |
/**
|
|
|
796 |
*
|
|
|
797 |
* @param int $userid
|
|
|
798 |
* @return array
|
|
|
799 |
*/
|
|
|
800 |
function local_cesa_reportes_get_user_extra_field_by_userid($userid)
|
|
|
801 |
{
|
|
|
802 |
global $DB;
|
|
|
803 |
|
|
|
804 |
$sql = 'SELECT f.id, f.name AS field, d.data AS value FROM {user_info_data} AS d, {user_info_field} AS f ' .
|
|
|
805 |
' WHERE d.fieldid = f.id AND userid = :userid ORDER BY name' ;
|
|
|
806 |
|
|
|
807 |
|
|
|
808 |
|
|
|
809 |
|
|
|
810 |
return $DB->get_records_sql($sql, ['userid' => $userid]);
|
|
|
811 |
}
|
|
|
812 |
|
|
|
813 |
/**
|
|
|
814 |
*
|
|
|
815 |
* @return array
|
|
|
816 |
*/
|
|
|
817 |
function local_cesa_reportes_get_user_extra_field_names()
|
|
|
818 |
{
|
|
|
819 |
global $DB;
|
|
|
820 |
|
|
|
821 |
$sql = 'SELECT id, name FROM {user_info_field} ORDER BY name' ;
|
|
|
822 |
|
|
|
823 |
|
|
|
824 |
return $DB->get_records_sql($sql);
|
|
|
825 |
}
|
|
|
826 |
|
|
|
827 |
/**
|
|
|
828 |
*
|
|
|
829 |
* @param boolean $filter_by_company_active
|
|
|
830 |
* @param array $filter_userids
|
|
|
831 |
* @param $filter_courseids
|
|
|
832 |
* @param boolean $include_modules
|
|
|
833 |
* @param int $page
|
|
|
834 |
* @return array
|
|
|
835 |
*/
|
|
|
836 |
function local_cesa_reportes_get_data_for_report_or_excel($filter_by_company_active, $filter_userids, $filter_courseids, $include_modules, $page = 0)
|
|
|
837 |
{
|
|
|
838 |
global $DB;
|
|
|
839 |
|
|
|
840 |
|
|
|
841 |
|
|
|
842 |
$sql = ' SELECT u.id AS id, u.firstname, u.lastname, u.email FROM {user} AS u WHERE u.id > 1 AND u.deleted = 0 ' .
|
|
|
843 |
' AND u.suspended = 0 ';
|
|
|
844 |
|
|
|
845 |
|
|
|
846 |
if($filter_by_company_active && $filter_userids) {
|
|
|
847 |
$filter_userids = empty($filter_userids) ? [-1] : $filter_userids;
|
|
|
848 |
$sql .= ' AND u.id IN (' . implode(',', $filter_userids) . ')';
|
|
|
849 |
}
|
|
|
850 |
|
|
|
851 |
$sql .= ' ORDER BY lastname ASC, firstname ASC ';
|
|
|
852 |
|
|
|
853 |
$users = $DB->get_records_sql($sql);
|
|
|
854 |
$max_users = count($users);
|
|
|
855 |
$max_pages = (int) ($max_users / 100);
|
|
|
856 |
if($max_users > ($max_pages * 100) ) {
|
|
|
857 |
$max_pages++;
|
|
|
858 |
}
|
|
|
859 |
|
|
|
860 |
|
|
|
861 |
if($page > 0) {
|
|
|
862 |
|
|
|
863 |
if($page > $max_pages) {
|
|
|
864 |
$page = $max_pages;
|
|
|
865 |
}
|
|
|
866 |
|
|
|
867 |
if($page == 1) {
|
|
|
868 |
$users = array_slice($users, 0, 100);
|
|
|
869 |
} else if($page == $max_pages) {
|
|
|
870 |
$offset = ( $page - 1) * 100;
|
|
|
871 |
$users = array_slice($users, $offset);
|
|
|
872 |
} else {
|
|
|
873 |
$offset = ( $page - 1) * 100;
|
|
|
874 |
$users = array_slice($users, $offset, 100);
|
|
|
875 |
}
|
|
|
876 |
|
|
|
877 |
|
|
|
878 |
}
|
|
|
879 |
|
|
|
880 |
/*
|
|
|
881 |
echo 'page2 = ' . $page . PHP_EOL;
|
|
|
882 |
echo 'max_pages = ' . $max_pages . PHP_EOL;
|
|
|
883 |
echo 'max_users = ' . $max_users . PHP_EOL;
|
|
|
884 |
echo 'current_users = ' . count($users) . PHP_EOL;
|
|
|
885 |
echo '</pre>';
|
|
|
886 |
exit;*/
|
|
|
887 |
|
|
|
888 |
$items = [];
|
|
|
889 |
$categories = [];
|
|
|
890 |
|
|
|
891 |
$courses = [];
|
|
|
892 |
$num_activities_assigned_for_courses = [];
|
|
|
893 |
$modules_for_course = [];
|
|
|
894 |
|
|
|
895 |
|
|
|
896 |
|
|
|
897 |
foreach($users as $user)
|
|
|
898 |
{
|
|
|
899 |
|
|
|
900 |
|
|
|
901 |
$mycourses = enrol_get_users_courses($user->id);
|
|
|
902 |
|
|
|
903 |
|
|
|
904 |
|
|
|
905 |
if(is_array($mycourses)) {
|
|
|
906 |
usort($mycourses, function($a, $b) { return strcasecmp($a->fullname,$b->fullname); });
|
|
|
907 |
}
|
|
|
908 |
|
|
|
909 |
$item = new \stdClass();
|
|
|
910 |
$item->userid = $user->id;
|
|
|
911 |
$item->firstname = $user->firstname;
|
|
|
912 |
$item->lastname = $user->lastname;
|
|
|
913 |
$item->email = $user->email;
|
|
|
914 |
$item->extras = local_cesa_reportes_get_user_extra_field_by_userid($user->id);
|
|
|
915 |
$item->courses = [];
|
|
|
916 |
|
|
|
917 |
|
|
|
918 |
foreach($mycourses as $val)
|
|
|
919 |
{
|
|
|
920 |
|
|
|
921 |
if($filter_by_company_active && $filter_courseids) {
|
|
|
922 |
|
|
|
923 |
if(!in_array($val->id, $filter_courseids)) {
|
|
|
924 |
continue;
|
|
|
925 |
}
|
|
|
926 |
|
|
|
927 |
}
|
|
|
928 |
|
|
|
929 |
if(isset($courses[ $val->id ])) {
|
|
|
930 |
$course = $courses[$val->id];
|
|
|
931 |
} else {
|
|
|
932 |
$course = get_course($val->id);
|
|
|
933 |
|
|
|
934 |
$courses[ $val->id ] = $course;
|
|
|
935 |
}
|
|
|
936 |
|
|
|
937 |
|
|
|
938 |
|
|
|
939 |
|
|
|
940 |
|
|
|
941 |
|
|
|
942 |
|
|
|
943 |
if(isset($num_activities_assigned_for_courses[$course->id])) {
|
|
|
944 |
$num_activities_assigned = $num_activities_assigned_for_courses[$course->id];
|
|
|
945 |
} else {
|
|
|
946 |
$num_activities_assigned = local_cesa_reportes_get_num_activities_assigned($course->id);
|
|
|
947 |
|
|
|
948 |
$num_activities_assigned_for_courses[$course->id] = $num_activities_assigned;
|
|
|
949 |
}
|
|
|
950 |
|
|
|
951 |
|
|
|
952 |
if(isset($categories[ $course->category ])) {
|
|
|
953 |
$category = $categories[ $course->category ];
|
|
|
954 |
} else {
|
|
|
955 |
$category = $DB->get_field('course_categories', 'name', ['id' => $course->category]);
|
|
|
956 |
$categories[ $course->category ] = $category;
|
|
|
957 |
}
|
|
|
958 |
|
|
|
959 |
|
|
|
960 |
|
|
|
961 |
|
|
|
962 |
|
|
|
963 |
$item_course = new \stdClass();
|
|
|
964 |
$item_course->courseid = $course->id;
|
|
|
965 |
$item_course->name = $course->fullname;
|
|
|
966 |
$item_course->category = $category;
|
|
|
967 |
$item_course->percentage = 0;
|
|
|
968 |
$item_course->activities_assigned = $num_activities_assigned;
|
|
|
969 |
$item_course->activities_completed = local_cesa_reportes_get_num_activities_completed($course->id, $user->id);
|
|
|
970 |
|
|
|
971 |
|
|
|
972 |
if($item_course->activities_assigned > 0 && $item_course->activities_completed > 0) {
|
|
|
973 |
$item_course->percentage = ( $item_course->activities_completed * 100 ) / $item_course->activities_assigned;
|
|
|
974 |
|
|
|
975 |
}
|
|
|
976 |
|
|
|
977 |
if($include_modules) {
|
|
|
978 |
|
|
|
979 |
$activities_completed = local_cesa_reportes_get_activities_completed($course->id, $user->id);
|
|
|
980 |
|
|
|
981 |
|
|
|
982 |
if(isset($modules_for_course[ $course->id ])) {
|
|
|
983 |
$modules = $modules_for_course[ $course->id ];
|
|
|
984 |
} else {
|
|
|
985 |
|
|
|
986 |
$modules = [];
|
|
|
987 |
|
|
|
988 |
$records = get_fast_modinfo($val->id)->get_cms();
|
|
|
989 |
foreach($records as $record)
|
|
|
990 |
{
|
|
|
991 |
$modules[ $record->id ] = $record->get_formatted_name();
|
|
|
992 |
}
|
|
|
993 |
|
|
|
994 |
$modules_for_course[ $course->id ] = $modules;
|
|
|
995 |
}
|
|
|
996 |
|
|
|
997 |
|
|
|
998 |
$item_course->activities = [];
|
|
|
999 |
|
|
|
1000 |
$ids = local_cesa_reportes_get_activities_assigned($course->id);
|
|
|
1001 |
foreach($ids as $id)
|
|
|
1002 |
{
|
|
|
1003 |
|
|
|
1004 |
|
|
|
1005 |
if(isset($activities_completed[ $id ])) {
|
|
|
1006 |
$timecompleted = $activities_completed[$id];
|
|
|
1007 |
} else {
|
|
|
1008 |
$timecompleted = 0;
|
|
|
1009 |
}
|
|
|
1010 |
|
|
|
1011 |
$activity = new \stdClass();
|
|
|
1012 |
$activity->module = $modules[$id];
|
|
|
1013 |
$activity->timecompleted = $timecompleted;
|
|
|
1014 |
|
|
|
1015 |
array_push($item_course->activities, $activity);
|
|
|
1016 |
|
|
|
1017 |
|
|
|
1018 |
}
|
|
|
1019 |
}
|
|
|
1020 |
|
|
|
1021 |
$item_course->timeenrolled = local_cesa_reportes_get_enroll_for_course_and_userid($course->id, $user->id);
|
|
|
1022 |
$item_course->timecompleted = local_cesa_reportes_get_timecompleted_for_course_and_userid($course->id, $user->id);
|
|
|
1023 |
|
|
|
1024 |
$min_and_max_date_events = local_cesa_reportes_get_min_and_max_date_events($course->id, $user->id);
|
|
|
1025 |
$item_course->time_activities_first = $min_and_max_date_events->min;
|
|
|
1026 |
$item_course->time_activities_last = $min_and_max_date_events->max;
|
|
|
1027 |
|
|
|
1028 |
/*
|
|
|
1029 |
$completion = new \completion_info($course);
|
|
|
1030 |
if ($completion->is_enabled()) {
|
|
|
1031 |
$item_course->completion_is_enabled = true;
|
|
|
1032 |
$item_course->percentage = \core_completion\progress::get_course_progress_percentage($course, $user->id);
|
|
|
1033 |
$item_course->percentage = !$item_course->percentage ? 0 : $item_course->percentage;
|
|
|
1034 |
} else {
|
|
|
1035 |
$item_course->completion_is_enabled = false;
|
|
|
1036 |
}*/
|
|
|
1037 |
|
|
|
1038 |
|
|
|
1039 |
array_push($item->courses, $item_course);
|
|
|
1040 |
}
|
|
|
1041 |
|
|
|
1042 |
|
|
|
1043 |
array_push($items, $item);
|
|
|
1044 |
}
|
|
|
1045 |
|
|
|
1046 |
return [
|
|
|
1047 |
'pagination' => [
|
|
|
1048 |
'page' => $page,
|
|
|
1049 |
'max_users' => $max_users,
|
|
|
1050 |
'max_pages' => $max_pages
|
|
|
1051 |
],
|
|
|
1052 |
'items' => $items
|
|
|
1053 |
] ;
|
|
|
1054 |
}
|
|
|
1055 |
|
|
|
1056 |
|
|
|
1057 |
/**
|
|
|
1058 |
*
|
|
|
1059 |
* @param boolean $filter_by_company_active
|
|
|
1060 |
* @param array $filter_userids
|
|
|
1061 |
* @param array $filter_courseids
|
|
|
1062 |
* @param string $filter_userkeyword
|
|
|
1063 |
* @param string $filter_from
|
|
|
1064 |
* @param string $filter_to,
|
|
|
1065 |
* @param boolean $include_modules
|
|
|
1066 |
* @param int $page
|
|
|
1067 |
* @return array
|
|
|
1068 |
*/
|
|
|
1069 |
function local_cesa_reportes_get_data_for_report_or_excel_custom($filter_by_company_active, $filter_userids, $filter_courseids, $filter_userkeyword, $filter_from, $filter_to, $include_modules, $page = 0)
|
|
|
1070 |
{
|
|
|
1071 |
global $DB;
|
|
|
1072 |
|
|
|
1073 |
|
|
|
1074 |
|
|
|
1075 |
$sql = ' SELECT u.id AS id, u.firstname, u.lastname, u.email FROM {user} AS u WHERE u.id > 1 AND u.deleted = 0 ' .
|
|
|
1076 |
' AND u.suspended = 0 ';
|
|
|
1077 |
|
|
|
1078 |
if($filter_userkeyword) {
|
|
|
1079 |
$sql .= " AND ( u.firstname like '%$filter_userkeyword%' OR u.lastname like '%$filter_userkeyword%' OR u.email like '%$filter_userkeyword%' ) " ;
|
|
|
1080 |
}
|
|
|
1081 |
|
|
|
1082 |
|
|
|
1083 |
if($filter_by_company_active && $filter_userids) {
|
|
|
1084 |
$filter_userids = empty($filter_userids) ? [-1] : $filter_userids;
|
|
|
1085 |
$sql .= ' AND u.id IN (' . implode(',', $filter_userids) . ')';
|
|
|
1086 |
}
|
|
|
1087 |
|
|
|
1088 |
$sql .= ' ORDER BY lastname ASC, firstname ASC ';
|
|
|
1089 |
|
|
|
1090 |
$users = $DB->get_records_sql($sql);
|
|
|
1091 |
$max_users = count($users);
|
|
|
1092 |
$max_pages = (int) ($max_users / 100);
|
|
|
1093 |
if($max_users > ($max_pages * 100) ) {
|
|
|
1094 |
$max_pages++;
|
|
|
1095 |
}
|
|
|
1096 |
|
|
|
1097 |
|
|
|
1098 |
if($page > 0) {
|
|
|
1099 |
|
|
|
1100 |
if($page > $max_pages) {
|
|
|
1101 |
$page = $max_pages;
|
|
|
1102 |
}
|
|
|
1103 |
|
|
|
1104 |
if($page == 1) {
|
|
|
1105 |
$users = array_slice($users, 0, 100);
|
|
|
1106 |
} else if($page == $max_pages) {
|
|
|
1107 |
$offset = ( $page - 1) * 100;
|
|
|
1108 |
$users = array_slice($users, $offset);
|
|
|
1109 |
} else {
|
|
|
1110 |
$offset = ( $page - 1) * 100;
|
|
|
1111 |
$users = array_slice($users, $offset, 100);
|
|
|
1112 |
}
|
|
|
1113 |
|
|
|
1114 |
|
|
|
1115 |
}
|
|
|
1116 |
|
|
|
1117 |
/*
|
|
|
1118 |
echo 'page2 = ' . $page . PHP_EOL;
|
|
|
1119 |
echo 'max_pages = ' . $max_pages . PHP_EOL;
|
|
|
1120 |
echo 'max_users = ' . $max_users . PHP_EOL;
|
|
|
1121 |
echo 'current_users = ' . count($users) . PHP_EOL;
|
|
|
1122 |
echo '</pre>';
|
|
|
1123 |
exit;*/
|
|
|
1124 |
|
|
|
1125 |
$items = [];
|
|
|
1126 |
$categories = [];
|
|
|
1127 |
|
|
|
1128 |
$courses = [];
|
|
|
1129 |
$num_activities_assigned_for_range = [];
|
|
|
1130 |
$num_activities_assigned_for_course = [];
|
|
|
1131 |
|
|
|
1132 |
$modules_for_course = [];
|
|
|
1133 |
|
|
|
1134 |
|
|
|
1135 |
|
|
|
1136 |
foreach($users as $user)
|
|
|
1137 |
{
|
|
|
1138 |
|
|
|
1139 |
|
|
|
1140 |
$mycourses = enrol_get_users_courses($user->id);
|
|
|
1141 |
|
|
|
1142 |
|
|
|
1143 |
|
|
|
1144 |
if(is_array($mycourses)) {
|
|
|
1145 |
usort($mycourses, function($a, $b) { return strcasecmp($a->fullname,$b->fullname); });
|
|
|
1146 |
}
|
|
|
1147 |
|
|
|
1148 |
$item = new \stdClass();
|
|
|
1149 |
$item->userid = $user->id;
|
|
|
1150 |
$item->firstname = $user->firstname;
|
|
|
1151 |
$item->lastname = $user->lastname;
|
|
|
1152 |
$item->email = $user->email;
|
|
|
1153 |
$item->extras = local_cesa_reportes_get_user_extra_field_by_userid($user->id);
|
|
|
1154 |
$item->courses = [];
|
|
|
1155 |
|
|
|
1156 |
|
|
|
1157 |
foreach($mycourses as $val)
|
|
|
1158 |
{
|
|
|
1159 |
|
|
|
1160 |
if($filter_by_company_active && $filter_courseids) {
|
|
|
1161 |
|
|
|
1162 |
if(!in_array($val->id, $filter_courseids)) {
|
|
|
1163 |
continue;
|
|
|
1164 |
}
|
|
|
1165 |
|
|
|
1166 |
}
|
|
|
1167 |
|
|
|
1168 |
if(isset($courses[ $val->id ])) {
|
|
|
1169 |
$course = $courses[$val->id];
|
|
|
1170 |
} else {
|
|
|
1171 |
$course = get_course($val->id);
|
|
|
1172 |
|
|
|
1173 |
$courses[ $val->id ] = $course;
|
|
|
1174 |
}
|
|
|
1175 |
|
|
|
1176 |
|
|
|
1177 |
|
|
|
1178 |
|
|
|
1179 |
if(isset($num_activities_assigned_for_range[$course->id])) {
|
|
|
1180 |
$num_activities_assigned = $num_activities_assigned_for_range[$course->id];
|
|
|
1181 |
} else {
|
|
|
1182 |
$num_activities_assigned = local_cesa_reportes_get_num_activities_assigned_range($course->id, $filter_from, $filter_to);
|
|
|
1183 |
|
|
|
1184 |
$num_activities_assigned_for_range[$course->id] = $num_activities_assigned;
|
|
|
1185 |
}
|
|
|
1186 |
|
|
|
1187 |
if(isset($num_activities_assigned_for_course[$course->id])) {
|
|
|
1188 |
$num_activities_assigned_course = $num_activities_assigned_for_course[$course->id];
|
|
|
1189 |
} else {
|
|
|
1190 |
$num_activities_assigned_course = local_cesa_reportes_get_num_activities_assigned($course->id);
|
|
|
1191 |
|
|
|
1192 |
$num_activities_assigned_for_course[$course->id] = $num_activities_assigned;
|
|
|
1193 |
}
|
|
|
1194 |
|
|
|
1195 |
if(isset($categories[ $course->category ])) {
|
|
|
1196 |
$category = $categories[ $course->category ];
|
|
|
1197 |
} else {
|
|
|
1198 |
$category = $DB->get_field('course_categories', 'name', ['id' => $course->category]);
|
|
|
1199 |
$categories[ $course->category ] = $category;
|
|
|
1200 |
}
|
|
|
1201 |
|
|
|
1202 |
|
|
|
1203 |
|
|
|
1204 |
|
|
|
1205 |
|
|
|
1206 |
$item_course = new \stdClass();
|
|
|
1207 |
$item_course->courseid = $course->id;
|
|
|
1208 |
$item_course->name = $course->fullname;
|
|
|
1209 |
$item_course->category = $category;
|
|
|
1210 |
$item_course->percentage = 0;
|
|
|
1211 |
$item_course->activities_assigned = $num_activities_assigned;
|
|
|
1212 |
$item_course->activities_completed = local_cesa_reportes_get_num_activities_completed_range($course->id, $user->id, $filter_from, $filter_to);
|
|
|
1213 |
|
|
|
1214 |
|
|
|
1215 |
|
|
|
1216 |
if($item_course->activities_assigned > 0 && $item_course->activities_completed > 0) {
|
|
|
1217 |
$item_course->percentage = ( $item_course->activities_completed * 100 ) / $item_course->activities_assigned;
|
|
|
1218 |
|
|
|
1219 |
}
|
|
|
1220 |
|
|
|
1221 |
$item_course->percentage_course = 0;
|
|
|
1222 |
$item_course->activities_assigned_course = $num_activities_assigned_course;
|
|
|
1223 |
$item_course->activities_completed_course = local_cesa_reportes_get_num_activities_completed($course->id, $user->id);
|
|
|
1224 |
|
|
|
1225 |
|
|
|
1226 |
|
|
|
1227 |
if($item_course->activities_assigned_course > 0 && $item_course->activities_completed_course > 0) {
|
|
|
1228 |
$item_course->percentage_course = ( $item_course->activities_completed_course * 100 ) / $item_course->activities_assigned_course;
|
|
|
1229 |
|
|
|
1230 |
}
|
|
|
1231 |
|
|
|
1232 |
if($include_modules) {
|
|
|
1233 |
|
|
|
1234 |
$activities_completed = local_cesa_reportes_get_activities_completed_range($course->id, $user->id, $filter_from, $filter_to);
|
|
|
1235 |
|
|
|
1236 |
if(isset($modules_for_course[ $course->id ])) {
|
|
|
1237 |
$modules = $modules_for_course[ $course->id ];
|
|
|
1238 |
} else {
|
|
|
1239 |
|
|
|
1240 |
$modules = [];
|
|
|
1241 |
|
|
|
1242 |
$records = get_fast_modinfo($val->id)->get_cms();
|
|
|
1243 |
foreach($records as $record)
|
|
|
1244 |
{
|
|
|
1245 |
$modules[ $record->id ] = $record->get_formatted_name();
|
|
|
1246 |
}
|
|
|
1247 |
|
|
|
1248 |
$modules_for_course[ $course->id ] = $modules;
|
|
|
1249 |
}
|
|
|
1250 |
|
|
|
1251 |
|
|
|
1252 |
$item_course->activities = [];
|
|
|
1253 |
|
|
|
1254 |
$ids = local_cesa_reportes_get_activities_assigned_range($course->id, $filter_from, $filter_to);
|
|
|
1255 |
foreach($ids as $id)
|
|
|
1256 |
{
|
|
|
1257 |
|
|
|
1258 |
|
|
|
1259 |
if(isset($activities_completed[ $id ])) {
|
|
|
1260 |
$timecompleted = $activities_completed[$id];
|
|
|
1261 |
} else {
|
|
|
1262 |
$timecompleted = 0;
|
|
|
1263 |
}
|
|
|
1264 |
|
|
|
1265 |
$activity = new \stdClass();
|
|
|
1266 |
$activity->module = $modules[$id];
|
|
|
1267 |
$activity->timecompleted = $timecompleted;
|
|
|
1268 |
|
|
|
1269 |
array_push($item_course->activities, $activity);
|
|
|
1270 |
|
|
|
1271 |
|
|
|
1272 |
}
|
|
|
1273 |
}
|
|
|
1274 |
|
|
|
1275 |
$item_course->timeenrolled = local_cesa_reportes_get_enroll_for_course_and_userid($course->id, $user->id);
|
|
|
1276 |
$item_course->timecompleted = local_cesa_reportes_get_timecompleted_for_course_and_userid_range($course->id, $user->id, $filter_from, $filter_to);
|
|
|
1277 |
$item_course->timecompleted_course = local_cesa_reportes_get_timecompleted_for_course_and_userid($course->id, $user->id);
|
|
|
1278 |
|
|
|
1279 |
|
|
|
1280 |
|
|
|
1281 |
$min_and_max_date_events = local_cesa_reportes_get_min_and_max_date_events_range($course->id, $user->id, $filter_from, $filter_to);
|
|
|
1282 |
$item_course->time_activities_first = $min_and_max_date_events->min;
|
|
|
1283 |
$item_course->time_activities_last = $min_and_max_date_events->max;
|
|
|
1284 |
|
|
|
1285 |
|
|
|
1286 |
$min_and_max_date_events = local_cesa_reportes_get_min_and_max_date_events($course->id, $user->id);
|
|
|
1287 |
$item_course->time_activities_first_course = $min_and_max_date_events->min;
|
|
|
1288 |
$item_course->time_activities_last_course = $min_and_max_date_events->max;
|
|
|
1289 |
|
|
|
1290 |
/*
|
|
|
1291 |
$completion = new \completion_info($course);
|
|
|
1292 |
if ($completion->is_enabled()) {
|
|
|
1293 |
$item_course->completion_is_enabled = true;
|
|
|
1294 |
$item_course->percentage = \core_completion\progress::get_course_progress_percentage($course, $user->id);
|
|
|
1295 |
$item_course->percentage = !$item_course->percentage ? 0 : $item_course->percentage;
|
|
|
1296 |
} else {
|
|
|
1297 |
$item_course->completion_is_enabled = false;
|
|
|
1298 |
}*/
|
|
|
1299 |
|
|
|
1300 |
|
|
|
1301 |
array_push($item->courses, $item_course);
|
|
|
1302 |
}
|
|
|
1303 |
|
|
|
1304 |
|
|
|
1305 |
array_push($items, $item);
|
|
|
1306 |
}
|
|
|
1307 |
|
|
|
1308 |
return [
|
|
|
1309 |
'pagination' => [
|
|
|
1310 |
'page' => $page,
|
|
|
1311 |
'max_users' => $max_users,
|
|
|
1312 |
'max_pages' => $max_pages
|
|
|
1313 |
],
|
|
|
1314 |
'items' => $items
|
|
|
1315 |
] ;
|
|
|
1316 |
}
|