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