1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
4
|
|
|
|
5
|
|
|
use Chamilo\CoreBundle\Framework\Container; |
6
|
|
|
use Chamilo\CourseBundle\Entity\CQuiz; |
7
|
|
|
use Chamilo\CoreBundle\Component\Utils\ActionIcon; |
8
|
|
|
use Chamilo\CoreBundle\Component\Utils\ToolIcon; |
9
|
|
|
use Chamilo\CoreBundle\Component\Utils\ObjectIcon; |
10
|
|
|
|
11
|
|
|
require_once __DIR__.'/../inc/global.inc.php'; |
12
|
|
|
|
13
|
|
|
$toolTable = Database::get_course_table(TABLE_TOOL_LIST); |
14
|
|
|
$quizTable = Database::get_course_table(TABLE_QUIZ_TEST); |
15
|
|
|
|
16
|
|
|
$this_section = SECTION_TRACKING; |
17
|
|
|
$is_allowedToTrack = api_is_course_admin() || api_is_platform_admin(true) || api_is_session_general_coach(); |
18
|
|
|
|
19
|
|
|
if (!$is_allowedToTrack) { |
20
|
|
|
api_not_allowed(true); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
$exportToXLS = false; |
24
|
|
|
if (isset($_GET['export'])) { |
25
|
|
|
$exportToXLS = true; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$courseInfo = api_get_course_info(); |
29
|
|
|
|
30
|
|
|
$global = false; |
31
|
|
|
if (api_is_platform_admin() && empty($_GET['cidReq'])) { |
32
|
|
|
$global = true; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$courseList = []; |
36
|
|
|
if ($global) { |
37
|
|
|
$temp = CourseManager::get_courses_list(); |
38
|
|
|
foreach ($temp as $tempCourse) { |
39
|
|
|
$courseList[] = api_get_course_entity($tempCourse['real_id']); |
40
|
|
|
} |
41
|
|
|
} else { |
42
|
|
|
$courseList = [api_get_course_entity()]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$sessionId = api_get_session_id(); |
46
|
|
|
|
47
|
|
|
if (empty($sessionId)) { |
48
|
|
|
$sessionCondition = ' AND session_id = 0'; |
49
|
|
|
} else { |
50
|
|
|
$sessionCondition = api_get_session_condition($sessionId, true, true); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$form = new FormValidator( |
54
|
|
|
'search_simple', |
55
|
|
|
'POST', |
56
|
|
|
api_get_self().'?'.api_get_cidreq(), |
57
|
|
|
'', |
58
|
|
|
null, |
59
|
|
|
false |
60
|
|
|
); |
61
|
|
|
$form->addElement('number', 'score', get_lang('Percentage')); |
62
|
|
|
if ($global) { |
63
|
|
|
$form->addElement('hidden', 'view', 'admin'); |
64
|
|
|
} else { |
65
|
|
|
// Get exam lists |
66
|
|
|
$courseId = api_get_course_int_id(); |
67
|
|
|
|
68
|
|
|
$sql = "SELECT quiz.title, iid FROM $quizTable AS quiz |
69
|
|
|
WHERE |
70
|
|
|
c_id = $courseId AND |
71
|
|
|
active = 1 |
72
|
|
|
$sessionCondition |
73
|
|
|
ORDER BY quiz.title ASC"; |
74
|
|
|
$result = Database::query($sql); |
75
|
|
|
// Only show select bar if there is more than one test |
76
|
|
|
if (Database::num_rows($result) > 0) { |
77
|
|
|
$exerciseList = [get_lang('All')]; |
78
|
|
|
while ($row = Database::fetch_array($result)) { |
79
|
|
|
$exerciseList[$row['id']] = $row['title']; |
80
|
|
|
} |
81
|
|
|
$form->addSelect('exercise_id', get_lang('Exercise'), $exerciseList); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$form->addButton( |
86
|
|
|
'filter', |
87
|
|
|
get_lang('Filter'), |
88
|
|
|
'filter', |
89
|
|
|
'primary', |
90
|
|
|
null, |
91
|
|
|
null, |
92
|
|
|
['style' => 'margin-top: 5px; margin-left: 15px;'] |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
$filter_score = isset($_REQUEST['score']) ? intval($_REQUEST['score']) : 70; |
96
|
|
|
$exerciseId = isset($_REQUEST['exercise_id']) ? intval($_REQUEST['exercise_id']) : 0; |
97
|
|
|
|
98
|
|
|
$form->setDefaults(['score' => $filter_score]); |
99
|
|
|
|
100
|
|
|
if (!$exportToXLS) { |
101
|
|
|
Display:: display_header(get_lang('Reporting')); |
102
|
|
|
$actionsLeft = $actionsRight = ''; |
103
|
|
|
if ($global) { |
104
|
|
|
$actionsLeft .= '<a href="'.api_get_path(WEB_CODE_PATH).'auth/my_progress.php">'. |
105
|
|
|
Display::getMdiIcon(ToolIcon::TRACKING, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('View my progress')); |
106
|
|
|
$actionsLeft .= '</a>'; |
107
|
|
|
|
108
|
|
|
$actionsRight .= '<a href="'.api_get_self().'?export=1&score='.$filter_score.'&exercise_id='.$exerciseId.'">'. |
109
|
|
|
Display::getMdiIcon(ActionIcon::EXPORT_SPREADSHEET, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Excel export')).'</a>'; |
110
|
|
|
$actionsRight .= '<a href="javascript: void(0);" onclick="javascript: window.print()">'. |
111
|
|
|
Display::getMdiIcon(ActionIcon::PRINT, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Print')).'</a>'; |
112
|
|
|
|
113
|
|
|
$menuItems[] = Display::url( |
114
|
|
|
Display::getMdiIcon(ObjectIcon::TEACHER, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Trainer View')), |
115
|
|
|
api_get_path(WEB_CODE_PATH).'my_space/index.php?view=teacher' |
116
|
|
|
); |
117
|
|
|
if (api_is_platform_admin()) { |
118
|
|
|
$menuItems[] = Display::url( |
119
|
|
|
Display::getMdiIcon(ObjectIcon::STAR, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Admin view')), |
120
|
|
|
api_get_path(WEB_CODE_PATH).'my_space/admin_view.php' |
121
|
|
|
); |
122
|
|
|
} else { |
123
|
|
|
$menuItems[] = Display::url( |
124
|
|
|
Display::getMdiIcon(ObjectIcon::STAR, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Coach interface')), |
125
|
|
|
api_get_path(WEB_CODE_PATH).'my_space/index.php?view=coach' |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
$menuItems[] = '<a href="#">'.Display::getMdiIcon(ToolIcon::QUIZ, 'ch-tool-icon-disabled', null, ICON_SIZE_MEDIUM, get_lang('Exam tracking')).'</a>'; |
129
|
|
|
|
130
|
|
|
$nb_menu_items = count($menuItems); |
131
|
|
|
if ($nb_menu_items > 1) { |
132
|
|
|
foreach ($menuItems as $key => $item) { |
133
|
|
|
$actionsLeft .= $item; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
$actionsLeft = TrackingCourseLog::actionsLeft('exams', $sessionId, false); |
137
|
|
|
} else { |
138
|
|
|
$actionsLeft = TrackingCourseLog::actionsLeft('exams', api_get_session_id(), false); |
139
|
|
|
$actionsRight .= Display::url( |
140
|
|
|
Display::getMdiIcon(ActionIcon::EXPORT_SPREADSHEET, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Excel export')), |
141
|
|
|
api_get_self().'?'.api_get_cidreq().'&export=1&score='.$filter_score.'&exercise_id='.$exerciseId |
142
|
|
|
); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
$toolbar = Display::toolbarAction('toolbar-exams', [$actionsLeft, $actionsRight]); |
146
|
|
|
echo $toolbar; |
147
|
|
|
|
148
|
|
|
$form->display(); |
149
|
|
|
echo '<h3>'.sprintf(get_lang('Filtering with score %s'), $filter_score).'%</h3>'; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
$html = '<div class="table-responsive">'; |
153
|
|
|
$html .= '<table class="table table-hover table-striped data_table">'; |
154
|
|
|
if ($global) { |
155
|
|
|
$html .= '<tr>'; |
156
|
|
|
$html .= '<th>'.get_lang('Courses').'</th>'; |
157
|
|
|
$html .= '<th>'.get_lang('Tests').'</th>'; |
158
|
|
|
$html .= '<th>'.get_lang('Taken').'</th>'; |
159
|
|
|
$html .= '<th>'.get_lang('Not taken').'</th>'; |
160
|
|
|
$html .= '<th>'.sprintf(get_lang('Pass minimum %s'), $filter_score).'%</th>'; |
161
|
|
|
$html .= '<th>'.get_lang('Fail').'</th>'; |
162
|
|
|
$html .= '<th>'.get_lang('Total learners').'</th>'; |
163
|
|
|
$html .= '</tr>'; |
164
|
|
|
} else { |
165
|
|
|
$html .= '<tr>'; |
166
|
|
|
$html .= '<th>'.get_lang('Tests').'</th>'; |
167
|
|
|
$html .= '<th>'.get_lang('User').'</th>'; |
168
|
|
|
$html .= '<th>'.get_lang('Username').'</th>'; |
169
|
|
|
//$html .= '<th>'.sprintf(get_lang('Pass minimum %s'), $filter_score).'</th>'; |
170
|
|
|
$html .= '<th>'.get_lang('Percentage').' %</th>'; |
171
|
|
|
$html .= '<th>'.get_lang('Status').'</th>'; |
172
|
|
|
$html .= '<th>'.get_lang('Attempts').'</th>'; |
173
|
|
|
$html .= '</tr>'; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
$export_array_global = $export_array = []; |
177
|
|
|
$s_css_class = null; |
178
|
|
|
|
179
|
|
|
if (!empty($courseList)) { |
180
|
|
|
$quizRepo = Container::getQuizRepository(); |
181
|
|
|
foreach ($courseList as $course) { |
182
|
|
|
$courseId = $course->getId(); |
183
|
|
|
$sessionList = SessionManager::get_session_by_course($courseId); |
184
|
|
|
|
185
|
|
|
$newSessionList = []; |
186
|
|
|
if (!empty($sessionList)) { |
187
|
|
|
foreach ($sessionList as $session) { |
188
|
|
|
$newSessionList[$session['id']] = $session['title']; |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
if ($global) { |
193
|
|
|
$qb = $quizRepo->getResourcesByCourse($course); |
194
|
|
|
$qb->select('count(resource)'); |
195
|
|
|
|
196
|
|
|
$exerciseCount = $qb->getQuery()->getSingleScalarResult(); |
197
|
|
|
|
198
|
|
|
/*$sql = "SELECT count(iid) as count |
199
|
|
|
FROM $quizTable AS quiz |
200
|
|
|
WHERE c_id = $courseId AND active = 1 AND (session_id = 0 OR session_id IS NULL)"; |
201
|
|
|
$result = Database::query($sql); |
202
|
|
|
$countExercises = Database::store_result($result); |
203
|
|
|
$exerciseCount = $countExercises[0]['count'];*/ |
204
|
|
|
|
205
|
|
|
$qb = $quizRepo->getResourcesByCourse($course); |
206
|
|
|
$qb->select('count(resource)'); |
207
|
|
|
$qb->andWhere('links.session IS NOT NULL'); |
208
|
|
|
|
209
|
|
|
$exerciseSessionCount = $qb->getQuery()->getSingleScalarResult(); |
210
|
|
|
|
211
|
|
|
/*$sql = "SELECT count(iid) as count |
212
|
|
|
FROM $quizTable AS quiz |
213
|
|
|
WHERE c_id = $courseId AND active = 1 AND session_id <> 0"; |
214
|
|
|
$result = Database::query($sql); |
215
|
|
|
$countExercises = Database::store_result($result); |
216
|
|
|
$exerciseSessionCount = $countExercises[0]['count'];*/ |
217
|
|
|
|
218
|
|
|
$exerciseCount = $exerciseCount + $exerciseCount * count($newSessionList) + $exerciseSessionCount; |
219
|
|
|
|
220
|
|
|
// Add course and session list. |
221
|
|
|
if (0 == $exerciseCount) { |
222
|
|
|
$exerciseCount = 2; |
223
|
|
|
} |
224
|
|
|
$html .= "<tr> |
225
|
|
|
<td rowspan=$exerciseCount>"; |
226
|
|
|
$html .= $course->getTitle(); |
227
|
|
|
$html .= "</td>"; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
$sql = "SELECT visibility FROM $toolTable |
231
|
|
|
WHERE c_id = $courseId AND title = 'quiz'"; |
232
|
|
|
$result = Database::query($sql); |
233
|
|
|
|
234
|
|
|
// If main tool is visible. |
235
|
|
|
if (1 == Database::result($result, 0, 'visibility')) { |
236
|
|
|
$exercises = []; |
237
|
|
|
// Getting the exam list. |
238
|
|
|
if ($global) { |
239
|
|
|
$qb = $quizRepo->getResourcesByCourse($course); |
240
|
|
|
$exercises = $qb->getQuery()->getResult(); |
241
|
|
|
/*$sql = "SELECT quiz.title, iid, session_id |
242
|
|
|
FROM $quizTable AS quiz |
243
|
|
|
WHERE c_id = $courseId AND active = 1 |
244
|
|
|
ORDER BY session_id, quiz.title ASC";*/ |
245
|
|
|
} else { |
246
|
|
|
//$sessionCondition = api_get_session_condition($sessionId, true, false); |
247
|
|
|
if (!empty($exerciseId)) { |
248
|
|
|
$exercises = []; |
249
|
|
|
$exercises[] = $quizRepo->find($exerciseId); |
250
|
|
|
/* |
251
|
|
|
$sql = "SELECT quiz.title, iid, session_id |
252
|
|
|
FROM $quizTable AS quiz |
253
|
|
|
WHERE |
254
|
|
|
c_id = $courseId AND |
255
|
|
|
active = 1 AND |
256
|
|
|
id = $exerciseId |
257
|
|
|
$sessionCondition |
258
|
|
|
ORDER BY session_id, quiz.title ASC"; |
259
|
|
|
*/ |
260
|
|
|
} else { |
261
|
|
|
$qb = $quizRepo->getResourcesByCourse($course, api_get_session_entity()); |
262
|
|
|
$exercises = $qb->getQuery()->getResult(); |
263
|
|
|
/* |
264
|
|
|
$sql = "SELECT quiz.title, iid, session_id |
265
|
|
|
FROM $quizTable AS quiz |
266
|
|
|
WHERE |
267
|
|
|
c_id = $courseId AND |
268
|
|
|
active = 1 |
269
|
|
|
$sessionCondition |
270
|
|
|
ORDER BY session_id, quiz.title ASC"; |
271
|
|
|
*/ |
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
if (!empty($exercises)) { |
276
|
|
|
/** @var CQuiz $exercise */ |
277
|
|
|
foreach ($exercises as $exercise) { |
278
|
|
|
$links = $exercise->getResourceNode()->getResourceLinks(); |
279
|
|
|
|
280
|
|
|
$exerciseSessionId = null; |
281
|
|
|
foreach ($links as $link) { |
282
|
|
|
if ($link->hasSession()) { |
283
|
|
|
$exerciseSessionId = $link->getSession()->getId(); |
284
|
|
|
break; |
285
|
|
|
} |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
//$exerciseSessionId = $exercise['session_id']; |
289
|
|
|
|
290
|
|
|
if (empty($exerciseSessionId)) { |
291
|
|
|
if ($global) { |
292
|
|
|
// If the exercise was created in the base course. |
293
|
|
|
// Load all sessions. |
294
|
|
|
foreach ($newSessionList as $currentSessionId => $sessionName) { |
295
|
|
|
$result = processStudentList( |
296
|
|
|
$filter_score, |
297
|
|
|
$global, |
298
|
|
|
$exercise, |
299
|
|
|
$courseInfo, |
300
|
|
|
$currentSessionId, |
301
|
|
|
$newSessionList |
302
|
|
|
); |
303
|
|
|
|
304
|
|
|
$html .= $result['html']; |
305
|
|
|
$export_array_global = array_merge( |
306
|
|
|
$export_array_global, |
307
|
|
|
$result['export_array_global'] |
308
|
|
|
); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
// Load base course. |
312
|
|
|
$result = processStudentList( |
313
|
|
|
$filter_score, |
314
|
|
|
$global, |
315
|
|
|
$exercise, |
316
|
|
|
$courseInfo, |
317
|
|
|
0, |
318
|
|
|
$newSessionList |
319
|
|
|
); |
320
|
|
|
$html .= $result['html']; |
321
|
|
|
$export_array_global = array_merge($export_array_global, $result['export_array_global']); |
322
|
|
|
} else { |
323
|
|
|
if (empty($sessionId)) { |
324
|
|
|
// Load base course. |
325
|
|
|
$result = processStudentList( |
326
|
|
|
$filter_score, |
327
|
|
|
$global, |
328
|
|
|
$exercise, |
329
|
|
|
$courseInfo, |
330
|
|
|
0, |
331
|
|
|
$newSessionList |
332
|
|
|
); |
333
|
|
|
|
334
|
|
|
$html .= $result['html']; |
335
|
|
|
if (is_array($result['export_array_global'])) { |
336
|
|
|
$export_array_global = array_merge( |
337
|
|
|
$export_array_global, |
338
|
|
|
$result['export_array_global'] |
339
|
|
|
); |
340
|
|
|
} |
341
|
|
|
} else { |
342
|
|
|
$result = processStudentList( |
343
|
|
|
$filter_score, |
344
|
|
|
$global, |
345
|
|
|
$exercise, |
346
|
|
|
$courseInfo, |
347
|
|
|
$sessionId, |
348
|
|
|
$newSessionList |
349
|
|
|
); |
350
|
|
|
|
351
|
|
|
$html .= $result['html']; |
352
|
|
|
$export_array_global = array_merge( |
353
|
|
|
$export_array_global, |
354
|
|
|
$result['export_array_global'] |
355
|
|
|
); |
356
|
|
|
} |
357
|
|
|
} |
358
|
|
|
} else { |
359
|
|
|
// If the exercise only exists in this session. |
360
|
|
|
$result = processStudentList( |
361
|
|
|
$filter_score, |
362
|
|
|
$global, |
363
|
|
|
$exercise, |
364
|
|
|
$courseInfo, |
365
|
|
|
$exerciseSessionId, |
366
|
|
|
$newSessionList |
367
|
|
|
); |
368
|
|
|
|
369
|
|
|
$html .= $result['html']; |
370
|
|
|
$export_array_global = array_merge( |
371
|
|
|
$export_array_global, |
372
|
|
|
$result['export_array_global'] |
373
|
|
|
); |
374
|
|
|
} |
375
|
|
|
} |
376
|
|
|
} else { |
377
|
|
|
$html .= "<tr> |
378
|
|
|
<td colspan='6'> |
379
|
|
|
".get_lang('There is no test for the moment')." |
380
|
|
|
</td> |
381
|
|
|
</tr> |
382
|
|
|
"; |
383
|
|
|
} |
384
|
|
|
} else { |
385
|
|
|
$html .= "<tr> |
386
|
|
|
<td colspan='6'> |
387
|
|
|
".get_lang('There is no test for the moment')." |
388
|
|
|
</td> |
389
|
|
|
</tr> |
390
|
|
|
"; |
391
|
|
|
} |
392
|
|
|
} |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
$html .= '</table>'; |
396
|
|
|
$html .= '</div>'; |
397
|
|
|
|
398
|
|
|
if (!$exportToXLS) { |
399
|
|
|
echo $html; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
$filename = 'exam-reporting-'.api_get_local_time().'.xlsx'; |
403
|
|
|
|
404
|
|
|
if ($exportToXLS) { |
405
|
|
|
export_complete_report_xls($filename, $export_array_global); |
406
|
|
|
exit; |
407
|
|
|
} |
408
|
|
|
/** |
409
|
|
|
* @param $a |
410
|
|
|
* @param $b |
411
|
|
|
* |
412
|
|
|
* @return int |
413
|
|
|
*/ |
414
|
|
|
function sort_user($a, $b) |
415
|
|
|
{ |
416
|
|
|
if (is_numeric($a['score']) && is_numeric($b['score'])) { |
417
|
|
|
if ($a['score'] < $b['score']) { |
418
|
|
|
return 1; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
return 0; |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
return 1; |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
/** |
428
|
|
|
* @param string $filename |
429
|
|
|
* @param array $array |
430
|
|
|
*/ |
431
|
|
|
function export_complete_report_xls($filename, $array) |
432
|
|
|
{ |
433
|
|
|
global $global, $filter_score; |
434
|
|
|
|
435
|
|
|
$list = []; |
436
|
|
|
if ($global) { |
437
|
|
|
$headers[] = get_lang('Courses'); |
|
|
|
|
438
|
|
|
$headers[] = get_lang('Tests'); |
439
|
|
|
$headers[] = get_lang('Taken'); |
440
|
|
|
$headers[] = get_lang('Not taken'); |
441
|
|
|
$headers[] = sprintf(get_lang('Pass minimum %s'), $filter_score).'%'; |
442
|
|
|
$headers[] = get_lang('Fail'); |
443
|
|
|
$headers[] = get_lang('Total learners'); |
444
|
|
|
|
445
|
|
|
$list[] = $headers; |
446
|
|
|
foreach ($array as $row) { |
447
|
|
|
$listItem = []; |
448
|
|
|
foreach ($row as $item) { |
449
|
|
|
$listItem[] = html_entity_decode(strip_tags($item)); |
450
|
|
|
} |
451
|
|
|
$list[] = $listItem; |
452
|
|
|
} |
453
|
|
|
} else { |
454
|
|
|
$headers[] = get_lang('Tests'); |
455
|
|
|
$headers[] = get_lang('User'); |
456
|
|
|
$headers[] = get_lang('Username'); |
457
|
|
|
$headers[] = get_lang('Percentage'); |
458
|
|
|
$headers[] = get_lang('Status'); |
459
|
|
|
$headers[] = get_lang('Attempts'); |
460
|
|
|
|
461
|
|
|
$list[] = $headers; |
462
|
|
|
|
463
|
|
|
foreach ($array as $row) { |
464
|
|
|
$listItem = []; |
465
|
|
|
$listItem[] = html_entity_decode(strip_tags($row['exercise'])); |
466
|
|
|
|
467
|
|
|
foreach ($row['users'] as $key => $user) { |
468
|
|
|
$listItem[] = html_entity_decode(strip_tags($user)); |
469
|
|
|
$listItem[] = $row['usernames'][$key]; |
470
|
|
|
foreach ($row['results'][$key] as $result_item) { |
471
|
|
|
$listItem[] = html_entity_decode(strip_tags($result_item)); |
472
|
|
|
} |
473
|
|
|
$line++; |
|
|
|
|
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
$list[] = $listItem; |
477
|
|
|
} |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
Export::arrayToXls($list, $filename); |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
function processStudentList($filter_score, $global, Cquiz $exercise, $courseInfo, $sessionId, $newSessionList) |
484
|
|
|
{ |
485
|
|
|
/*if ((isset($exercise['id']) && empty($exercise['id'])) || |
486
|
|
|
!isset($exercise['id']) |
487
|
|
|
) { |
488
|
|
|
return [ |
489
|
|
|
'html' => '', |
490
|
|
|
'export_array_global' => [], |
491
|
|
|
'total_students' => 0, |
492
|
|
|
]; |
493
|
|
|
}*/ |
494
|
|
|
|
495
|
|
|
$exerciseStatsTable = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); |
496
|
|
|
$courseId = $courseInfo['real_id']; |
497
|
|
|
|
498
|
|
|
if (empty($sessionId)) { |
499
|
|
|
$students = CourseManager::get_student_list_from_course_code( |
500
|
|
|
$courseInfo['code'], |
501
|
|
|
false, |
502
|
|
|
0, |
503
|
|
|
null, |
504
|
|
|
null, |
505
|
|
|
false |
506
|
|
|
); |
507
|
|
|
} else { |
508
|
|
|
$students = CourseManager::get_student_list_from_course_code( |
509
|
|
|
$courseInfo['code'], |
510
|
|
|
true, |
511
|
|
|
$sessionId, |
512
|
|
|
null, |
513
|
|
|
null, |
514
|
|
|
false |
515
|
|
|
); |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
$html = null; |
519
|
|
|
$totalStudents = count($students); |
520
|
|
|
|
521
|
|
|
if (!$global) { |
522
|
|
|
$html .= "<tr>"; |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
if (!$global) { |
526
|
|
|
$html .= '<td rowspan="'.$totalStudents.'">'; |
527
|
|
|
} else { |
528
|
|
|
$html .= '<td>'; |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
$html .= $exercise->getTitle(); |
532
|
|
|
|
533
|
|
|
if ($global && !empty($sessionId)) { |
534
|
|
|
$sessionName = isset($newSessionList[$sessionId]) ? $newSessionList[$sessionId] : null; |
535
|
|
|
$html .= Display::getMdiIcon(ObjectIcon::STAR, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Session')).' ('.$sessionName.')'; |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
$html .= '</td>'; |
539
|
|
|
|
540
|
|
|
$globalRow = [ |
541
|
|
|
$courseInfo['title'], |
542
|
|
|
$exercise->getTitle(), |
543
|
|
|
]; |
544
|
|
|
|
545
|
|
|
$total_with_parameter_score = 0; |
546
|
|
|
$taken = 0; |
547
|
|
|
$export_array_global = []; |
548
|
|
|
$studentResult = []; |
549
|
|
|
$export_array = []; |
550
|
|
|
|
551
|
|
|
$exerciseId = $exercise->getIid(); |
552
|
|
|
$sessionCondition = api_get_session_condition($sessionId); |
553
|
|
|
foreach ($students as $student) { |
554
|
|
|
$studentId = isset($student['user_id']) ? $student['user_id'] : $student['id_user']; |
555
|
|
|
$studentId = (int) $studentId; |
556
|
|
|
$sql = "SELECT COUNT(exe_id) as count |
557
|
|
|
FROM $exerciseStatsTable |
558
|
|
|
WHERE |
559
|
|
|
c_id = $courseId AND |
560
|
|
|
exe_exo_id = $exerciseId AND |
561
|
|
|
exe_user_id= $studentId |
562
|
|
|
$sessionCondition |
563
|
|
|
"; |
564
|
|
|
$result = Database::query($sql); |
565
|
|
|
$attempts = Database::fetch_array($result); |
566
|
|
|
|
567
|
|
|
$sql = "SELECT exe_id, score, max_score |
568
|
|
|
FROM $exerciseStatsTable |
569
|
|
|
WHERE |
570
|
|
|
exe_user_id = $studentId AND |
571
|
|
|
c_id = $courseId AND |
572
|
|
|
exe_exo_id = ".$exerciseId." AND |
573
|
|
|
session_id = $sessionId |
574
|
|
|
ORDER BY score DESC |
575
|
|
|
LIMIT 1"; |
576
|
|
|
$result = Database::query($sql); |
577
|
|
|
$score = 0; |
578
|
|
|
$weighting = 0; |
579
|
|
|
while ($scoreInfo = Database::fetch_array($result)) { |
580
|
|
|
$score = $score + $scoreInfo['score']; |
581
|
|
|
$weighting = $weighting + $scoreInfo['max_score']; |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
$percentageScore = 0; |
585
|
|
|
|
586
|
|
|
if (0 != $weighting) { |
587
|
|
|
$percentageScore = round(($score * 100) / $weighting); |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
if ($attempts['count'] > 0) { |
591
|
|
|
$taken++; |
592
|
|
|
} |
593
|
|
|
|
594
|
|
|
if ($percentageScore >= $filter_score) { |
595
|
|
|
$total_with_parameter_score++; |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
$tempArray = []; |
599
|
|
|
|
600
|
|
|
if (!$global) { |
601
|
|
|
$userInfo = api_get_user_info($studentId); |
602
|
|
|
|
603
|
|
|
// User |
604
|
|
|
$userRow = '<td>'; |
605
|
|
|
$userRow .= $userInfo['complete_name']; |
606
|
|
|
$userRow .= '</td>'; |
607
|
|
|
$userRow .= '<td>'.$userInfo['username'].'</td>'; |
608
|
|
|
|
609
|
|
|
// Best result. |
610
|
|
|
if (!empty($attempts['count'])) { |
611
|
|
|
$userRow .= '<td>'; |
612
|
|
|
$userRow .= $percentageScore; |
613
|
|
|
$tempArray[] = $percentageScore; |
614
|
|
|
$userRow .= '</td>'; |
615
|
|
|
|
616
|
|
|
if ($percentageScore >= $filter_score) { |
617
|
|
|
$userRow .= '<td style="background-color:#DFFFA8">'; |
618
|
|
|
$userRow .= get_lang('Pass').'</td>'; |
619
|
|
|
$tempArray[] = get_lang('Pass'); |
620
|
|
|
} else { |
621
|
|
|
$userRow .= '<td style="background-color:#FC9A9E" >'; |
622
|
|
|
$userRow .= get_lang('Fail').'</td>'; |
623
|
|
|
$tempArray[] = get_lang('Fail'); |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
$userRow .= '<td>'; |
627
|
|
|
$userRow .= $attempts['count']; |
628
|
|
|
$tempArray[] = $attempts['count']; |
629
|
|
|
$userRow .= '</td>'; |
630
|
|
|
} else { |
631
|
|
|
$score = '-'; |
632
|
|
|
$userRow .= '<td>'; |
633
|
|
|
$userRow .= '-'; |
634
|
|
|
$tempArray[] = '-'; |
635
|
|
|
$userRow .= '</td>'; |
636
|
|
|
|
637
|
|
|
$userRow .= '<td style="background-color:#FCE89A">'; |
638
|
|
|
$userRow .= get_lang('No attempts'); |
639
|
|
|
$tempArray[] = get_lang('No attempts'); |
640
|
|
|
$userRow .= '</td>'; |
641
|
|
|
$userRow .= '<td>'; |
642
|
|
|
$userRow .= 0; |
643
|
|
|
$tempArray[] = 0; |
644
|
|
|
$userRow .= '</td>'; |
645
|
|
|
} |
646
|
|
|
$userRow .= '</tr>'; |
647
|
|
|
|
648
|
|
|
$studentResult[$studentId] = [ |
649
|
|
|
'html' => $userRow, |
650
|
|
|
'score' => $score, |
651
|
|
|
'array' => $tempArray, |
652
|
|
|
'user' => $userInfo['complete_name'], |
653
|
|
|
'username' => $userInfo['username'], |
654
|
|
|
]; |
655
|
|
|
} |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
$row_not_global['exercise'] = $exercise->getTitle(); |
|
|
|
|
659
|
|
|
|
660
|
|
|
if (!$global) { |
661
|
|
|
if (!empty($studentResult)) { |
662
|
|
|
$studentResultEmpty = $studentResultContent = []; |
663
|
|
|
foreach ($studentResult as $row) { |
664
|
|
|
if ('-' == $row['score']) { |
665
|
|
|
$studentResultEmpty[] = $row; |
666
|
|
|
} else { |
667
|
|
|
$studentResultContent[] = $row; |
668
|
|
|
} |
669
|
|
|
} |
670
|
|
|
|
671
|
|
|
// Sort only users with content |
672
|
|
|
usort($studentResultContent, 'sort_user'); |
673
|
|
|
$studentResult = array_merge($studentResultContent, $studentResultEmpty); |
674
|
|
|
|
675
|
|
|
foreach ($studentResult as $row) { |
676
|
|
|
$html .= $row['html']; |
677
|
|
|
$row_not_global['results'][] = $row['array']; |
678
|
|
|
$row_not_global['users'][] = $row['user']; |
679
|
|
|
$row_not_global['usernames'][] = $row['username']; |
680
|
|
|
} |
681
|
|
|
$export_array[] = $row_not_global; |
682
|
|
|
} |
683
|
|
|
} |
684
|
|
|
|
685
|
|
|
if ($global) { |
686
|
|
|
// Exam taken |
687
|
|
|
$html .= '<td>'; |
688
|
|
|
$html .= $taken; |
689
|
|
|
$globalRow[] = $taken; |
690
|
|
|
$html .= '</td>'; |
691
|
|
|
|
692
|
|
|
// Exam NOT taken |
693
|
|
|
$html .= '<td>'; |
694
|
|
|
$html .= $not_taken = $totalStudents - $taken; |
695
|
|
|
$globalRow[] = $not_taken; |
696
|
|
|
$html .= '</td>'; |
697
|
|
|
|
698
|
|
|
// Exam pass |
699
|
|
|
if (!empty($total_with_parameter_score)) { |
700
|
|
|
$html .= '<td style="background-color:#DFFFA8" >'; |
701
|
|
|
} else { |
702
|
|
|
$html .= '<td style="background-color:#FCE89A" >'; |
703
|
|
|
} |
704
|
|
|
|
705
|
|
|
$html .= $total_with_parameter_score; |
706
|
|
|
$globalRow[] = $total_with_parameter_score; |
707
|
|
|
$html .= '</td>'; |
708
|
|
|
|
709
|
|
|
// Exam fail |
710
|
|
|
$html .= '<td>'; |
711
|
|
|
|
712
|
|
|
$html .= $fail = $taken - $total_with_parameter_score; |
713
|
|
|
$globalRow[] = $fail; |
714
|
|
|
$html .= '</td>'; |
715
|
|
|
|
716
|
|
|
$html .= '<td>'; |
717
|
|
|
$html .= $totalStudents; |
718
|
|
|
$globalRow[] = $totalStudents; |
719
|
|
|
|
720
|
|
|
$html .= '</td>'; |
721
|
|
|
|
722
|
|
|
$html .= '</tr>'; |
723
|
|
|
$export_array_global[] = $globalRow; |
724
|
|
|
} |
725
|
|
|
|
726
|
|
|
return [ |
727
|
|
|
'html' => $html, |
728
|
|
|
'export_array_global' => $global ? $export_array_global : $export_array, |
729
|
|
|
'total_students' => $totalStudents, |
730
|
|
|
]; |
731
|
|
|
} |
732
|
|
|
|
733
|
|
|
Display:: display_footer(); |
734
|
|
|
|