Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Tracking often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Tracking, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 18 | class Tracking |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * Get group reporting |
||
| 22 | * @param int $course_id |
||
| 23 | * @param int $sessionId |
||
| 24 | * @param int $group_id |
||
| 25 | * @param string $type |
||
| 26 | * @param int $start |
||
| 27 | * @param int $limit |
||
| 28 | * @param int $sidx |
||
| 29 | * @param string $sord |
||
| 30 | * @param array $where_condition |
||
| 31 | * @return array|null |
||
| 32 | */ |
||
| 33 | public static function get_group_reporting( |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @param int $user_id |
||
| 117 | * @param array $courseInfo |
||
| 118 | * @param int $session_id |
||
| 119 | * @param string $origin |
||
| 120 | * @param bool $export_csv |
||
| 121 | * @param int $lp_id |
||
| 122 | * @param int $lp_item_id |
||
| 123 | * @param int $extendId |
||
| 124 | * @param int $extendAttemptId |
||
| 125 | * @param string $extendedAttempt |
||
| 126 | * @param string $extendedAll |
||
| 127 | * @param string $type classic or simple |
||
| 128 | * @param boolean $allowExtend Optional. Allow or not extend te results |
||
| 129 | * @return null|string |
||
| 130 | */ |
||
| 131 | public static function getLpStats( |
||
| 132 | $user_id, |
||
| 133 | $courseInfo, |
||
| 134 | $session_id, |
||
| 135 | $origin, |
||
| 136 | $export_csv, |
||
| 137 | $lp_id, |
||
| 138 | $lp_item_id = null, |
||
| 139 | $extendId = null, |
||
| 140 | $extendAttemptId = null, |
||
| 141 | $extendedAttempt = null, |
||
| 142 | $extendedAll = null, |
||
| 143 | $type = 'classic', |
||
| 144 | $allowExtend = true |
||
| 145 | ) { |
||
| 146 | if (empty($courseInfo) || empty($lp_id)) { |
||
| 147 | return null; |
||
| 148 | } |
||
| 149 | |||
| 150 | $hideTime = api_get_configuration_value('hide_lp_time'); |
||
| 151 | |||
| 152 | $lp_id = intval($lp_id); |
||
| 153 | $lp_item_id = intval($lp_item_id); |
||
| 154 | $user_id = intval($user_id); |
||
| 155 | $session_id = intval($session_id); |
||
| 156 | $origin = Security::remove_XSS($origin); |
||
| 157 | $list = learnpath::get_flat_ordered_items_list($lp_id, 0, $courseInfo['real_id']); |
||
| 158 | $is_allowed_to_edit = api_is_allowed_to_edit(null, true); |
||
| 159 | $course_id = $courseInfo['real_id']; |
||
| 160 | $courseCode = $courseInfo['code']; |
||
| 161 | $session_condition = api_get_session_condition($session_id); |
||
| 162 | |||
| 163 | // Extend all button |
||
| 164 | $output = null; |
||
| 165 | $extend_all = 0; |
||
| 166 | |||
| 167 | if ($origin == 'tracking') { |
||
| 168 | $url_suffix = '&session_id='.$session_id.'&course='.$courseCode.'&student_id='.$user_id.'&lp_id='.$lp_id.'&origin='.$origin; |
||
| 169 | } else { |
||
| 170 | $url_suffix = '&lp_id='.$lp_id; |
||
| 171 | } |
||
| 172 | |||
| 173 | if (!empty($extendedAll)) { |
||
| 174 | $extend_all_link = Display::url( |
||
| 175 | Display::return_icon('view_less_stats.gif', get_lang('HideAllAttempts')), |
||
| 176 | api_get_self().'?action=stats'.$url_suffix |
||
| 177 | ); |
||
| 178 | $extend_all = 1; |
||
| 179 | } else { |
||
| 180 | $extend_all_link = Display::url( |
||
| 181 | Display::return_icon('view_more_stats.gif', get_lang('ShowAllAttempts')), |
||
| 182 | api_get_self().'?action=stats&extend_all=1'.$url_suffix |
||
| 183 | ); |
||
| 184 | } |
||
| 185 | |||
| 186 | if ($origin != 'tracking') { |
||
| 187 | $output .= '<div class="section-status">'; |
||
| 188 | $output .= Display::page_header(get_lang('ScormMystatus')); |
||
| 189 | $output .= '</div>'; |
||
| 190 | } |
||
| 191 | |||
| 192 | $actionColumn = null; |
||
| 193 | if ($type == 'classic') { |
||
| 194 | $actionColumn = ' <th>'.get_lang('Actions').'</th>'; |
||
| 195 | } |
||
| 196 | |||
| 197 | $timeHeader = '<th class="lp_time" colspan="2">'.get_lang('ScormTime').'</th>'; |
||
| 198 | if ($hideTime) { |
||
| 199 | $timeHeader = ''; |
||
| 200 | } |
||
| 201 | $output .= '<div class="table-responsive">'; |
||
| 202 | $output .= '<table id="lp_tracking" class="table tracking"> |
||
| 203 | <thead> |
||
| 204 | <tr class="table-header"> |
||
| 205 | <th width="16">' . ($allowExtend == true ? $extend_all_link : ' ').'</th> |
||
| 206 | <th colspan="4"> |
||
| 207 | ' . get_lang('ScormLessonTitle').' |
||
| 208 | </th> |
||
| 209 | <th colspan="2"> |
||
| 210 | ' . get_lang('ScormStatus').' |
||
| 211 | </th> |
||
| 212 | <th colspan="2"> |
||
| 213 | ' . get_lang('ScormScore').' |
||
| 214 | </th> |
||
| 215 | '.$timeHeader.' |
||
| 216 | '.$actionColumn.' |
||
| 217 | </tr> |
||
| 218 | </thead> |
||
| 219 | <tbody> |
||
| 220 | '; |
||
| 221 | |||
| 222 | // Going through the items using the $items[] array instead of the database order ensures |
||
| 223 | // we get them in the same order as in the imsmanifest file, which is rather random when using |
||
| 224 | // the database table. |
||
| 225 | $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM); |
||
| 226 | $TBL_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW); |
||
| 227 | $TBL_LP_VIEW = Database::get_course_table(TABLE_LP_VIEW); |
||
| 228 | $tbl_quiz_questions = Database::get_course_table(TABLE_QUIZ_QUESTION); |
||
| 229 | $TBL_QUIZ = Database::get_course_table(TABLE_QUIZ_TEST); |
||
| 230 | $tbl_stats_exercices = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); |
||
| 231 | $tbl_stats_attempts = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); |
||
| 232 | |||
| 233 | $sql = "SELECT max(view_count) |
||
| 234 | FROM $TBL_LP_VIEW |
||
| 235 | WHERE |
||
| 236 | c_id = $course_id AND |
||
| 237 | lp_id = $lp_id AND |
||
| 238 | user_id = $user_id |
||
| 239 | $session_condition"; |
||
| 240 | $res = Database::query($sql); |
||
| 241 | $view = ''; |
||
| 242 | if (Database::num_rows($res) > 0) { |
||
| 243 | $myrow = Database::fetch_array($res); |
||
| 244 | $view = $myrow[0]; |
||
| 245 | } |
||
| 246 | |||
| 247 | $counter = 0; |
||
| 248 | $total_time = 0; |
||
| 249 | $h = get_lang('h'); |
||
| 250 | |||
| 251 | if (!empty($export_csv)) { |
||
| 252 | $csvHeaders = array( |
||
| 253 | get_lang('ScormLessonTitle'), |
||
| 254 | get_lang('ScormStatus'), |
||
| 255 | get_lang('ScormScore') |
||
| 256 | ); |
||
| 257 | |||
| 258 | if ($hideTime === false) { |
||
| 259 | $csvHeaders[] = get_lang('ScormTime'); |
||
| 260 | } |
||
| 261 | |||
| 262 | $csv_content[] = $csvHeaders; |
||
| 263 | } |
||
| 264 | |||
| 265 | $result_disabled_ext_all = true; |
||
| 266 | $chapterTypes = learnpath::getChapterTypes(); |
||
| 267 | |||
| 268 | // Show lp items |
||
| 269 | if (is_array($list) && count($list) > 0) { |
||
| 270 | foreach ($list as $my_item_id) { |
||
| 271 | $extend_this = 0; |
||
| 272 | $order = 'DESC'; |
||
| 273 | if ((!empty($extendId) && $extendId == $my_item_id) || $extend_all) { |
||
| 274 | $extend_this = 1; |
||
| 275 | $order = 'ASC'; |
||
| 276 | } |
||
| 277 | |||
| 278 | // Prepare statement to go through each attempt. |
||
| 279 | $viewCondition = null; |
||
| 280 | if (!empty($view)) { |
||
| 281 | $viewCondition = " AND v.view_count = $view "; |
||
| 282 | } |
||
| 283 | |||
| 284 | $sql = "SELECT |
||
| 285 | iv.status as mystatus, |
||
| 286 | v.view_count as mycount, |
||
| 287 | iv.score as myscore, |
||
| 288 | iv.total_time as mytime, |
||
| 289 | i.id as myid, |
||
| 290 | i.lp_id as mylpid, |
||
| 291 | iv.lp_view_id as mylpviewid, |
||
| 292 | i.title as mytitle, |
||
| 293 | i.max_score as mymaxscore, |
||
| 294 | iv.max_score as myviewmaxscore, |
||
| 295 | i.item_type as item_type, |
||
| 296 | iv.view_count as iv_view_count, |
||
| 297 | iv.id as iv_id, |
||
| 298 | path |
||
| 299 | FROM $TBL_LP_ITEM as i |
||
| 300 | INNER JOIN $TBL_LP_ITEM_VIEW as iv |
||
| 301 | ON (i.id = iv.lp_item_id AND i.c_id = iv.c_id) |
||
| 302 | INNER JOIN $TBL_LP_VIEW as v |
||
| 303 | ON (iv.lp_view_id = v.id AND v.c_id = iv.c_id) |
||
| 304 | WHERE |
||
| 305 | v.c_id = $course_id AND |
||
| 306 | i.id = $my_item_id AND |
||
| 307 | i.lp_id = $lp_id AND |
||
| 308 | v.user_id = $user_id AND |
||
| 309 | v.session_id = $session_id |
||
| 310 | $viewCondition |
||
| 311 | ORDER BY iv.view_count $order "; |
||
| 312 | |||
| 313 | $result = Database::query($sql); |
||
| 314 | $num = Database::num_rows($result); |
||
| 315 | $time_for_total = 0; |
||
| 316 | |||
| 317 | // Extend all |
||
| 318 | if (($extend_this || $extend_all) && $num > 0) { |
||
| 319 | $row = Database::fetch_array($result); |
||
| 320 | $result_disabled_ext_all = false; |
||
| 321 | View Code Duplication | if ($row['item_type'] == 'quiz') { |
|
| 322 | // Check results_disabled in quiz table. |
||
| 323 | $my_path = Database::escape_string($row['path']); |
||
| 324 | |||
| 325 | $sql = "SELECT results_disabled |
||
| 326 | FROM $TBL_QUIZ |
||
| 327 | WHERE |
||
| 328 | c_id = $course_id AND |
||
| 329 | id ='".$my_path."'"; |
||
| 330 | $res_result_disabled = Database::query($sql); |
||
| 331 | $row_result_disabled = Database::fetch_row($res_result_disabled); |
||
| 332 | |||
| 333 | if (Database::num_rows($res_result_disabled) > 0 && |
||
| 334 | (int) $row_result_disabled[0] === 1 |
||
| 335 | ) { |
||
| 336 | $result_disabled_ext_all = true; |
||
| 337 | } |
||
| 338 | } |
||
| 339 | |||
| 340 | // If there are several attempts, and the link to extend has been clicked, show each attempt... |
||
| 341 | if (($counter % 2) == 0) { |
||
| 342 | $oddclass = 'row_odd'; |
||
| 343 | } else { |
||
| 344 | $oddclass = 'row_even'; |
||
| 345 | } |
||
| 346 | |||
| 347 | $extend_link = ''; |
||
| 348 | View Code Duplication | if (!empty($inter_num)) { |
|
| 349 | $extend_link = Display::url( |
||
| 350 | Display::return_icon( |
||
| 351 | 'visible.gif', |
||
| 352 | get_lang('HideAttemptView') |
||
| 353 | ), |
||
| 354 | api_get_self().'?action=stats&fold_id='.$my_item_id.$url_suffix |
||
| 355 | ); |
||
| 356 | } |
||
| 357 | $title = $row['mytitle']; |
||
| 358 | |||
| 359 | if (empty($title)) { |
||
| 360 | $title = learnpath::rl_get_resource_name($courseInfo['code'], $lp_id, $row['myid']); |
||
| 361 | } |
||
| 362 | |||
| 363 | if (in_array($row['item_type'], $chapterTypes)) { |
||
| 364 | $title = "<h4> $title </h4>"; |
||
| 365 | } |
||
| 366 | $lesson_status = $row['mystatus']; |
||
| 367 | $title = Security::remove_XSS($title); |
||
| 368 | $counter++; |
||
| 369 | |||
| 370 | $action = null; |
||
| 371 | if ($type == 'classic') { |
||
| 372 | $action = '<td></td>'; |
||
| 373 | } |
||
| 374 | |||
| 375 | if (in_array($row['item_type'], $chapterTypes)) { |
||
| 376 | $output .= '<tr class="'.$oddclass.'"> |
||
| 377 | <td>'.$extend_link.'</td> |
||
| 378 | <td colspan="4"> |
||
| 379 | '.$title.' |
||
| 380 | </td> |
||
| 381 | <td colspan="2">'.learnpathItem::humanize_status($lesson_status, true, $type).'</td> |
||
| 382 | <td colspan="2"></td> |
||
| 383 | <td colspan="2"></td> |
||
| 384 | '.$action.' |
||
| 385 | </tr>'; |
||
| 386 | continue; |
||
| 387 | } else { |
||
| 388 | $output .= '<tr class="'.$oddclass.'"> |
||
| 389 | <td>'.$extend_link.'</td> |
||
| 390 | <td colspan="4"> |
||
| 391 | '.$title.' |
||
| 392 | </td> |
||
| 393 | <td colspan="2"></td> |
||
| 394 | <td colspan="2"></td> |
||
| 395 | <td colspan="2"></td> |
||
| 396 | '.$action.' |
||
| 397 | </tr>'; |
||
| 398 | } |
||
| 399 | |||
| 400 | $attemptCount = 1; |
||
| 401 | do { |
||
| 402 | // Check if there are interactions below. |
||
| 403 | $extend_attempt_link = ''; |
||
| 404 | $extend_this_attempt = 0; |
||
| 405 | |||
| 406 | if ((learnpath::get_interactions_count_from_db($row['iv_id'], $course_id) > 0 || |
||
| 407 | learnpath::get_objectives_count_from_db($row['iv_id'], $course_id) > 0) && |
||
| 408 | !$extend_all |
||
| 409 | ) { |
||
| 410 | View Code Duplication | if ($extendAttemptId == $row['iv_id']) { |
|
| 411 | // The extend button for this attempt has been clicked. |
||
| 412 | $extend_this_attempt = 1; |
||
| 413 | $extend_attempt_link = Display::url( |
||
| 414 | Display::return_icon('visible.gif', get_lang('HideAttemptView')), |
||
| 415 | api_get_self().'?action=stats&extend_id='.$my_item_id.'&fold_attempt_id='.$row['iv_id'].$url_suffix |
||
| 416 | ); |
||
| 417 | } else { // Same case if fold_attempt_id is set, so not implemented explicitly. |
||
| 418 | // The extend button for this attempt has not been clicked. |
||
| 419 | $extend_attempt_link = Display::url( |
||
| 420 | Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')), |
||
| 421 | api_get_self().'?action=stats&extend_id='.$my_item_id.'&extend_attempt_id='.$row['iv_id'].$url_suffix |
||
| 422 | ); |
||
| 423 | } |
||
| 424 | } |
||
| 425 | |||
| 426 | if (($counter % 2) == 0) { |
||
| 427 | $oddclass = 'row_odd'; |
||
| 428 | } else { |
||
| 429 | $oddclass = 'row_even'; |
||
| 430 | } |
||
| 431 | |||
| 432 | $lesson_status = $row['mystatus']; |
||
| 433 | $score = $row['myscore']; |
||
| 434 | $time_for_total = $row['mytime']; |
||
| 435 | $time = learnpathItem::getScormTimeFromParameter('js', $row['mytime']); |
||
| 436 | |||
| 437 | if ($score == 0) { |
||
| 438 | $maxscore = $row['mymaxscore']; |
||
| 439 | } else { |
||
| 440 | if ($row['item_type'] == 'sco') { |
||
| 441 | View Code Duplication | if (!empty($row['myviewmaxscore']) && $row['myviewmaxscore'] > 0) { |
|
| 442 | $maxscore = $row['myviewmaxscore']; |
||
| 443 | } elseif ($row['myviewmaxscore'] === '') { |
||
| 444 | $maxscore = 0; |
||
| 445 | } else { |
||
| 446 | $maxscore = $row['mymaxscore']; |
||
| 447 | } |
||
| 448 | } else { |
||
| 449 | $maxscore = $row['mymaxscore']; |
||
| 450 | } |
||
| 451 | } |
||
| 452 | |||
| 453 | // Remove "NaN" if any (@todo: locate the source of these NaN) |
||
| 454 | $time = str_replace('NaN', '00'.$h.'00\'00"', $time); |
||
| 455 | |||
| 456 | if ($row['item_type'] != 'dir') { |
||
| 457 | if (!$is_allowed_to_edit && $result_disabled_ext_all) { |
||
| 458 | $view_score = Display::return_icon( |
||
| 459 | 'invisible.gif', |
||
| 460 | get_lang('ResultsHiddenByExerciseSetting') |
||
| 461 | ); |
||
| 462 | } else { |
||
| 463 | switch ($row['item_type']) { |
||
| 464 | View Code Duplication | case 'sco': |
|
| 465 | if ($maxscore == 0) { |
||
| 466 | $view_score = $score; |
||
| 467 | } else { |
||
| 468 | $view_score = ExerciseLib::show_score( |
||
| 469 | $score, |
||
| 470 | $maxscore, |
||
| 471 | false |
||
| 472 | ); |
||
| 473 | } |
||
| 474 | break; |
||
| 475 | View Code Duplication | case 'document': |
|
| 476 | $view_score = ($score == 0 ? '/' : ExerciseLib::show_score($score, $maxscore, false)); |
||
| 477 | break; |
||
| 478 | default: |
||
| 479 | $view_score = ExerciseLib::show_score( |
||
| 480 | $score, |
||
| 481 | $maxscore, |
||
| 482 | false |
||
| 483 | ); |
||
| 484 | break; |
||
| 485 | } |
||
| 486 | } |
||
| 487 | |||
| 488 | $action = null; |
||
| 489 | if ($type == 'classic') { |
||
| 490 | $action = '<td></td>'; |
||
| 491 | } |
||
| 492 | $timeRow = '<td class="lp_time" colspan="2">'.$time.'</td>'; |
||
| 493 | if ($hideTime) { |
||
| 494 | $timeRow = ''; |
||
| 495 | } |
||
| 496 | $output .= '<tr class="'.$oddclass.'"> |
||
| 497 | <td></td> |
||
| 498 | <td>' . $extend_attempt_link.'</td> |
||
| 499 | <td colspan="3">' . get_lang('Attempt').' '.$attemptCount.'</td> |
||
| 500 | <td colspan="2">' . learnpathItem::humanize_status($lesson_status, true, $type).'</td> |
||
| 501 | <td colspan="2">' . $view_score.'</td> |
||
| 502 | '.$timeRow.' |
||
| 503 | '.$action.' |
||
| 504 | </tr>'; |
||
| 505 | $attemptCount++; |
||
| 506 | if (!empty($export_csv)) { |
||
| 507 | $temp = array(); |
||
| 508 | $temp[] = $title = Security::remove_XSS($title); |
||
| 509 | $temp[] = Security::remove_XSS( |
||
| 510 | learnpathItem::humanize_status($lesson_status, false, $type) |
||
| 511 | ); |
||
| 512 | |||
| 513 | View Code Duplication | if ($row['item_type'] == 'quiz') { |
|
| 514 | if (!$is_allowed_to_edit && $result_disabled_ext_all) { |
||
| 515 | $temp[] = '/'; |
||
| 516 | } else { |
||
| 517 | $temp[] = ($score == 0 ? '0/'.$maxscore : ($maxscore == 0 ? $score : $score.'/'.float_format($maxscore, 1))); |
||
| 518 | } |
||
| 519 | } else { |
||
| 520 | $temp[] = ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score.'/'.float_format($maxscore, 1))); |
||
| 521 | } |
||
| 522 | |||
| 523 | if ($hideTime === false) { |
||
| 524 | $temp[] = $time; |
||
| 525 | } |
||
| 526 | $csv_content[] = $temp; |
||
| 527 | } |
||
| 528 | } |
||
| 529 | |||
| 530 | $counter++; |
||
| 531 | $action = null; |
||
| 532 | if ($type == 'classic') { |
||
| 533 | $action = '<td></td>'; |
||
| 534 | } |
||
| 535 | |||
| 536 | if ($extend_this_attempt || $extend_all) { |
||
| 537 | $list1 = learnpath::get_iv_interactions_array($row['iv_id']); |
||
| 538 | foreach ($list1 as $id => $interaction) { |
||
| 539 | if (($counter % 2) == 0) { |
||
| 540 | $oddclass = 'row_odd'; |
||
| 541 | } else { |
||
| 542 | $oddclass = 'row_even'; |
||
| 543 | } |
||
| 544 | $student_response = urldecode($interaction['student_response']); |
||
| 545 | $content_student_response = explode('__|', $student_response); |
||
| 546 | |||
| 547 | if (count($content_student_response) > 0) { |
||
| 548 | if (count($content_student_response) >= 3) { |
||
| 549 | // Pop the element off the end of array. |
||
| 550 | array_pop($content_student_response); |
||
| 551 | } |
||
| 552 | $student_response = implode(',', $content_student_response); |
||
| 553 | } |
||
| 554 | |||
| 555 | $timeRow = '<td class="lp_time">'.$interaction['time'].'</td>'; |
||
| 556 | if ($hideTime) { |
||
| 557 | $timeRow = ''; |
||
| 558 | } |
||
| 559 | |||
| 560 | $output .= '<tr class="'.$oddclass.'"> |
||
| 561 | <td></td> |
||
| 562 | <td></td> |
||
| 563 | <td></td> |
||
| 564 | <td>'.$interaction['order_id'].'</td> |
||
| 565 | <td>'.$interaction['id'].'</td> |
||
| 566 | <td colspan="2">' . $interaction['type'].'</td> |
||
| 567 | <td>'.$student_response.'</td> |
||
| 568 | <td>'.$interaction['result'].'</td> |
||
| 569 | <td>'.$interaction['latency'].'</td> |
||
| 570 | '.$timeRow.' |
||
| 571 | '.$action.' |
||
| 572 | </tr>'; |
||
| 573 | $counter++; |
||
| 574 | } |
||
| 575 | $list2 = learnpath::get_iv_objectives_array($row['iv_id']); |
||
| 576 | View Code Duplication | foreach ($list2 as $id => $interaction) { |
|
| 577 | if (($counter % 2) == 0) { |
||
| 578 | $oddclass = 'row_odd'; |
||
| 579 | } else { |
||
| 580 | $oddclass = 'row_even'; |
||
| 581 | } |
||
| 582 | $output .= '<tr class="'.$oddclass.'"> |
||
| 583 | <td></td> |
||
| 584 | <td></td> |
||
| 585 | <td></td> |
||
| 586 | <td>' . $interaction['order_id'].'</td> |
||
| 587 | <td colspan="2">' . $interaction['objective_id'].'</td> |
||
| 588 | <td colspan="2">' . $interaction['status'].'</td> |
||
| 589 | <td>' . $interaction['score_raw'].'</td> |
||
| 590 | <td>' . $interaction['score_max'].'</td> |
||
| 591 | <td>' . $interaction['score_min'].'</td> |
||
| 592 | '.$action.' |
||
| 593 | </tr>'; |
||
| 594 | $counter++; |
||
| 595 | } |
||
| 596 | } |
||
| 597 | } while ($row = Database::fetch_array($result)); |
||
| 598 | } elseif ($num > 0) { |
||
| 599 | // Not extended. |
||
| 600 | $row = Database::fetch_array($result, 'ASSOC'); |
||
| 601 | $my_id = $row['myid']; |
||
| 602 | $my_lp_id = $row['mylpid']; |
||
| 603 | $my_lp_view_id = $row['mylpviewid']; |
||
| 604 | $my_path = $row['path']; |
||
| 605 | $result_disabled_ext_all = false; |
||
| 606 | |||
| 607 | View Code Duplication | if ($row['item_type'] == 'quiz') { |
|
| 608 | // Check results_disabled in quiz table. |
||
| 609 | $my_path = Database::escape_string($my_path); |
||
| 610 | $sql = "SELECT results_disabled |
||
| 611 | FROM $TBL_QUIZ |
||
| 612 | WHERE c_id = $course_id AND id ='".$my_path."'"; |
||
| 613 | $res_result_disabled = Database::query($sql); |
||
| 614 | $row_result_disabled = Database::fetch_row($res_result_disabled); |
||
| 615 | |||
| 616 | if (Database::num_rows($res_result_disabled) > 0 && |
||
| 617 | (int) $row_result_disabled[0] === 1 |
||
| 618 | ) { |
||
| 619 | $result_disabled_ext_all = true; |
||
| 620 | } |
||
| 621 | } |
||
| 622 | |||
| 623 | // Check if there are interactions below |
||
| 624 | $extend_this_attempt = 0; |
||
| 625 | $inter_num = learnpath::get_interactions_count_from_db($row['iv_id'], $course_id); |
||
| 626 | $objec_num = learnpath::get_objectives_count_from_db($row['iv_id'], $course_id); |
||
| 627 | $extend_attempt_link = ''; |
||
| 628 | if ($inter_num > 0 || $objec_num > 0) { |
||
| 629 | View Code Duplication | if (!empty($extendAttemptId) && $extendAttemptId == $row['iv_id']) { |
|
| 630 | // The extend button for this attempt has been clicked. |
||
| 631 | $extend_this_attempt = 1; |
||
| 632 | $extend_attempt_link = Display::url( |
||
| 633 | Display::return_icon('visible.gif', get_lang('HideAttemptView')), |
||
| 634 | api_get_self().'?action=stats&extend_id='.$my_item_id.'&fold_attempt_id='.$row['iv_id'].$url_suffix |
||
| 635 | ); |
||
| 636 | } else { |
||
| 637 | // Same case if fold_attempt_id is set, so not implemented explicitly. |
||
| 638 | // The extend button for this attempt has not been clicked. |
||
| 639 | $extend_attempt_link = Display::url( |
||
| 640 | Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')), |
||
| 641 | api_get_self().'?action=stats&extend_id='.$my_item_id.'&extend_attempt_id='.$row['iv_id'].$url_suffix |
||
| 642 | ); |
||
| 643 | } |
||
| 644 | } |
||
| 645 | |||
| 646 | if (($counter % 2) == 0) { |
||
| 647 | $oddclass = 'row_odd'; |
||
| 648 | } else { |
||
| 649 | $oddclass = 'row_even'; |
||
| 650 | } |
||
| 651 | |||
| 652 | $extend_link = ''; |
||
| 653 | if ($inter_num > 1) { |
||
| 654 | $extend_link = Display::url( |
||
| 655 | Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')), |
||
| 656 | api_get_self().'?action=stats&extend_id='.$my_item_id.'&extend_attempt_id='.$row['iv_id'].$url_suffix |
||
| 657 | ); |
||
| 658 | } |
||
| 659 | |||
| 660 | $lesson_status = $row['mystatus']; |
||
| 661 | $score = $row['myscore']; |
||
| 662 | $subtotal_time = $row['mytime']; |
||
| 663 | |||
| 664 | while ($tmp_row = Database::fetch_array($result)) { |
||
| 665 | $subtotal_time += $tmp_row['mytime']; |
||
| 666 | } |
||
| 667 | $title = $row['mytitle']; |
||
| 668 | // Selecting the exe_id from stats attempts tables in order to look the max score value. |
||
| 669 | $sql = 'SELECT * FROM '.$tbl_stats_exercices.' |
||
| 670 | WHERE |
||
| 671 | exe_exo_id="'.$row['path'].'" AND |
||
| 672 | exe_user_id="'.$user_id.'" AND |
||
| 673 | orig_lp_id = "'.$lp_id.'" AND |
||
| 674 | orig_lp_item_id = "'.$row['myid'].'" AND |
||
| 675 | c_id = '.$course_id.' AND |
||
| 676 | status <> "incomplete" AND |
||
| 677 | session_id = '.$session_id.' |
||
| 678 | ORDER BY exe_date DESC |
||
| 679 | LIMIT 1'; |
||
| 680 | |||
| 681 | $resultLastAttempt = Database::query($sql); |
||
| 682 | $num = Database::num_rows($resultLastAttempt); |
||
| 683 | $id_last_attempt = null; |
||
| 684 | if ($num > 0) { |
||
| 685 | while ($rowLA = Database::fetch_array($resultLastAttempt)) { |
||
| 686 | $id_last_attempt = $rowLA['exe_id']; |
||
| 687 | } |
||
| 688 | } |
||
| 689 | |||
| 690 | switch ($row['item_type']) { |
||
| 691 | case 'sco': |
||
| 692 | View Code Duplication | if (!empty($row['myviewmaxscore']) and $row['myviewmaxscore'] > 0) { |
|
| 693 | $maxscore = $row['myviewmaxscore']; |
||
| 694 | } elseif ($row['myviewmaxscore'] === '') { |
||
| 695 | $maxscore = 0; |
||
| 696 | } else { |
||
| 697 | $maxscore = $row['mymaxscore']; |
||
| 698 | } |
||
| 699 | break; |
||
| 700 | case 'quiz': |
||
| 701 | // Get score and total time from last attempt of a exercise en lp. |
||
| 702 | $sql = "SELECT score |
||
| 703 | FROM $TBL_LP_ITEM_VIEW |
||
| 704 | WHERE |
||
| 705 | c_id = $course_id AND |
||
| 706 | lp_item_id = '".(int) $my_id."' AND |
||
| 707 | lp_view_id = '" . (int) $my_lp_view_id."' |
||
| 708 | ORDER BY view_count DESC limit 1"; |
||
| 709 | $res_score = Database::query($sql); |
||
| 710 | $row_score = Database::fetch_array($res_score); |
||
| 711 | |||
| 712 | $sql = "SELECT SUM(total_time) as total_time |
||
| 713 | FROM $TBL_LP_ITEM_VIEW |
||
| 714 | WHERE |
||
| 715 | c_id = $course_id AND |
||
| 716 | lp_item_id = '".(int) $my_id."' AND |
||
| 717 | lp_view_id = '" . (int) $my_lp_view_id."'"; |
||
| 718 | $res_time = Database::query($sql); |
||
| 719 | $row_time = Database::fetch_array($res_time); |
||
| 720 | |||
| 721 | if (Database::num_rows($res_score) > 0 && |
||
| 722 | Database::num_rows($res_time) > 0 |
||
| 723 | ) { |
||
| 724 | $score = (float) $row_score['score']; |
||
| 725 | $subtotal_time = (int) $row_time['total_time']; |
||
| 726 | } else { |
||
| 727 | $score = 0; |
||
| 728 | $subtotal_time = 0; |
||
| 729 | } |
||
| 730 | |||
| 731 | // Selecting the max score from an attempt. |
||
| 732 | $sql = "SELECT SUM(t.ponderation) as maxscore |
||
| 733 | FROM ( |
||
| 734 | SELECT DISTINCT |
||
| 735 | question_id, marks, ponderation |
||
| 736 | FROM $tbl_stats_attempts as at |
||
| 737 | INNER JOIN $tbl_quiz_questions as q |
||
| 738 | ON (q.id = at.question_id AND q.c_id = $course_id) |
||
| 739 | WHERE exe_id ='$id_last_attempt' |
||
| 740 | ) as t"; |
||
| 741 | |||
| 742 | $result = Database::query($sql); |
||
| 743 | $row_max_score = Database::fetch_array($result); |
||
| 744 | $maxscore = $row_max_score['maxscore']; |
||
| 745 | break; |
||
| 746 | default: |
||
| 747 | $maxscore = $row['mymaxscore']; |
||
| 748 | break; |
||
| 749 | } |
||
| 750 | |||
| 751 | $time_for_total = $subtotal_time; |
||
| 752 | $time = learnpathItem::getScormTimeFromParameter( |
||
| 753 | 'js', |
||
| 754 | $subtotal_time |
||
| 755 | ); |
||
| 756 | if (empty($title)) { |
||
| 757 | $title = learnpath::rl_get_resource_name( |
||
| 758 | $courseInfo['code'], |
||
| 759 | $lp_id, |
||
| 760 | $row['myid'] |
||
| 761 | ); |
||
| 762 | } |
||
| 763 | |||
| 764 | $action = null; |
||
| 765 | if ($type == 'classic') { |
||
| 766 | $action = '<td></td>'; |
||
| 767 | } |
||
| 768 | |||
| 769 | if (in_array($row['item_type'], $chapterTypes)) { |
||
| 770 | $title = Security::remove_XSS($title); |
||
| 771 | $output .= '<tr class="'.$oddclass.'"> |
||
| 772 | <td>'.$extend_link.'</td> |
||
| 773 | <td colspan="4"> |
||
| 774 | <h4>'.$title.'</h4> |
||
| 775 | </td> |
||
| 776 | <td colspan="2">'.learnpathitem::humanize_status($lesson_status).'</td> |
||
| 777 | <td colspan="2"></td> |
||
| 778 | <td colspan="2"></td> |
||
| 779 | '.$action.' |
||
| 780 | </tr>'; |
||
| 781 | } else { |
||
| 782 | $correct_test_link = '-'; |
||
| 783 | $showRowspan = false; |
||
| 784 | if ($row['item_type'] == 'quiz') { |
||
| 785 | $my_url_suffix = '&course='.$courseCode.'&student_id='.$user_id.'&lp_id='.intval($row['mylpid']).'&origin='.$origin; |
||
| 786 | $sql = 'SELECT * FROM '.$tbl_stats_exercices.' |
||
| 787 | WHERE |
||
| 788 | exe_exo_id="' . $row['path'].'" AND |
||
| 789 | exe_user_id="' . $user_id.'" AND |
||
| 790 | orig_lp_id = "' . $lp_id.'" AND |
||
| 791 | orig_lp_item_id = "' . $row['myid'].'" AND |
||
| 792 | c_id = ' . $course_id.' AND |
||
| 793 | status <> "incomplete" AND |
||
| 794 | session_id = ' . $session_id.' |
||
| 795 | ORDER BY exe_date DESC '; |
||
| 796 | |||
| 797 | $resultLastAttempt = Database::query($sql); |
||
| 798 | $num = Database::num_rows($resultLastAttempt); |
||
| 799 | $showRowspan = false; |
||
| 800 | if ($num > 0) { |
||
| 801 | $linkId = 'link_'.$my_id; |
||
| 802 | if ($extendedAttempt == 1 && |
||
| 803 | $lp_id == $my_lp_id && |
||
| 804 | $lp_item_id == $my_id |
||
| 805 | ) { |
||
| 806 | $showRowspan = true; |
||
| 807 | $correct_test_link = Display::url( |
||
| 808 | Display::return_icon( |
||
| 809 | 'view_less_stats.gif', |
||
| 810 | get_lang('HideAllAttempts') |
||
| 811 | ), |
||
| 812 | api_get_self().'?action=stats'.$my_url_suffix.'&session_id='.$session_id.'&lp_item_id='.$my_id.'#'.$linkId, |
||
| 813 | ['id' => $linkId] |
||
| 814 | ); |
||
| 815 | View Code Duplication | } else { |
|
| 816 | $correct_test_link = Display::url( |
||
| 817 | Display::return_icon( |
||
| 818 | 'view_more_stats.gif', |
||
| 819 | get_lang( |
||
| 820 | 'ShowAllAttemptsByExercise' |
||
| 821 | ) |
||
| 822 | ), |
||
| 823 | api_get_self().'?action=stats&extend_attempt=1'.$my_url_suffix.'&session_id='.$session_id.'&lp_item_id='.$my_id.'#'.$linkId, |
||
| 824 | ['id' => $linkId] |
||
| 825 | ); |
||
| 826 | } |
||
| 827 | } |
||
| 828 | } |
||
| 829 | |||
| 830 | $title = Security::remove_XSS($title); |
||
| 831 | $action = null; |
||
| 832 | if ($type == 'classic') { |
||
| 833 | $action = '<td '.($showRowspan ? 'rowspan="2"' : '').'>'.$correct_test_link.'</td>'; |
||
| 834 | } |
||
| 835 | |||
| 836 | if ($lp_id == $my_lp_id && false) { |
||
| 837 | $output .= '<tr class ='.$oddclass.'> |
||
| 838 | <td>' . $extend_link.'</td> |
||
| 839 | <td colspan="4">' . $title.'</td> |
||
| 840 | <td colspan="2"> </td> |
||
| 841 | <td colspan="2"> </td> |
||
| 842 | <td colspan="2"> </td> |
||
| 843 | '.$action.' |
||
| 844 | </tr>'; |
||
| 845 | $output .= '</tr>'; |
||
| 846 | } else { |
||
| 847 | if ($lp_id == $my_lp_id && $lp_item_id == $my_id) { |
||
| 848 | $output .= "<tr class='$oddclass'>"; |
||
| 849 | } else { |
||
| 850 | $output .= "<tr class='$oddclass'>"; |
||
| 851 | } |
||
| 852 | |||
| 853 | $scoreItem = null; |
||
| 854 | if ($row['item_type'] == 'quiz') { |
||
| 855 | if (!$is_allowed_to_edit && $result_disabled_ext_all) { |
||
| 856 | $scoreItem .= Display::return_icon( |
||
| 857 | 'invisible.gif', |
||
| 858 | get_lang('ResultsHiddenByExerciseSetting') |
||
| 859 | ); |
||
| 860 | } else { |
||
| 861 | $scoreItem .= ExerciseLib::show_score($score, $maxscore, false); |
||
| 862 | } |
||
| 863 | } else { |
||
| 864 | $scoreItem .= $score == 0 ? '/' : ($maxscore == 0 ? $score : $score.'/'.$maxscore); |
||
| 865 | } |
||
| 866 | |||
| 867 | $timeRow = '<td class="lp_time" colspan="2">'.$time.'</td>'; |
||
| 868 | if ($hideTime) { |
||
| 869 | $timeRow = ''; |
||
| 870 | } |
||
| 871 | |||
| 872 | $output .= ' |
||
| 873 | <td>'.$extend_link.'</td> |
||
| 874 | <td colspan="4">' . $title.'</td> |
||
| 875 | <td colspan="2">' . learnpathitem::humanize_status($lesson_status).'</td> |
||
| 876 | <td colspan="2">'.$scoreItem.'</td> |
||
| 877 | '.$timeRow.' |
||
| 878 | '.$action.' |
||
| 879 | '; |
||
| 880 | $output .= '</tr>'; |
||
| 881 | } |
||
| 882 | |||
| 883 | if (!empty($export_csv)) { |
||
| 884 | $temp = array(); |
||
| 885 | $temp[] = api_html_entity_decode($title, ENT_QUOTES); |
||
| 886 | $temp[] = api_html_entity_decode($lesson_status, ENT_QUOTES); |
||
| 887 | |||
| 888 | View Code Duplication | if ($row['item_type'] == 'quiz') { |
|
| 889 | if (!$is_allowed_to_edit && $result_disabled_ext_all) { |
||
| 890 | $temp[] = '/'; |
||
| 891 | } else { |
||
| 892 | $temp[] = ($score == 0 ? '0/'.$maxscore : ($maxscore == 0 ? $score : $score.'/'.float_format($maxscore, 1))); |
||
| 893 | } |
||
| 894 | } else { |
||
| 895 | $temp[] = ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score.'/'.float_format($maxscore, 1))); |
||
| 896 | } |
||
| 897 | |||
| 898 | if ($hideTime === false) { |
||
| 899 | $temp[] = $time; |
||
| 900 | } |
||
| 901 | $csv_content[] = $temp; |
||
| 902 | } |
||
| 903 | } |
||
| 904 | |||
| 905 | $counter++; |
||
| 906 | |||
| 907 | $action = null; |
||
| 908 | if ($type == 'classic') { |
||
| 909 | $action = '<td></td>'; |
||
| 910 | } |
||
| 911 | |||
| 912 | if ($extend_this_attempt || $extend_all) { |
||
| 913 | $list1 = learnpath::get_iv_interactions_array($row['iv_id']); |
||
| 914 | foreach ($list1 as $id => $interaction) { |
||
| 915 | if (($counter % 2) == 0) { |
||
| 916 | $oddclass = 'row_odd'; |
||
| 917 | } else { |
||
| 918 | $oddclass = 'row_even'; |
||
| 919 | } |
||
| 920 | |||
| 921 | $timeRow = '<td class="lp_time">'.$interaction['time'].'</td>'; |
||
| 922 | if ($hideTime) { |
||
| 923 | $timeRow = ''; |
||
| 924 | } |
||
| 925 | |||
| 926 | $output .= '<tr class="'.$oddclass.'"> |
||
| 927 | <td></td> |
||
| 928 | <td></td> |
||
| 929 | <td></td> |
||
| 930 | <td>'.$interaction['order_id'].'</td> |
||
| 931 | <td>'.$interaction['id'].'</td> |
||
| 932 | <td colspan="2">' . $interaction['type'].'</td> |
||
| 933 | <td>'.urldecode($interaction['student_response']).'</td> |
||
| 934 | <td>'.$interaction['result'].'</td> |
||
| 935 | <td>'.$interaction['latency'].'</td> |
||
| 936 | '.$timeRow.' |
||
| 937 | '.$action.' |
||
| 938 | </tr>'; |
||
| 939 | $counter++; |
||
| 940 | } |
||
| 941 | $list2 = learnpath::get_iv_objectives_array($row['iv_id']); |
||
| 942 | View Code Duplication | foreach ($list2 as $id => $interaction) { |
|
| 943 | if (($counter % 2) == 0) { |
||
| 944 | $oddclass = 'row_odd'; |
||
| 945 | } else { |
||
| 946 | $oddclass = 'row_even'; |
||
| 947 | } |
||
| 948 | $output .= '<tr class="'.$oddclass.'"> |
||
| 949 | <td></td> |
||
| 950 | <td></td> |
||
| 951 | <td></td> |
||
| 952 | <td>' . $interaction['order_id'].'</td> |
||
| 953 | <td colspan="2">'.$interaction['objective_id'].'</td> |
||
| 954 | <td colspan="2">' . $interaction['status'].'</td> |
||
| 955 | <td>' . $interaction['score_raw'].'</td> |
||
| 956 | <td>' . $interaction['score_max'].'</td> |
||
| 957 | <td>' . $interaction['score_min'].'</td> |
||
| 958 | '.$action.' |
||
| 959 | </tr>'; |
||
| 960 | $counter++; |
||
| 961 | } |
||
| 962 | } |
||
| 963 | |||
| 964 | // Attempts listing by exercise. |
||
| 965 | if ($lp_id == $my_lp_id && $lp_item_id == $my_id && $extendedAttempt) { |
||
| 966 | // Get attempts of a exercise. |
||
| 967 | if (!empty($lp_id) && |
||
| 968 | !empty($lp_item_id) && |
||
| 969 | $row['item_type'] === 'quiz' |
||
| 970 | ) { |
||
| 971 | $sql = "SELECT path FROM $TBL_LP_ITEM |
||
| 972 | WHERE |
||
| 973 | c_id = $course_id AND |
||
| 974 | id = '$lp_item_id' AND |
||
| 975 | lp_id = '$lp_id'"; |
||
| 976 | $res_path = Database::query($sql); |
||
| 977 | $row_path = Database::fetch_array($res_path); |
||
| 978 | |||
| 979 | if (Database::num_rows($res_path) > 0) { |
||
| 980 | $sql = 'SELECT * FROM '.$tbl_stats_exercices.' |
||
| 981 | WHERE |
||
| 982 | exe_exo_id="' . (int) $row_path['path'].'" AND |
||
| 983 | status <> "incomplete" AND |
||
| 984 | exe_user_id="' . $user_id.'" AND |
||
| 985 | orig_lp_id = "' . (int) $lp_id.'" AND |
||
| 986 | orig_lp_item_id = "' . (int) $lp_item_id.'" AND |
||
| 987 | c_id = ' . $course_id.' AND |
||
| 988 | session_id = ' . $session_id.' |
||
| 989 | ORDER BY exe_date'; |
||
| 990 | $res_attempts = Database::query($sql); |
||
| 991 | $num_attempts = Database::num_rows($res_attempts); |
||
| 992 | if ($num_attempts > 0) { |
||
| 993 | $n = 1; |
||
| 994 | while ($row_attempts = Database::fetch_array($res_attempts)) { |
||
| 995 | $my_score = $row_attempts['exe_result']; |
||
| 996 | $my_maxscore = $row_attempts['exe_weighting']; |
||
| 997 | $my_exe_id = $row_attempts['exe_id']; |
||
| 998 | $my_orig_lp = $row_attempts['orig_lp_id']; |
||
| 999 | $my_orig_lp_item = $row_attempts['orig_lp_item_id']; |
||
| 1000 | $my_exo_exe_id = $row_attempts['exe_exo_id']; |
||
| 1001 | $mktime_start_date = api_strtotime($row_attempts['start_date'], 'UTC'); |
||
| 1002 | $mktime_exe_date = api_strtotime($row_attempts['exe_date'], 'UTC'); |
||
| 1003 | if ($mktime_start_date && $mktime_exe_date) { |
||
| 1004 | $mytime = ((int) $mktime_exe_date - (int) $mktime_start_date); |
||
| 1005 | $time_attemp = learnpathItem::getScormTimeFromParameter('js', $mytime); |
||
| 1006 | $time_attemp = str_replace('NaN', '00'.$h.'00\'00"', $time_attemp); |
||
| 1007 | } else { |
||
| 1008 | $time_attemp = ' - '; |
||
| 1009 | } |
||
| 1010 | if (!$is_allowed_to_edit && $result_disabled_ext_all) { |
||
| 1011 | $view_score = Display::return_icon( |
||
| 1012 | 'invisible.gif', |
||
| 1013 | get_lang( |
||
| 1014 | 'ResultsHiddenByExerciseSetting' |
||
| 1015 | ) |
||
| 1016 | ); |
||
| 1017 | } else { |
||
| 1018 | // Show only float when need it |
||
| 1019 | if ($my_score == 0) { |
||
| 1020 | $view_score = ExerciseLib::show_score( |
||
| 1021 | 0, |
||
| 1022 | $my_maxscore, |
||
| 1023 | false |
||
| 1024 | ); |
||
| 1025 | } else { |
||
| 1026 | if ($my_maxscore == 0) { |
||
| 1027 | $view_score = $my_score; |
||
| 1028 | } else { |
||
| 1029 | $view_score = ExerciseLib::show_score( |
||
| 1030 | $my_score, |
||
| 1031 | $my_maxscore, |
||
| 1032 | false |
||
| 1033 | ); |
||
| 1034 | } |
||
| 1035 | } |
||
| 1036 | } |
||
| 1037 | $my_lesson_status = $row_attempts['status']; |
||
| 1038 | |||
| 1039 | if ($my_lesson_status == '') { |
||
| 1040 | $my_lesson_status = learnpathitem::humanize_status('completed'); |
||
| 1041 | } elseif ($my_lesson_status == 'incomplete') { |
||
| 1042 | $my_lesson_status = learnpathitem::humanize_status('incomplete'); |
||
| 1043 | } |
||
| 1044 | $timeRow = '<td class="lp_time" colspan="2">'.$time_attemp.'</td>'; |
||
| 1045 | if ($hideTime) { |
||
| 1046 | $timeRow = ''; |
||
| 1047 | } |
||
| 1048 | |||
| 1049 | $output .= '<tr class="'.$oddclass.'" > |
||
| 1050 | <td></td> |
||
| 1051 | <td>' . $extend_attempt_link.'</td> |
||
| 1052 | <td colspan="3">' . get_lang('Attempt').' '.$n.'</td> |
||
| 1053 | <td colspan="2">' . $my_lesson_status.'</td> |
||
| 1054 | <td colspan="2">'.$view_score.'</td> |
||
| 1055 | '.$timeRow; |
||
| 1056 | |||
| 1057 | if ($action == 'classic') { |
||
| 1058 | if ($origin != 'tracking') { |
||
| 1059 | if (!$is_allowed_to_edit && $result_disabled_ext_all) { |
||
| 1060 | $output .= '<td> |
||
| 1061 | <img src="'.Display::returnIconPath('quiz_na.gif').'" alt="'.get_lang('ShowAttempt').'" title="'.get_lang('ShowAttempt').'"> |
||
| 1062 | </td>'; |
||
| 1063 | } else { |
||
| 1064 | $output .= '<td> |
||
| 1065 | <a href="../exercise/exercise_show.php?origin=' . $origin.'&id='.$my_exe_id.'&cidReq='.$courseCode.'" target="_parent"> |
||
| 1066 | <img src="'.Display::returnIconPath('quiz.png').'" alt="'.get_lang('ShowAttempt').'" title="'.get_lang('ShowAttempt').'"> |
||
| 1067 | </a></td>'; |
||
| 1068 | } |
||
| 1069 | } else { |
||
| 1070 | if (!$is_allowed_to_edit && $result_disabled_ext_all) { |
||
| 1071 | $output .= '<td> |
||
| 1072 | <img src="'.Display::returnIconPath('quiz_na.gif').'" alt="'.get_lang('ShowAndQualifyAttempt').'" title="'.get_lang('ShowAndQualifyAttempt').'"></td>'; |
||
| 1073 | } else { |
||
| 1074 | $output .= '<td> |
||
| 1075 | <a href="../exercise/exercise_show.php?cidReq=' . $courseCode.'&origin=correct_exercise_in_lp&id='.$my_exe_id.'" target="_parent"> |
||
| 1076 | <img src="'.Display::returnIconPath('quiz.gif').'" alt="'.get_lang('ShowAndQualifyAttempt').'" title="'.get_lang('ShowAndQualifyAttempt').'"></a></td>'; |
||
| 1077 | } |
||
| 1078 | } |
||
| 1079 | } |
||
| 1080 | $output .= '</tr>'; |
||
| 1081 | $n++; |
||
| 1082 | } |
||
| 1083 | } |
||
| 1084 | $output .= '<tr><td colspan="12"> </td></tr>'; |
||
| 1085 | } |
||
| 1086 | } |
||
| 1087 | } |
||
| 1088 | } |
||
| 1089 | |||
| 1090 | $total_time += $time_for_total; |
||
| 1091 | // QUIZZ IN LP |
||
| 1092 | $a_my_id = array(); |
||
| 1093 | if (!empty($my_lp_id)) { |
||
| 1094 | $a_my_id[] = $my_lp_id; |
||
| 1095 | } |
||
| 1096 | } |
||
| 1097 | } |
||
| 1098 | |||
| 1099 | // NOT Extend all "left green cross" |
||
| 1100 | if (!empty($a_my_id)) { |
||
| 1101 | if ($extendedAttempt) { |
||
| 1102 | // "Right green cross" extended |
||
| 1103 | $total_score = self::get_avg_student_score( |
||
| 1104 | $user_id, |
||
| 1105 | $course_id, |
||
| 1106 | $a_my_id, |
||
| 1107 | $session_id, |
||
| 1108 | false, |
||
| 1109 | false |
||
| 1110 | ); |
||
| 1111 | } else { |
||
| 1112 | // "Left green cross" extended |
||
| 1113 | $total_score = self::get_avg_student_score( |
||
| 1114 | $user_id, |
||
| 1115 | $course_id, |
||
| 1116 | $a_my_id, |
||
| 1117 | $session_id, |
||
| 1118 | false, |
||
| 1119 | true |
||
| 1120 | ); |
||
| 1121 | } |
||
| 1122 | } else { |
||
| 1123 | // Extend all "left green cross" |
||
| 1124 | $total_score = self::get_avg_student_score( |
||
| 1125 | $user_id, |
||
| 1126 | $course_id, |
||
| 1127 | array($lp_id), |
||
| 1128 | $session_id, |
||
| 1129 | false, |
||
| 1130 | false |
||
| 1131 | ); |
||
| 1132 | } |
||
| 1133 | |||
| 1134 | $total_time = learnpathItem::getScormTimeFromParameter('js', $total_time); |
||
| 1135 | $total_time = str_replace('NaN', '00'.$h.'00\'00"', $total_time); |
||
| 1136 | |||
| 1137 | if (!$is_allowed_to_edit && $result_disabled_ext_all) { |
||
| 1138 | $final_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting')); |
||
| 1139 | $finalScoreToCsv = get_lang('ResultsHiddenByExerciseSetting'); |
||
| 1140 | } else { |
||
| 1141 | if (is_numeric($total_score)) { |
||
| 1142 | $final_score = $total_score.'%'; |
||
| 1143 | } else { |
||
| 1144 | $final_score = $total_score; |
||
| 1145 | } |
||
| 1146 | $finalScoreToCsv = $final_score; |
||
| 1147 | } |
||
| 1148 | $progress = learnpath::getProgress($lp_id, $user_id, $course_id, $session_id); |
||
| 1149 | |||
| 1150 | if (($counter % 2) == 0) { |
||
| 1151 | $oddclass = 'row_odd'; |
||
| 1152 | } else { |
||
| 1153 | $oddclass = 'row_even'; |
||
| 1154 | } |
||
| 1155 | |||
| 1156 | $action = null; |
||
| 1157 | if ($type == 'classic') { |
||
| 1158 | $action = '<td></td>'; |
||
| 1159 | } |
||
| 1160 | |||
| 1161 | $timeTotal = '<td class="lp_time" colspan="2">'.$total_time.'</div>'; |
||
| 1162 | if ($hideTime) { |
||
| 1163 | $timeTotal = ''; |
||
| 1164 | } |
||
| 1165 | |||
| 1166 | $output .= '<tr class="'.$oddclass.'"> |
||
| 1167 | <td></td> |
||
| 1168 | <td colspan="4"> |
||
| 1169 | <i>' . get_lang('AccomplishedStepsTotal').'</i> |
||
| 1170 | </td> |
||
| 1171 | <td colspan="2">'.$progress.'%</td> |
||
| 1172 | <td colspan="2">' . $final_score.'</td> |
||
| 1173 | '.$timeTotal.' |
||
| 1174 | '.$action.' |
||
| 1175 | </tr>'; |
||
| 1176 | |||
| 1177 | $output .= ' |
||
| 1178 | </tbody> |
||
| 1179 | </table> |
||
| 1180 | </div> |
||
| 1181 | '; |
||
| 1182 | |||
| 1183 | if (!empty($export_csv)) { |
||
| 1184 | $temp = array( |
||
| 1185 | '', |
||
| 1186 | '', |
||
| 1187 | '', |
||
| 1188 | '' |
||
| 1189 | ); |
||
| 1190 | $csv_content[] = $temp; |
||
| 1191 | $temp = array( |
||
| 1192 | get_lang('AccomplishedStepsTotal'), |
||
| 1193 | '', |
||
| 1194 | $finalScoreToCsv |
||
| 1195 | ); |
||
| 1196 | |||
| 1197 | if ($hideTime === false) { |
||
| 1198 | $temp[] = $total_time; |
||
| 1199 | } |
||
| 1200 | |||
| 1201 | $csv_content[] = $temp; |
||
| 1202 | ob_end_clean(); |
||
| 1203 | Export::arrayToCsv($csv_content, 'reporting_learning_path_details'); |
||
| 1204 | exit; |
||
| 1205 | } |
||
| 1206 | |||
| 1207 | return $output; |
||
| 1208 | } |
||
| 1209 | |||
| 1210 | /** |
||
| 1211 | * @param int $userId |
||
| 1212 | * @param bool $getCount |
||
| 1213 | * |
||
| 1214 | * @return array |
||
| 1215 | */ |
||
| 1216 | public static function getStats($userId, $getCount = false) |
||
| 1524 | |||
| 1525 | /** |
||
| 1526 | * Calculates the time spent on the platform by a user |
||
| 1527 | * @param int|array User id |
||
| 1528 | * @param string $timeFilter type of time filter: 'last_week' or 'custom' |
||
| 1529 | * @param string $start_date start date date('Y-m-d H:i:s') |
||
| 1530 | * @param string $end_date end date date('Y-m-d H:i:s') |
||
| 1531 | * |
||
| 1532 | * @return int $nb_seconds |
||
| 1533 | */ |
||
| 1534 | public static function get_time_spent_on_the_platform( |
||
| 1589 | |||
| 1590 | /** |
||
| 1591 | * Calculates the time spent on the course |
||
| 1592 | * @param integer $user_id |
||
| 1593 | * @param integer $courseId |
||
| 1594 | * @param int Session id (optional) |
||
| 1595 | * |
||
| 1596 | * @return int Time in seconds |
||
| 1597 | */ |
||
| 1598 | public static function get_time_spent_on_the_course($user_id, $courseId, $session_id = 0) |
||
| 1630 | |||
| 1631 | /** |
||
| 1632 | * Get first connection date for a student |
||
| 1633 | * @param int $student_id |
||
| 1634 | * |
||
| 1635 | * @return string|bool Date format long without day or false if there are no connections |
||
| 1636 | */ |
||
| 1637 | public static function get_first_connection_date($student_id) |
||
| 1638 | { |
||
| 1639 | $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); |
||
| 1640 | $sql = 'SELECT login_date |
||
| 1641 | FROM '.$table.' |
||
| 1642 | WHERE login_user_id = ' . intval($student_id).' |
||
| 1643 | ORDER BY login_date ASC |
||
| 1644 | LIMIT 0,1'; |
||
| 1645 | |||
| 1646 | $rs = Database::query($sql); |
||
| 1647 | if (Database::num_rows($rs) > 0) { |
||
| 1648 | if ($first_login_date = Database::result($rs, 0, 0)) { |
||
| 1649 | return api_convert_and_format_date( |
||
| 1650 | $first_login_date, |
||
| 1651 | DATE_FORMAT_SHORT, |
||
| 1652 | date_default_timezone_get() |
||
| 1653 | ); |
||
| 1654 | } |
||
| 1655 | } |
||
| 1656 | |||
| 1657 | return false; |
||
| 1658 | } |
||
| 1659 | |||
| 1660 | /** |
||
| 1661 | * Get las connection date for a student |
||
| 1662 | * @param int $student_id |
||
| 1663 | * @param bool $warning_message Show a warning message (optional) |
||
| 1664 | * @param bool $return_timestamp True for returning results in timestamp (optional) |
||
| 1665 | * @return string|int|bool Date format long without day, false if there are no connections or |
||
| 1666 | * timestamp if parameter $return_timestamp is true |
||
| 1667 | */ |
||
| 1668 | public static function get_last_connection_date( |
||
| 1707 | |||
| 1708 | /** |
||
| 1709 | * Get las connection date for a student |
||
| 1710 | * @param array $studentList Student id array |
||
| 1711 | * @param int $days |
||
| 1712 | * @param bool $getCount |
||
| 1713 | * @return int |
||
| 1714 | */ |
||
| 1715 | public static function getInactiveUsers($studentList, $days, $getCount = true) |
||
| 1745 | |||
| 1746 | /** |
||
| 1747 | * Get first user's connection date on the course |
||
| 1748 | * @param int User id |
||
| 1749 | * @param int $courseId |
||
| 1750 | * @param int Session id (optional, default=0) |
||
| 1751 | * @param bool $convert_date |
||
| 1752 | * @return string|bool Date with format long without day or false if there is no date |
||
| 1753 | */ |
||
| 1754 | public static function get_first_connection_date_on_the_course( |
||
| 1789 | |||
| 1790 | /** |
||
| 1791 | * Get last user's connection date on the course |
||
| 1792 | * @param int User id |
||
| 1793 | * @param array $courseInfo real_id and code are used |
||
| 1794 | * @param int Session id (optional, default=0) |
||
| 1795 | * @param bool $convert_date |
||
| 1796 | * @return string|bool Date with format long without day or false if there is no date |
||
| 1797 | */ |
||
| 1798 | public static function get_last_connection_date_on_the_course( |
||
| 1852 | |||
| 1853 | /** |
||
| 1854 | * Get count of the connections to the course during a specified period |
||
| 1855 | * @param int $courseId |
||
| 1856 | * @param int Session id (optional) |
||
| 1857 | * @param int Datetime from which to collect data (defaults to 0) |
||
| 1858 | * @param int Datetime to which to collect data (defaults to now) |
||
| 1859 | * @return int count connections |
||
| 1860 | */ |
||
| 1861 | public static function get_course_connections_count( |
||
| 1923 | |||
| 1924 | /** |
||
| 1925 | * Get count courses per student |
||
| 1926 | * @param int $user_id Student id |
||
| 1927 | * @param bool $include_sessions Include sessions (optional) |
||
| 1928 | * @return int count courses |
||
| 1929 | */ |
||
| 1930 | public static function count_course_per_student($user_id, $include_sessions = true) |
||
| 1952 | |||
| 1953 | /** |
||
| 1954 | * Gets the score average from all tests in a course by student |
||
| 1955 | * |
||
| 1956 | * @param $student_id |
||
| 1957 | * @param $course_code |
||
| 1958 | * @param int $exercise_id |
||
| 1959 | * @param null $session_id |
||
| 1960 | * @param int $active_filter 2 for consider all tests |
||
| 1961 | * 1 for active <> -1 |
||
| 1962 | * 0 for active <> 0 |
||
| 1963 | * @param int $into_lp 1 for all exercises |
||
| 1964 | * 0 for without LP |
||
| 1965 | * @internal param \Student $mixed id |
||
| 1966 | * @internal param \Course $string code |
||
| 1967 | * @internal param \Exercise $int id (optional), filtered by exercise |
||
| 1968 | * @internal param \Session $int id (optional), if param $session_id is null |
||
| 1969 | * it'll return results including sessions, 0 = session is not filtered |
||
| 1970 | * @return string value (number %) Which represents a round integer about the score average. |
||
| 1971 | */ |
||
| 1972 | public static function get_avg_student_exercise_score( |
||
| 2104 | |||
| 2105 | /** |
||
| 2106 | * Get count student's exercise COMPLETED attempts |
||
| 2107 | * @param int $student_id |
||
| 2108 | * @param int $courseId |
||
| 2109 | * @param int $exercise_id |
||
| 2110 | * @param int $lp_id |
||
| 2111 | * @param int $lp_item_id |
||
| 2112 | * @param int $session_id |
||
| 2113 | * @param int $find_all_lp 0 = just LP specified |
||
| 2114 | * 1 = LP specified or whitout LP, |
||
| 2115 | * 2 = all rows |
||
| 2116 | * @internal param \Student $int id |
||
| 2117 | * @internal param \Course $string code |
||
| 2118 | * @internal param \Exercise $int id |
||
| 2119 | * @internal param \Learning $int path id (optional), |
||
| 2120 | * for showing attempts inside a learning path $lp_id and $lp_item_id params are required. |
||
| 2121 | * @internal param \Learning $int path item id (optional), |
||
| 2122 | * for showing attempts inside a learning path $lp_id and $lp_item_id params are required. |
||
| 2123 | * @return int count of attempts |
||
| 2124 | */ |
||
| 2125 | public static function count_student_exercise_attempts( |
||
| 2166 | |||
| 2167 | /** |
||
| 2168 | * Get count student's exercise progress |
||
| 2169 | * |
||
| 2170 | * @param array $exercise_list |
||
| 2171 | * @param int $user_id |
||
| 2172 | * @param int $courseId |
||
| 2173 | * @param int $session_id |
||
| 2174 | * |
||
| 2175 | * @return string |
||
| 2176 | */ |
||
| 2177 | public static function get_exercise_student_progress( |
||
| 2213 | |||
| 2214 | /** |
||
| 2215 | * @param array $exercise_list |
||
| 2216 | * @param int $user_id |
||
| 2217 | * @param int $courseId |
||
| 2218 | * @param int $session_id |
||
| 2219 | * @return string |
||
| 2220 | */ |
||
| 2221 | View Code Duplication | public static function get_exercise_student_average_best_attempt( |
|
| 2248 | |||
| 2249 | /** |
||
| 2250 | * get teacher progress by course and session |
||
| 2251 | * @param int course id |
||
| 2252 | * @param int session id |
||
| 2253 | * @return array |
||
| 2254 | */ |
||
| 2255 | static function get_teachers_progress_by_course($courseId, $sessionId) |
||
| 2422 | |||
| 2423 | /** |
||
| 2424 | * Returns the average student progress in the learning paths of the given |
||
| 2425 | * course, it will take into account the progress that were not started. |
||
| 2426 | * @param int|array $studentId |
||
| 2427 | * @param string $courseCode |
||
| 2428 | * @param array $lpIdList Limit average to listed lp ids |
||
| 2429 | * @param int $sessionId Session id (optional), |
||
| 2430 | * if parameter $session_id is null(default) it'll return results including |
||
| 2431 | * sessions, 0 = session is not filtered |
||
| 2432 | * @param bool $returnArray Will return an array of the type: |
||
| 2433 | * [sum_of_progresses, number] if it is set to true |
||
| 2434 | * @param boolean $onlySeriousGame Optional. Limit average to lp on seriousgame mode |
||
| 2435 | * @return double Average progress of the user in this course |
||
| 2436 | */ |
||
| 2437 | public static function get_avg_student_progress( |
||
| 2576 | |||
| 2577 | /** |
||
| 2578 | * This function gets: |
||
| 2579 | * 1. The score average from all SCORM Test items in all LP in a course-> All the answers / All the max scores. |
||
| 2580 | * 2. The score average from all Tests (quiz) in all LP in a course-> All the answers / All the max scores. |
||
| 2581 | * 3. And finally it will return the average between 1. and 2. |
||
| 2582 | * @todo improve performance, when loading 1500 users with 20 lps the script dies |
||
| 2583 | * This function does not take the results of a Test out of a LP |
||
| 2584 | * |
||
| 2585 | * @param mixed $student_id Array of user ids or an user id |
||
| 2586 | * @param string $course_code |
||
| 2587 | * @param array $lp_ids List of LP ids |
||
| 2588 | * @param int $session_id Session id (optional), |
||
| 2589 | * if param $session_id is null(default) it'll return results |
||
| 2590 | * including sessions, 0 = session is not filtered |
||
| 2591 | * @param bool $return_array Returns an array of the |
||
| 2592 | * type [sum_score, num_score] if set to true |
||
| 2593 | * @param bool $get_only_latest_attempt_results get only the latest attempts or ALL attempts |
||
| 2594 | * @param bool $getOnlyBestAttempt |
||
| 2595 | * |
||
| 2596 | * @return string Value (number %) Which represents a round integer explain in got in 3. |
||
| 2597 | */ |
||
| 2598 | public static function get_avg_student_score( |
||
| 2960 | |||
| 2961 | /** |
||
| 2962 | * This function gets: |
||
| 2963 | * 1. The score average from all SCORM Test items in all LP in a course-> All the answers / All the max scores. |
||
| 2964 | * 2. The score average from all Tests (quiz) in all LP in a course-> All the answers / All the max scores. |
||
| 2965 | * 3. And finally it will return the average between 1. and 2. |
||
| 2966 | * This function does not take the results of a Test out of a LP |
||
| 2967 | * |
||
| 2968 | * @param int|array Array of user ids or an user id |
||
| 2969 | * @param string $course_code Course code |
||
| 2970 | * @param array $lp_ids List of LP ids |
||
| 2971 | * @param int $session_id Session id (optional), if param $session_id is 0(default) |
||
| 2972 | * it'll return results including sessions, 0 = session is not filtered |
||
| 2973 | * @param bool Returns an array of the type [sum_score, num_score] if set to true |
||
| 2974 | * @param bool get only the latest attempts or ALL attempts |
||
| 2975 | * @return string Value (number %) Which represents a round integer explain in got in 3. |
||
| 2976 | */ |
||
| 2977 | public static function getAverageStudentScore( |
||
| 3041 | |||
| 3042 | /** |
||
| 3043 | * This function gets time spent in learning path for a student inside a course |
||
| 3044 | * @param int|array $student_id Student id(s) |
||
| 3045 | * @param string $course_code Course code |
||
| 3046 | * @param array $lp_ids Limit average to listed lp ids |
||
| 3047 | * @param int $session_id Session id (optional), if param $session_id is null(default) |
||
| 3048 | * it'll return results including sessions, 0 = session is not filtered |
||
| 3049 | * @return int Total time |
||
| 3050 | */ |
||
| 3051 | public static function get_time_spent_in_lp( |
||
| 3109 | |||
| 3110 | /** |
||
| 3111 | * This function gets last connection time to one learning path |
||
| 3112 | * @param int|array $student_id Student id(s) |
||
| 3113 | * @param string $course_code Course code |
||
| 3114 | * @param int $lp_id Learning path id |
||
| 3115 | * @param int $session_id |
||
| 3116 | * @return int Total time |
||
| 3117 | */ |
||
| 3118 | public static function get_last_connection_time_in_lp( |
||
| 3164 | |||
| 3165 | /** |
||
| 3166 | * gets the list of students followed by coach |
||
| 3167 | * @param int $coach_id Coach id |
||
| 3168 | * @return array List of students |
||
| 3169 | */ |
||
| 3170 | public static function get_student_followed_by_coach($coach_id) |
||
| 3261 | |||
| 3262 | /** |
||
| 3263 | * Get student followed by a coach inside a session |
||
| 3264 | * @param int Session id |
||
| 3265 | * @param int Coach id |
||
| 3266 | * @return array students list |
||
| 3267 | */ |
||
| 3268 | public static function get_student_followed_by_coach_in_a_session( |
||
| 3313 | |||
| 3314 | /** |
||
| 3315 | * Check if a coach is allowed to follow a student |
||
| 3316 | * @param int Coach id |
||
| 3317 | * @param int Student id |
||
| 3318 | * @return bool |
||
| 3319 | */ |
||
| 3320 | public static function is_allowed_to_coach_student($coach_id, $student_id) |
||
| 3354 | |||
| 3355 | /** |
||
| 3356 | * Get courses followed by coach |
||
| 3357 | * @param int Coach id |
||
| 3358 | * @param int Session id (optional) |
||
| 3359 | * @return array Courses list |
||
| 3360 | */ |
||
| 3361 | public static function get_courses_followed_by_coach($coach_id, $id_session = 0) |
||
| 3451 | |||
| 3452 | /** |
||
| 3453 | * Get sessions coached by user |
||
| 3454 | * @param $coach_id |
||
| 3455 | * @param int $start |
||
| 3456 | * @param int $limit |
||
| 3457 | * @param bool $getCount |
||
| 3458 | * @param string $keyword |
||
| 3459 | * @param string $description |
||
| 3460 | * @return mixed |
||
| 3461 | */ |
||
| 3462 | public static function get_sessions_coached_by_user( |
||
| 3463 | $coach_id, |
||
| 3464 | $start = 0, |
||
| 3465 | $limit = 0, |
||
| 3466 | $getCount = false, |
||
| 3467 | $keyword = '', |
||
| 3468 | $description = '' |
||
| 3469 | ) { |
||
| 3470 | // table definition |
||
| 3471 | $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); |
||
| 3472 | $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); |
||
| 3473 | $coach_id = intval($coach_id); |
||
| 3474 | |||
| 3475 | $select = " SELECT * FROM "; |
||
| 3476 | if ($getCount) { |
||
| 3477 | $select = " SELECT count(DISTINCT id) as count FROM "; |
||
| 3478 | } |
||
| 3479 | |||
| 3480 | $limitCondition = null; |
||
| 3481 | View Code Duplication | if (!empty($start) && !empty($limit)) { |
|
| 3482 | $limitCondition = " LIMIT ".intval($start).", ".intval($limit); |
||
| 3483 | } |
||
| 3484 | |||
| 3485 | $keywordCondition = null; |
||
| 3486 | |||
| 3487 | View Code Duplication | if (!empty($keyword)) { |
|
| 3488 | $keyword = Database::escape_string($keyword); |
||
| 3489 | $keywordCondition = " AND (name LIKE '%$keyword%' ) "; |
||
| 3490 | |||
| 3491 | if (!empty($description)) { |
||
| 3492 | $description = Database::escape_string($description); |
||
| 3493 | $keywordCondition = " AND (name LIKE '%$keyword%' OR description LIKE '%$description%' ) "; |
||
| 3494 | } |
||
| 3495 | } |
||
| 3496 | |||
| 3497 | $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
||
| 3498 | $access_url_id = api_get_current_access_url_id(); |
||
| 3499 | |||
| 3500 | $sql = " |
||
| 3501 | $select |
||
| 3502 | ( |
||
| 3503 | SELECT DISTINCT |
||
| 3504 | id, |
||
| 3505 | name, |
||
| 3506 | access_start_date, |
||
| 3507 | access_end_date |
||
| 3508 | FROM $tbl_session session |
||
| 3509 | INNER JOIN $tbl_session_rel_access_url session_rel_url |
||
| 3510 | ON (session.id = session_rel_url.session_id) |
||
| 3511 | WHERE |
||
| 3512 | id_coach = $coach_id AND |
||
| 3513 | access_url_id = $access_url_id |
||
| 3514 | $keywordCondition |
||
| 3515 | UNION |
||
| 3516 | SELECT DISTINCT |
||
| 3517 | session.id, |
||
| 3518 | session.name, |
||
| 3519 | session.access_start_date, |
||
| 3520 | session.access_end_date |
||
| 3521 | FROM $tbl_session as session |
||
| 3522 | INNER JOIN $tbl_session_course_user as session_course_user |
||
| 3523 | ON |
||
| 3524 | session.id = session_course_user.session_id AND |
||
| 3525 | session_course_user.user_id = $coach_id AND |
||
| 3526 | session_course_user.status = 2 |
||
| 3527 | INNER JOIN $tbl_session_rel_access_url session_rel_url |
||
| 3528 | ON (session.id = session_rel_url.session_id) |
||
| 3529 | WHERE |
||
| 3530 | access_url_id = $access_url_id |
||
| 3531 | $keywordCondition |
||
| 3532 | ) as sessions $limitCondition |
||
| 3533 | "; |
||
| 3534 | |||
| 3535 | $rs = Database::query($sql); |
||
| 3536 | if ($getCount) { |
||
| 3537 | $row = Database::fetch_array($rs); |
||
| 3538 | return $row['count']; |
||
| 3539 | } |
||
| 3540 | |||
| 3541 | $sessions = []; |
||
| 3542 | while ($row = Database::fetch_array($rs)) { |
||
| 3543 | if ($row['access_start_date'] == '0000-00-00 00:00:00') { |
||
| 3544 | $row['access_start_date'] = null; |
||
| 3545 | } |
||
| 3546 | |||
| 3547 | $sessions[$row['id']] = $row; |
||
| 3548 | } |
||
| 3549 | |||
| 3550 | if (!empty($sessions)) { |
||
| 3551 | foreach ($sessions as & $session) { |
||
| 3552 | if (empty($session['access_start_date']) |
||
| 3553 | ) { |
||
| 3554 | $session['status'] = get_lang('SessionActive'); |
||
| 3555 | } |
||
| 3556 | else { |
||
| 3557 | $time_start = api_strtotime($session['access_start_date'], 'UTC'); |
||
| 3558 | $time_end = api_strtotime($session['access_end_date'], 'UTC'); |
||
| 3559 | if ($time_start < time() && time() < $time_end) { |
||
| 3560 | $session['status'] = get_lang('SessionActive'); |
||
| 3561 | } else { |
||
| 3562 | if (time() < $time_start) { |
||
| 3563 | $session['status'] = get_lang('SessionFuture'); |
||
| 3564 | } else { |
||
| 3565 | if (time() > $time_end) { |
||
| 3566 | $session['status'] = get_lang('SessionPast'); |
||
| 3567 | } |
||
| 3568 | } |
||
| 3569 | } |
||
| 3570 | } |
||
| 3571 | } |
||
| 3572 | } |
||
| 3573 | |||
| 3574 | return $sessions; |
||
| 3575 | } |
||
| 3576 | |||
| 3577 | /** |
||
| 3578 | * Get courses list from a session |
||
| 3579 | * @param int Session id |
||
| 3580 | * @return array Courses list |
||
| 3581 | */ |
||
| 3582 | View Code Duplication | public static function get_courses_list_from_session($session_id) |
|
| 3583 | { |
||
| 3584 | $session_id = intval($session_id); |
||
| 3585 | |||
| 3586 | // table definition |
||
| 3587 | $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); |
||
| 3588 | $courseTable = Database::get_main_table(TABLE_MAIN_COURSE); |
||
| 3589 | |||
| 3590 | $sql = "SELECT DISTINCT code, c_id |
||
| 3591 | FROM $tbl_session_course sc |
||
| 3592 | INNER JOIN $courseTable c |
||
| 3593 | ON sc.c_id = c.id |
||
| 3594 | WHERE session_id= $session_id"; |
||
| 3595 | |||
| 3596 | $result = Database::query($sql); |
||
| 3597 | |||
| 3598 | $courses = array(); |
||
| 3599 | while ($row = Database::fetch_array($result)) { |
||
| 3600 | $courses[$row['code']] = $row; |
||
| 3601 | } |
||
| 3602 | |||
| 3603 | return $courses; |
||
| 3604 | } |
||
| 3605 | |||
| 3606 | /** |
||
| 3607 | * Count the number of documents that an user has uploaded to a course |
||
| 3608 | * @param int|array Student id(s) |
||
| 3609 | * @param string Course code |
||
| 3610 | * @param int Session id (optional), |
||
| 3611 | * if param $session_id is null(default) |
||
| 3612 | * return count of assignments including sessions, 0 = session is not filtered |
||
| 3613 | * @return int Number of documents |
||
| 3614 | */ |
||
| 3615 | public static function count_student_uploaded_documents($student_id, $course_code, $session_id = null) |
||
| 3654 | |||
| 3655 | /** |
||
| 3656 | * Count assignments per student |
||
| 3657 | * @param $student_id |
||
| 3658 | * @param null $course_code |
||
| 3659 | * @param null $session_id |
||
| 3660 | * @return int Count of assignments |
||
| 3661 | * @internal param array|int $Student id(s) |
||
| 3662 | * @internal param Course $string code |
||
| 3663 | * @internal param Session $int id (optional), |
||
| 3664 | * if param $session_id is null(default) return count of assignments |
||
| 3665 | * including sessions, 0 = session is not filtered |
||
| 3666 | */ |
||
| 3667 | public static function count_student_assignments($student_id, $course_code = null, $session_id = null) |
||
| 3714 | |||
| 3715 | /** |
||
| 3716 | * Count messages per student inside forum tool |
||
| 3717 | * @param int|array Student id |
||
| 3718 | * @param string Course code |
||
| 3719 | * @param int Session id (optional), if param $session_id is |
||
| 3720 | * null(default) return count of messages including sessions, 0 = session is not filtered |
||
| 3721 | * @return int Count of messages |
||
| 3722 | */ |
||
| 3723 | public static function count_student_messages($student_id, $courseCode = null, $session_id = null) |
||
| 3724 | { |
||
| 3725 | if (empty($student_id)) { |
||
| 3726 | return 0; |
||
| 3727 | } |
||
| 3728 | |||
| 3729 | // Table definition. |
||
| 3730 | $tbl_forum_post = Database::get_course_table(TABLE_FORUM_POST); |
||
| 3731 | $tbl_forum = Database::get_course_table(TABLE_FORUM); |
||
| 3732 | |||
| 3733 | $conditions = array(); |
||
| 3734 | View Code Duplication | if (is_array($student_id)) { |
|
| 3735 | $studentList = array_map('intval', $student_id); |
||
| 3736 | $conditions[] = " post.poster_id IN ('".implode("','", $studentList)."') "; |
||
| 3737 | } else { |
||
| 3738 | $student_id = intval($student_id); |
||
| 3739 | $conditions[] = " post.poster_id = '$student_id' "; |
||
| 3740 | } |
||
| 3741 | |||
| 3742 | $conditionsToString = implode('AND ', $conditions); |
||
| 3743 | |||
| 3744 | if (empty($courseCode)) { |
||
| 3745 | $sql = "SELECT count(poster_id) as count |
||
| 3746 | FROM $tbl_forum_post post |
||
| 3747 | INNER JOIN $tbl_forum forum |
||
| 3748 | ON (forum.forum_id = post.forum_id AND forum.c_id = post.c_id) |
||
| 3749 | WHERE $conditionsToString"; |
||
| 3750 | |||
| 3751 | $rs = Database::query($sql); |
||
| 3752 | $row = Database::fetch_array($rs, 'ASSOC'); |
||
| 3753 | return $row['count']; |
||
| 3754 | } |
||
| 3755 | |||
| 3756 | require_once api_get_path(SYS_CODE_PATH).'forum/forumconfig.inc.php'; |
||
| 3757 | require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; |
||
| 3758 | |||
| 3759 | $courseInfo = api_get_course_info($courseCode); |
||
| 3760 | |||
| 3761 | $forums = []; |
||
| 3762 | if (!empty($courseInfo)) { |
||
| 3763 | $forums = get_forums('', $courseCode, true, $session_id); |
||
| 3764 | $course_id = $courseInfo['real_id']; |
||
| 3765 | $conditions[] = " post.c_id = $course_id "; |
||
| 3766 | } |
||
| 3767 | |||
| 3768 | if (!empty($forums)) { |
||
| 3769 | $idList = array_column($forums, 'forum_id'); |
||
| 3770 | $idListToString = implode("', '", $idList); |
||
| 3771 | $conditions[] = " post.forum_id IN ('$idListToString')"; |
||
| 3772 | } |
||
| 3773 | |||
| 3774 | $conditionsToString = implode('AND ', $conditions); |
||
| 3775 | $sql = "SELECT count(poster_id) as count |
||
| 3776 | FROM $tbl_forum_post post |
||
| 3777 | WHERE $conditionsToString"; |
||
| 3778 | |||
| 3779 | $rs = Database::query($sql); |
||
| 3780 | $row = Database::fetch_array($rs, 'ASSOC'); |
||
| 3781 | $count = $row['count']; |
||
| 3782 | |||
| 3783 | return $count; |
||
| 3784 | } |
||
| 3785 | |||
| 3786 | /** |
||
| 3787 | * This function counts the number of post by course |
||
| 3788 | * @param string Course code |
||
| 3789 | * @param int Session id (optional), if param $session_id is |
||
| 3790 | * null(default) it'll return results including sessions, |
||
| 3791 | * 0 = session is not filtered |
||
| 3792 | * @param int $groupId |
||
| 3793 | * @return int The number of post by course |
||
| 3794 | */ |
||
| 3795 | View Code Duplication | public static function count_number_of_posts_by_course($course_code, $session_id = null, $groupId = 0) |
|
| 3842 | |||
| 3843 | /** |
||
| 3844 | * This function counts the number of threads by course |
||
| 3845 | * @param string Course code |
||
| 3846 | * @param int Session id (optional), |
||
| 3847 | * if param $session_id is null(default) it'll return results including |
||
| 3848 | * sessions, 0 = session is not filtered |
||
| 3849 | * @param int $groupId |
||
| 3850 | * @return int The number of threads by course |
||
| 3851 | */ |
||
| 3852 | View Code Duplication | public static function count_number_of_threads_by_course($course_code, $session_id = null, $groupId = 0) |
|
| 3906 | |||
| 3907 | /** |
||
| 3908 | * This function counts the number of forums by course |
||
| 3909 | * @param string Course code |
||
| 3910 | * @param int Session id (optional), |
||
| 3911 | * if param $session_id is null(default) it'll return results |
||
| 3912 | * including sessions, 0 = session is not filtered |
||
| 3913 | * @param int $groupId |
||
| 3914 | * @return int The number of forums by course |
||
| 3915 | */ |
||
| 3916 | public static function count_number_of_forums_by_course($course_code, $session_id = null, $groupId = 0) |
||
| 3958 | |||
| 3959 | /** |
||
| 3960 | * This function counts the chat last connections by course in x days |
||
| 3961 | * @param string Course code |
||
| 3962 | * @param int Last x days |
||
| 3963 | * @param int Session id (optional) |
||
| 3964 | * @return int Chat last connections by course in x days |
||
| 3965 | */ |
||
| 3966 | public static function chat_connections_during_last_x_days_by_course($course_code, $last_days, $session_id = 0) |
||
| 3995 | |||
| 3996 | /** |
||
| 3997 | * This function gets the last student's connection in chat |
||
| 3998 | * @param int Student id |
||
| 3999 | * @param string Course code |
||
| 4000 | * @param int Session id (optional) |
||
| 4001 | * @return string datetime formatted without day (e.g: February 23, 2010 10:20:50 ) |
||
| 4002 | */ |
||
| 4003 | public static function chat_last_connection($student_id, $courseId, $session_id = 0) |
||
| 4004 | { |
||
| 4005 | $student_id = intval($student_id); |
||
| 4006 | $courseId = intval($courseId); |
||
| 4007 | $session_id = intval($session_id); |
||
| 4008 | $date_time = ''; |
||
| 4009 | |||
| 4010 | // table definition |
||
| 4011 | $tbl_stats_access = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS); |
||
| 4012 | $sql = "SELECT access_date |
||
| 4013 | FROM $tbl_stats_access |
||
| 4014 | WHERE |
||
| 4015 | access_tool='".TOOL_CHAT."' AND |
||
| 4016 | access_user_id='$student_id' AND |
||
| 4017 | c_id = $courseId AND |
||
| 4018 | access_session_id = '$session_id' |
||
| 4019 | ORDER BY access_date DESC limit 1"; |
||
| 4020 | $rs = Database::query($sql); |
||
| 4021 | if (Database::num_rows($rs) > 0) { |
||
| 4022 | $row = Database::fetch_array($rs); |
||
| 4023 | $date_time = api_convert_and_format_date( |
||
| 4024 | $row['access_date'], |
||
| 4025 | null, |
||
| 4026 | date_default_timezone_get() |
||
| 4027 | ); |
||
| 4028 | } |
||
| 4029 | return $date_time; |
||
| 4030 | } |
||
| 4031 | |||
| 4032 | /** |
||
| 4033 | * Get count student's visited links |
||
| 4034 | * @param int $student_id Student id |
||
| 4035 | * @param int $courseId |
||
| 4036 | * @param int $session_id Session id (optional) |
||
| 4037 | * @return int count of visited links |
||
| 4038 | */ |
||
| 4039 | View Code Duplication | public static function count_student_visited_links($student_id, $courseId, $session_id = 0) |
|
| 4058 | |||
| 4059 | /** |
||
| 4060 | * Get count student downloaded documents |
||
| 4061 | * @param int Student id |
||
| 4062 | * @param int $courseId |
||
| 4063 | * @param int Session id (optional) |
||
| 4064 | * @return int Count downloaded documents |
||
| 4065 | */ |
||
| 4066 | View Code Duplication | public static function count_student_downloaded_documents($student_id, $courseId, $session_id = 0) |
|
| 4084 | |||
| 4085 | /** |
||
| 4086 | * Get course list inside a session from a student |
||
| 4087 | * @param int $user_id Student id |
||
| 4088 | * @param int $id_session Session id (optional) |
||
| 4089 | * @return array Courses list |
||
| 4090 | */ |
||
| 4091 | public static function get_course_list_in_session_from_student($user_id, $id_session = 0) |
||
| 4112 | |||
| 4113 | /** |
||
| 4114 | * Get inactive students in course |
||
| 4115 | * @param int $courseId |
||
| 4116 | * @param string|int $since Since login course date (optional, default = 'never') |
||
| 4117 | * @param int $session_id (optional) |
||
| 4118 | * @return array Inactive users |
||
| 4119 | */ |
||
| 4120 | public static function getInactiveStudentsInCourse( |
||
| 4195 | |||
| 4196 | /** |
||
| 4197 | * Get count login per student |
||
| 4198 | * @param int $student_id Student id |
||
| 4199 | * @param int $courseId |
||
| 4200 | * @param int $session_id Session id (optional) |
||
| 4201 | * @return int count login |
||
| 4202 | */ |
||
| 4203 | public static function count_login_per_student($student_id, $courseId, $session_id = 0) |
||
| 4222 | |||
| 4223 | /** |
||
| 4224 | * Get students followed by a human resources manager |
||
| 4225 | * @param int Drh id |
||
| 4226 | * @return array Student list |
||
| 4227 | */ |
||
| 4228 | View Code Duplication | public static function get_student_followed_by_drh($hr_dept_id) |
|
| 4244 | |||
| 4245 | |||
| 4246 | |||
| 4247 | /** |
||
| 4248 | * get count clicks about tools most used by course |
||
| 4249 | * @param int $courseId |
||
| 4250 | * @param int Session id (optional), |
||
| 4251 | * if param $session_id is null(default) it'll return results |
||
| 4252 | * including sessions, 0 = session is not filtered |
||
| 4253 | * @return array tools data |
||
| 4254 | */ |
||
| 4255 | public static function get_tools_most_used_by_course($courseId, $session_id = null) |
||
| 4286 | |||
| 4287 | /** |
||
| 4288 | * Get total clicks |
||
| 4289 | * THIS FUNCTION IS NOT BEEN USED, IT WAS MEANT TO BE USE WITH track_e_course_access.date_from and track_e_course_access.date_to, |
||
| 4290 | * BUT NO ROW MATCH THE CONDITION, IT SHOULD BE FINE TO USE IT WHEN YOU USE USER DEFINED DATES AND NO CHAMILO DATES |
||
| 4291 | * @param int User Id |
||
| 4292 | * @param int Course Id |
||
| 4293 | * @param int Session Id (optional), if param $session_id is 0 (default) it'll return results including sessions, 0 = session is not filtered |
||
| 4294 | * @param string Date from |
||
| 4295 | * @param string Date to |
||
| 4296 | * @return array Data |
||
| 4297 | * @author César Perales [email protected] 2014-01-16 |
||
| 4298 | */ |
||
| 4299 | public static function get_total_clicks($userId, $courseId, $sessionId = 0, $date_from = '', $date_to = '') |
||
| 4412 | |||
| 4413 | /** |
||
| 4414 | * get documents most downloaded by course |
||
| 4415 | * @param string Course code |
||
| 4416 | * @param int Session id (optional), |
||
| 4417 | * if param $session_id is null(default) it'll return results including |
||
| 4418 | * sessions, 0 = session is not filtered |
||
| 4419 | * @param int Limit (optional, default = 0, 0 = without limit) |
||
| 4420 | * @return array documents downloaded |
||
| 4421 | */ |
||
| 4422 | public static function get_documents_most_downloaded_by_course($course_code, $session_id = 0, $limit = 0) |
||
| 4453 | |||
| 4454 | /** |
||
| 4455 | * get links most visited by course |
||
| 4456 | * @param string Course code |
||
| 4457 | * @param int Session id (optional), |
||
| 4458 | * if param $session_id is null(default) it'll |
||
| 4459 | * return results including sessions, 0 = session is not filtered |
||
| 4460 | * @return array links most visited |
||
| 4461 | */ |
||
| 4462 | public static function get_links_most_visited_by_course($course_code, $session_id = null) |
||
| 4496 | |||
| 4497 | /** |
||
| 4498 | * Shows the user progress (when clicking in the Progress tab) |
||
| 4499 | * |
||
| 4500 | * @param int $user_id |
||
| 4501 | * @param int $session_id |
||
| 4502 | * @param string $extra_params |
||
| 4503 | * @param bool $show_courses |
||
| 4504 | * @param bool $showAllSessions |
||
| 4505 | * |
||
| 4506 | * @return string |
||
| 4507 | */ |
||
| 4508 | public static function show_user_progress( |
||
| 4509 | $user_id, |
||
| 4510 | $session_id = 0, |
||
| 4511 | $extra_params = '', |
||
| 4512 | $show_courses = true, |
||
| 4513 | $showAllSessions = true |
||
| 4514 | ) { |
||
| 4515 | $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); |
||
| 4516 | $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); |
||
| 4517 | $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); |
||
| 4518 | $tbl_access_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
||
| 4519 | $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); |
||
| 4520 | $tbl_access_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
||
| 4521 | |||
| 4522 | $trackingColumns = [ |
||
| 4523 | 'course_session' => [ |
||
| 4524 | 'course_title' => true, |
||
| 4525 | 'published_exercises' => true, |
||
| 4526 | 'new_exercises' => true, |
||
| 4527 | 'my_average' => true, |
||
| 4528 | 'average_exercise_result' => true, |
||
| 4529 | 'time_spent' => true, |
||
| 4530 | 'lp_progress' => true, |
||
| 4531 | 'score' => true, |
||
| 4532 | 'best_score' => true, |
||
| 4533 | 'last_connection' => true, |
||
| 4534 | 'details' => true, |
||
| 4535 | ], |
||
| 4536 | ]; |
||
| 4537 | |||
| 4538 | $trackingColumnsConfig = api_get_configuration_value('tracking_columns'); |
||
| 4539 | if (!empty($trackingColumnsConfig)) { |
||
| 4540 | $trackingColumns = $trackingColumnsConfig; |
||
| 4541 | } |
||
| 4542 | |||
| 4543 | $user_id = intval($user_id); |
||
| 4544 | $session_id = intval($session_id); |
||
| 4545 | $urlId = api_get_current_access_url_id(); |
||
| 4546 | |||
| 4547 | if (api_is_multiple_url_enabled()) { |
||
| 4548 | $sql = "SELECT c.code, title |
||
| 4549 | FROM $tbl_course_user cu |
||
| 4550 | INNER JOIN $tbl_course c |
||
| 4551 | ON (cu.c_id = c.id) |
||
| 4552 | INNER JOIN $tbl_access_rel_course a |
||
| 4553 | ON (a.c_id = c.id) |
||
| 4554 | WHERE |
||
| 4555 | cu.user_id = $user_id AND |
||
| 4556 | relation_type<> ".COURSE_RELATION_TYPE_RRHH." AND |
||
| 4557 | access_url_id = ".$urlId." |
||
| 4558 | ORDER BY title"; |
||
| 4559 | } else { |
||
| 4560 | $sql = "SELECT c.code, title |
||
| 4561 | FROM $tbl_course_user u |
||
| 4562 | INNER JOIN $tbl_course c ON (c_id = c.id) |
||
| 4563 | WHERE |
||
| 4564 | u.user_id= $user_id AND |
||
| 4565 | relation_type<>".COURSE_RELATION_TYPE_RRHH." |
||
| 4566 | ORDER BY title"; |
||
| 4567 | } |
||
| 4568 | |||
| 4569 | $rs = Database::query($sql); |
||
| 4570 | $courses = $course_in_session = $temp_course_in_session = array(); |
||
| 4571 | while ($row = Database::fetch_array($rs, 'ASSOC')) { |
||
| 4572 | $courses[$row['code']] = $row['title']; |
||
| 4573 | } |
||
| 4574 | |||
| 4575 | $orderBy = " ORDER BY name "; |
||
| 4576 | $extraInnerJoin = null; |
||
| 4577 | |||
| 4578 | if (SessionManager::orderCourseIsEnabled() && !empty($session_id)) { |
||
| 4579 | $orderBy = " ORDER BY s.id, position "; |
||
| 4580 | $tableSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); |
||
| 4581 | $extraInnerJoin = " INNER JOIN $tableSessionRelCourse src |
||
| 4582 | ON (cu.c_id = src.c_id AND src.session_id = $session_id) "; |
||
| 4583 | } |
||
| 4584 | |||
| 4585 | $sessionCondition = ''; |
||
| 4586 | if (!empty($session_id)) { |
||
| 4587 | $sessionCondition = " AND s.id = $session_id"; |
||
| 4588 | } |
||
| 4589 | |||
| 4590 | // Get the list of sessions where the user is subscribed as student |
||
| 4591 | if (api_is_multiple_url_enabled()) { |
||
| 4592 | $sql = "SELECT DISTINCT c.code, s.id as session_id, name |
||
| 4593 | FROM $tbl_session_course_user cu |
||
| 4594 | INNER JOIN $tbl_access_rel_session a |
||
| 4595 | ON (a.session_id = cu.session_id) |
||
| 4596 | INNER JOIN $tbl_session s |
||
| 4597 | ON (s.id = a.session_id) |
||
| 4598 | INNER JOIN $tbl_course c |
||
| 4599 | ON (c.id = cu.c_id) |
||
| 4600 | $extraInnerJoin |
||
| 4601 | WHERE |
||
| 4602 | cu.user_id = $user_id AND |
||
| 4603 | access_url_id = ".$urlId." |
||
| 4604 | $sessionCondition |
||
| 4605 | $orderBy "; |
||
| 4606 | } else { |
||
| 4607 | $sql = "SELECT DISTINCT c.code, s.id as session_id, name |
||
| 4608 | FROM $tbl_session_course_user cu |
||
| 4609 | INNER JOIN $tbl_session s |
||
| 4610 | ON (s.id = cu.session_id) |
||
| 4611 | INNER JOIN $tbl_course c |
||
| 4612 | ON (c.id = cu.c_id) |
||
| 4613 | $extraInnerJoin |
||
| 4614 | WHERE |
||
| 4615 | cu.user_id = $user_id |
||
| 4616 | $sessionCondition |
||
| 4617 | $orderBy "; |
||
| 4618 | } |
||
| 4619 | |||
| 4620 | $rs = Database::query($sql); |
||
| 4621 | $simple_session_array = array(); |
||
| 4622 | while ($row = Database::fetch_array($rs, 'ASSOC')) { |
||
| 4623 | $course_info = api_get_course_info($row['code']); |
||
| 4624 | $temp_course_in_session[$row['session_id']]['course_list'][$course_info['real_id']] = $course_info; |
||
| 4625 | $temp_course_in_session[$row['session_id']]['name'] = $row['name']; |
||
| 4626 | $simple_session_array[$row['session_id']] = $row['name']; |
||
| 4627 | } |
||
| 4628 | |||
| 4629 | foreach ($simple_session_array as $my_session_id => $session_name) { |
||
| 4630 | $course_list = $temp_course_in_session[$my_session_id]['course_list']; |
||
| 4631 | $my_course_data = array(); |
||
| 4632 | foreach ($course_list as $courseId => $course_data) { |
||
| 4633 | $my_course_data[$courseId] = $course_data['title']; |
||
| 4634 | } |
||
| 4635 | |||
| 4636 | if (empty($session_id)) { |
||
| 4637 | $my_course_data = utf8_sort($my_course_data); |
||
| 4638 | } |
||
| 4639 | |||
| 4640 | $final_course_data = array(); |
||
| 4641 | foreach ($my_course_data as $course_id => $value) { |
||
| 4642 | if (isset($course_list[$course_id])) { |
||
| 4643 | $final_course_data[$course_id] = $course_list[$course_id]; |
||
| 4644 | } |
||
| 4645 | } |
||
| 4646 | $course_in_session[$my_session_id]['course_list'] = $final_course_data; |
||
| 4647 | $course_in_session[$my_session_id]['name'] = $session_name; |
||
| 4648 | } |
||
| 4649 | |||
| 4650 | $html = ''; |
||
| 4651 | |||
| 4652 | // Course list |
||
| 4653 | if ($show_courses) { |
||
| 4654 | if (!empty($courses)) { |
||
| 4655 | $html .= Display::page_subheader( |
||
| 4656 | Display::return_icon( |
||
| 4657 | 'course.png', |
||
| 4658 | get_lang('MyCourses'), |
||
| 4659 | array(), |
||
| 4660 | ICON_SIZE_SMALL |
||
| 4661 | ).' '.get_lang('MyCourses') |
||
| 4662 | ); |
||
| 4663 | $html .= '<div class="table-responsive">'; |
||
| 4664 | $html .= '<table class="table table-striped table-hover">'; |
||
| 4665 | $html .= '<thead>'; |
||
| 4666 | $html .= '<tr> |
||
| 4667 | '.Display::tag('th', get_lang('Course'), array('width'=>'300px')).' |
||
| 4668 | '.Display::tag('th', get_lang('TimeSpentInTheCourse')).' |
||
| 4669 | '.Display::tag('th', get_lang('Progress')).' |
||
| 4670 | '.Display::tag('th', get_lang('BestScore')).' |
||
| 4671 | '.Display::tag('th', get_lang('LastConnexion')).' |
||
| 4672 | '.Display::tag('th', get_lang('Details')).' |
||
| 4673 | </tr>'; |
||
| 4674 | $html .= '</thead><tbody>'; |
||
| 4675 | |||
| 4676 | foreach ($courses as $course_code => $course_title) { |
||
| 4677 | $courseInfo = api_get_course_info($course_code); |
||
| 4678 | $courseId = $courseInfo['real_id']; |
||
| 4679 | |||
| 4680 | $total_time_login = self::get_time_spent_on_the_course( |
||
| 4681 | $user_id, |
||
| 4682 | $courseId |
||
| 4683 | ); |
||
| 4684 | $time = api_time_to_hms($total_time_login); |
||
| 4685 | $progress = self::get_avg_student_progress( |
||
| 4686 | $user_id, |
||
| 4687 | $course_code |
||
| 4688 | ); |
||
| 4689 | $bestScore = self::get_avg_student_score( |
||
| 4690 | $user_id, |
||
| 4691 | $course_code, |
||
| 4692 | array(), |
||
| 4693 | null, |
||
| 4694 | false, |
||
| 4695 | false, |
||
| 4696 | true |
||
| 4697 | ); |
||
| 4698 | |||
| 4699 | $last_connection = self::get_last_connection_date_on_the_course( |
||
| 4700 | $user_id, |
||
| 4701 | $courseInfo |
||
| 4702 | ); |
||
| 4703 | |||
| 4704 | if (is_null($progress) || empty($progress)) { |
||
| 4705 | $progress = '0%'; |
||
| 4706 | } else { |
||
| 4707 | $progress = $progress.'%'; |
||
| 4708 | } |
||
| 4709 | |||
| 4710 | if (isset($_GET['course']) && |
||
| 4711 | $course_code == $_GET['course'] && |
||
| 4712 | empty($_GET['session_id']) |
||
| 4713 | ) { |
||
| 4714 | $html .= '<tr class="row_odd" style="background-color:#FBF09D">'; |
||
| 4715 | } else { |
||
| 4716 | $html .= '<tr class="row_even">'; |
||
| 4717 | } |
||
| 4718 | $url = api_get_course_url($course_code, $session_id); |
||
| 4719 | $course_url = Display::url($course_title, $url, array('target'=>SESSION_LINK_TARGET)); |
||
| 4720 | $html .= '<td>'.$course_url.'</td>'; |
||
| 4721 | $html .= '<td align="center">'.$time.'</td>'; |
||
| 4722 | $html .= '<td align="center">'.$progress.'</td>'; |
||
| 4723 | $html .= '<td align="center">'; |
||
| 4724 | if (empty($bestScore)) { |
||
| 4725 | $html .= '-'; |
||
| 4726 | } else { |
||
| 4727 | $html .= $bestScore.'%'; |
||
| 4728 | } |
||
| 4729 | |||
| 4730 | $html .= '</td>'; |
||
| 4731 | $html .= '<td align="center">'.$last_connection.'</td>'; |
||
| 4732 | $html .= '<td align="center">'; |
||
| 4733 | if (isset($_GET['course']) && |
||
| 4734 | $course_code == $_GET['course'] && |
||
| 4735 | empty($_GET['session_id']) |
||
| 4736 | ) { |
||
| 4737 | $html .= '<a href="#course_session_header">'; |
||
| 4738 | $html .= Display::return_icon('2rightarrow_na.png', get_lang('Details')); |
||
| 4739 | View Code Duplication | } else { |
|
| 4740 | $html .= '<a href="'.api_get_self().'?course='.$course_code.$extra_params.'#course_session_header">'; |
||
| 4741 | $html .= Display::return_icon('2rightarrow.png', get_lang('Details')); |
||
| 4742 | } |
||
| 4743 | $html .= '</a>'; |
||
| 4744 | $html .= '</td></tr>'; |
||
| 4745 | } |
||
| 4746 | $html .= '</tbody></table>'; |
||
| 4747 | $html .= '</div>'; |
||
| 4748 | } |
||
| 4749 | } |
||
| 4750 | |||
| 4751 | // Session list |
||
| 4752 | if (!empty($course_in_session)) { |
||
| 4753 | $main_session_graph = ''; |
||
| 4754 | //Load graphics only when calling to an specific session |
||
| 4755 | $session_graph = array(); |
||
| 4756 | $all_exercise_graph_name_list = array(); |
||
| 4757 | $my_results = array(); |
||
| 4758 | $all_exercise_graph_list = array(); |
||
| 4759 | $all_exercise_start_time = array(); |
||
| 4760 | foreach ($course_in_session as $my_session_id => $session_data) { |
||
| 4761 | $course_list = $session_data['course_list']; |
||
| 4762 | $user_count = count(SessionManager::get_users_by_session($my_session_id)); |
||
| 4763 | $exercise_graph_name_list = array(); |
||
| 4764 | $exercise_graph_list = array(); |
||
| 4765 | |||
| 4766 | foreach ($course_list as $course_data) { |
||
| 4767 | $exercise_list = ExerciseLib::get_all_exercises( |
||
| 4768 | $course_data, |
||
| 4769 | $my_session_id, |
||
| 4770 | false, |
||
| 4771 | null, |
||
| 4772 | false, |
||
| 4773 | 1 |
||
| 4774 | ); |
||
| 4775 | |||
| 4776 | foreach ($exercise_list as $exercise_data) { |
||
| 4777 | $exercise_obj = new Exercise($course_data['real_id']); |
||
| 4778 | $exercise_obj->read($exercise_data['id']); |
||
| 4779 | // Exercise is not necessary to be visible to show results check the result_disable configuration instead |
||
| 4780 | //$visible_return = $exercise_obj->is_visible(); |
||
| 4781 | if ($exercise_data['results_disabled'] == 0 || $exercise_data['results_disabled'] == 2) { |
||
| 4782 | $best_average = intval( |
||
| 4783 | ExerciseLib::get_best_average_score_by_exercise( |
||
| 4784 | $exercise_data['id'], |
||
| 4785 | $course_data['real_id'], |
||
| 4786 | $my_session_id, |
||
| 4787 | $user_count |
||
| 4788 | ) |
||
| 4789 | ); |
||
| 4790 | |||
| 4791 | $exercise_graph_list[] = $best_average; |
||
| 4792 | $all_exercise_graph_list[] = $best_average; |
||
| 4793 | |||
| 4794 | $user_result_data = ExerciseLib::get_best_attempt_by_user( |
||
| 4795 | api_get_user_id(), |
||
| 4796 | $exercise_data['id'], |
||
| 4797 | $course_data['real_id'], |
||
| 4798 | $my_session_id |
||
| 4799 | ); |
||
| 4800 | |||
| 4801 | $score = 0; |
||
| 4802 | if (!empty($user_result_data['exe_weighting']) && intval($user_result_data['exe_weighting']) != 0) { |
||
| 4803 | $score = intval($user_result_data['exe_result'] / $user_result_data['exe_weighting'] * 100); |
||
| 4804 | } |
||
| 4805 | $time = api_strtotime($exercise_data['start_time']) ? api_strtotime($exercise_data['start_time'], 'UTC') : 0; |
||
| 4806 | $all_exercise_start_time[] = $time; |
||
| 4807 | $my_results[] = $score; |
||
| 4808 | if (count($exercise_list) <= 10) { |
||
| 4809 | $title = cut($course_data['title'], 30)." \n ".cut($exercise_data['title'], 30); |
||
| 4810 | $exercise_graph_name_list[] = $title; |
||
| 4811 | $all_exercise_graph_name_list[] = $title; |
||
| 4812 | } else { |
||
| 4813 | // if there are more than 10 results, space becomes difficult to find, |
||
| 4814 | // so only show the title of the exercise, not the tool |
||
| 4815 | $title = cut($exercise_data['title'], 30); |
||
| 4816 | $exercise_graph_name_list[] = $title; |
||
| 4817 | $all_exercise_graph_name_list[] = $title; |
||
| 4818 | } |
||
| 4819 | } |
||
| 4820 | } |
||
| 4821 | } |
||
| 4822 | } |
||
| 4823 | |||
| 4824 | // Complete graph |
||
| 4825 | if (!empty($my_results) && !empty($all_exercise_graph_list)) { |
||
| 4826 | asort($all_exercise_start_time); |
||
| 4827 | |||
| 4828 | //Fix exams order |
||
| 4829 | $final_all_exercise_graph_name_list = array(); |
||
| 4830 | $my_results_final = array(); |
||
| 4831 | $final_all_exercise_graph_list = array(); |
||
| 4832 | |||
| 4833 | foreach ($all_exercise_start_time as $key => $time) { |
||
| 4834 | $label_time = ''; |
||
| 4835 | if (!empty($time)) { |
||
| 4836 | $label_time = date('d-m-y', $time); |
||
| 4837 | } |
||
| 4838 | $final_all_exercise_graph_name_list[] = $all_exercise_graph_name_list[$key].' '.$label_time; |
||
| 4839 | $my_results_final[] = $my_results[$key]; |
||
| 4840 | $final_all_exercise_graph_list[] = $all_exercise_graph_list[$key]; |
||
| 4841 | } |
||
| 4842 | $main_session_graph = self::generate_session_exercise_graph( |
||
| 4843 | $final_all_exercise_graph_name_list, |
||
| 4844 | $my_results_final, |
||
| 4845 | $final_all_exercise_graph_list |
||
| 4846 | ); |
||
| 4847 | } |
||
| 4848 | |||
| 4849 | $sessionIcon = Display::return_icon( |
||
| 4850 | 'session.png', |
||
| 4851 | get_lang('Sessions'), |
||
| 4852 | array(), |
||
| 4853 | ICON_SIZE_SMALL |
||
| 4854 | ); |
||
| 4855 | |||
| 4856 | $anchor = Display::url('', '', ['name' => 'course_session_header']); |
||
| 4857 | $html .= $anchor.Display::page_subheader( |
||
| 4858 | $sessionIcon.' '.get_lang('Sessions') |
||
| 4859 | ); |
||
| 4860 | |||
| 4861 | $html .= '<div class="table-responsive">'; |
||
| 4862 | $html .= '<table class="table table-striped table-hover">'; |
||
| 4863 | $html .= '<thead>'; |
||
| 4864 | $html .= '<tr> |
||
| 4865 | '.Display::tag('th', get_lang('Session'), array('width'=>'300px')).' |
||
| 4866 | '.Display::tag('th', get_lang('PublishedExercises'), array('width'=>'300px')).' |
||
| 4867 | '.Display::tag('th', get_lang('NewExercises')).' |
||
| 4868 | '.Display::tag('th', get_lang('AverageExerciseResult')).' |
||
| 4869 | '.Display::tag('th', get_lang('Details')).' |
||
| 4870 | </tr>'; |
||
| 4871 | $html .= '</thead>'; |
||
| 4872 | $html .= '<tbody>'; |
||
| 4873 | |||
| 4874 | foreach ($course_in_session as $my_session_id => $session_data) { |
||
| 4875 | $course_list = $session_data['course_list']; |
||
| 4876 | $session_name = $session_data['name']; |
||
| 4877 | if ($showAllSessions == false) { |
||
| 4878 | if (isset($session_id) && !empty($session_id)) { |
||
| 4879 | if ($session_id != $my_session_id) { |
||
| 4880 | continue; |
||
| 4881 | } |
||
| 4882 | } |
||
| 4883 | } |
||
| 4884 | |||
| 4885 | $all_exercises = 0; |
||
| 4886 | $all_unanswered_exercises_by_user = 0; |
||
| 4887 | $all_average = 0; |
||
| 4888 | $stats_array = array(); |
||
| 4889 | |||
| 4890 | foreach ($course_list as $course_data) { |
||
| 4891 | // All exercises in the course @todo change for a real count |
||
| 4892 | $exercises = ExerciseLib::get_all_exercises($course_data, $my_session_id); |
||
| 4893 | $count_exercises = 0; |
||
| 4894 | if (is_array($exercises) && !empty($exercises)) { |
||
| 4895 | $count_exercises = count($exercises); |
||
| 4896 | } |
||
| 4897 | |||
| 4898 | // Count of user results |
||
| 4899 | $done_exercises = null; |
||
| 4900 | $courseInfo = api_get_course_info($course_data['code']); |
||
| 4901 | |||
| 4902 | $answered_exercises = 0; |
||
| 4903 | if (!empty($exercises)) { |
||
| 4904 | foreach ($exercises as $exercise_item) { |
||
| 4905 | $attempts = Event::count_exercise_attempts_by_user( |
||
| 4906 | api_get_user_id(), |
||
| 4907 | $exercise_item['id'], |
||
| 4908 | $courseInfo['real_id'], |
||
| 4909 | $my_session_id |
||
| 4910 | ); |
||
| 4911 | if ($attempts > 1) { |
||
| 4912 | $answered_exercises++; |
||
| 4913 | } |
||
| 4914 | } |
||
| 4915 | } |
||
| 4916 | |||
| 4917 | // Average |
||
| 4918 | $average = ExerciseLib::get_average_score_by_course( |
||
| 4919 | $courseInfo['real_id'], |
||
| 4920 | $my_session_id |
||
| 4921 | ); |
||
| 4922 | $all_exercises += $count_exercises; |
||
| 4923 | $all_unanswered_exercises_by_user += $count_exercises - $answered_exercises; |
||
| 4924 | $all_average += $average; |
||
| 4925 | } |
||
| 4926 | |||
| 4927 | if (!empty($course_list)) { |
||
| 4928 | $all_average = $all_average / count($course_list); |
||
| 4929 | } |
||
| 4930 | |||
| 4931 | if (isset($_GET['session_id']) && $my_session_id == $_GET['session_id']) { |
||
| 4932 | $html .= '<tr style="background-color:#FBF09D">'; |
||
| 4933 | } else { |
||
| 4934 | $html .= '<tr>'; |
||
| 4935 | } |
||
| 4936 | $url = api_get_path(WEB_CODE_PATH)."session/index.php?session_id={$my_session_id}"; |
||
| 4937 | |||
| 4938 | $html .= Display::tag('td', Display::url($session_name, $url, array('target'=>SESSION_LINK_TARGET))); |
||
| 4939 | $html .= Display::tag('td', $all_exercises); |
||
| 4940 | $html .= Display::tag('td', $all_unanswered_exercises_by_user); |
||
| 4941 | $html .= Display::tag('td', ExerciseLib::convert_to_percentage($all_average)); |
||
| 4942 | |||
| 4943 | if (isset($_GET['session_id']) && $my_session_id == $_GET['session_id']) { |
||
| 4944 | $icon = Display::url( |
||
| 4945 | Display::return_icon( |
||
| 4946 | '2rightarrow_na.png', |
||
| 4947 | get_lang('Details') |
||
| 4948 | ), |
||
| 4949 | api_get_self().'?session_id='.$my_session_id.'#course_session_list' |
||
| 4950 | ); |
||
| 4951 | } else { |
||
| 4952 | $icon = Display::url( |
||
| 4953 | Display::return_icon( |
||
| 4954 | '2rightarrow.png', |
||
| 4955 | get_lang('Details') |
||
| 4956 | ), |
||
| 4957 | api_get_self().'?session_id='.$my_session_id.'#course_session_list' |
||
| 4958 | ); |
||
| 4959 | } |
||
| 4960 | $html .= Display::tag('td', $icon); |
||
| 4961 | $html .= '</tr>'; |
||
| 4962 | } |
||
| 4963 | $html .= '</tbody>'; |
||
| 4964 | $html .= '</table></div><br />'; |
||
| 4965 | $html .= Display::div( |
||
| 4966 | $main_session_graph, |
||
| 4967 | array( |
||
| 4968 | 'id' => 'session_graph', |
||
| 4969 | 'class' => 'chart-session', |
||
| 4970 | 'style' => 'position:relative; text-align: center;', |
||
| 4971 | ) |
||
| 4972 | ); |
||
| 4973 | |||
| 4974 | // Checking selected session. |
||
| 4975 | if (isset($_GET['session_id'])) { |
||
| 4976 | $session_id_from_get = intval($_GET['session_id']); |
||
| 4977 | $session_data = $course_in_session[$session_id_from_get]; |
||
| 4978 | $course_list = $session_data['course_list']; |
||
| 4979 | |||
| 4980 | $html .= '<a name= "course_session_list"></a>'; |
||
| 4981 | $html .= Display::tag('h3', $session_data['name'].' - '.get_lang('CourseList')); |
||
| 4982 | |||
| 4983 | $html .= '<div class="table-responsive">'; |
||
| 4984 | $html .= '<table class="table table-hover table-striped">'; |
||
| 4985 | |||
| 4986 | $columnHeaders = [ |
||
| 4987 | 'course_title' => [ |
||
| 4988 | get_lang('Course'), |
||
| 4989 | array('width'=>'300px') |
||
| 4990 | ], |
||
| 4991 | 'published_exercises' => [ |
||
| 4992 | get_lang('PublishedExercises') |
||
| 4993 | ], |
||
| 4994 | 'new_exercises' => [ |
||
| 4995 | get_lang('NewExercises'), |
||
| 4996 | ], |
||
| 4997 | 'my_average' => [ |
||
| 4998 | get_lang('MyAverage'), |
||
| 4999 | ], |
||
| 5000 | 'average_exercise_result' => [ |
||
| 5001 | get_lang('AverageExerciseResult'), |
||
| 5002 | ], |
||
| 5003 | 'time_spent' => [ |
||
| 5004 | get_lang('TimeSpentInTheCourse'), |
||
| 5005 | ], |
||
| 5006 | 'lp_progress' => [ |
||
| 5007 | get_lang('LPProgress'), |
||
| 5008 | ], |
||
| 5009 | 'score' => [ |
||
| 5010 | get_lang('Score').Display::return_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array('align' => 'absmiddle', 'hspace' => '3px')), |
||
| 5011 | ], |
||
| 5012 | 'best_score' => [ |
||
| 5013 | get_lang('BestScore'), |
||
| 5014 | ], |
||
| 5015 | 'last_connection' => [ |
||
| 5016 | get_lang('LastConnexion'), |
||
| 5017 | ], |
||
| 5018 | 'details' => [ |
||
| 5019 | get_lang('Details'), |
||
| 5020 | ], |
||
| 5021 | ]; |
||
| 5022 | |||
| 5023 | $html .= '<thead><tr>'; |
||
| 5024 | foreach ($columnHeaders as $key => $columnSetting) { |
||
| 5025 | if (isset($trackingColumns['course_session']) && |
||
| 5026 | in_array($key, $trackingColumns['course_session']) && |
||
| 5027 | $trackingColumns['course_session'][$key] |
||
| 5028 | ) { |
||
| 5029 | $settings = isset($columnSetting[1]) ? $columnSetting[1] : []; |
||
| 5030 | $html .= Display::tag( |
||
| 5031 | 'th', |
||
| 5032 | $columnSetting[0], |
||
| 5033 | $settings |
||
| 5034 | ); |
||
| 5035 | } |
||
| 5036 | } |
||
| 5037 | |||
| 5038 | $html .= '</tr> |
||
| 5039 | </thead> |
||
| 5040 | <tbody>'; |
||
| 5041 | |||
| 5042 | foreach ($course_list as $course_data) { |
||
| 5043 | $course_code = $course_data['code']; |
||
| 5044 | $course_title = $course_data['title']; |
||
| 5045 | $courseId = $course_data['real_id']; |
||
| 5046 | |||
| 5047 | // All exercises in the course @todo change for a real count |
||
| 5048 | $exercises = ExerciseLib::get_all_exercises( |
||
| 5049 | $course_data, |
||
| 5050 | $session_id_from_get |
||
| 5051 | ); |
||
| 5052 | $count_exercises = 0; |
||
| 5053 | if (!empty($exercises)) { |
||
| 5054 | $count_exercises = count($exercises); |
||
| 5055 | } |
||
| 5056 | $answered_exercises = 0; |
||
| 5057 | foreach ($exercises as $exercise_item) { |
||
| 5058 | $attempts = Event::count_exercise_attempts_by_user( |
||
| 5059 | api_get_user_id(), |
||
| 5060 | $exercise_item['id'], |
||
| 5061 | $courseId, |
||
| 5062 | $session_id_from_get |
||
| 5063 | ); |
||
| 5064 | if ($attempts > 1) { |
||
| 5065 | $answered_exercises++; |
||
| 5066 | } |
||
| 5067 | } |
||
| 5068 | |||
| 5069 | $unanswered_exercises = $count_exercises - $answered_exercises; |
||
| 5070 | |||
| 5071 | // Average |
||
| 5072 | $average = ExerciseLib::get_average_score_by_course( |
||
| 5073 | $courseId, |
||
| 5074 | $session_id_from_get |
||
| 5075 | ); |
||
| 5076 | $my_average = ExerciseLib::get_average_score_by_course_by_user( |
||
| 5077 | api_get_user_id(), |
||
| 5078 | $courseId, |
||
| 5079 | $session_id_from_get |
||
| 5080 | ); |
||
| 5081 | |||
| 5082 | $bestScore = self::get_avg_student_score( |
||
| 5083 | $user_id, |
||
| 5084 | $course_code, |
||
| 5085 | array(), |
||
| 5086 | $session_id_from_get, |
||
| 5087 | false, |
||
| 5088 | false, |
||
| 5089 | true |
||
| 5090 | ); |
||
| 5091 | |||
| 5092 | $stats_array[$course_code] = array( |
||
| 5093 | 'exercises' => $count_exercises, |
||
| 5094 | 'unanswered_exercises_by_user' => $unanswered_exercises, |
||
| 5095 | 'done_exercises' => $done_exercises, |
||
| 5096 | 'average' => $average, |
||
| 5097 | 'my_average' => $my_average, |
||
| 5098 | 'best_score' => $bestScore |
||
| 5099 | ); |
||
| 5100 | |||
| 5101 | $last_connection = self::get_last_connection_date_on_the_course( |
||
| 5102 | $user_id, |
||
| 5103 | $course_data, |
||
| 5104 | $session_id_from_get |
||
| 5105 | ); |
||
| 5106 | |||
| 5107 | $progress = self::get_avg_student_progress( |
||
| 5108 | $user_id, |
||
| 5109 | $course_code, |
||
| 5110 | array(), |
||
| 5111 | $session_id_from_get |
||
| 5112 | ); |
||
| 5113 | |||
| 5114 | $total_time_login = self::get_time_spent_on_the_course( |
||
| 5115 | $user_id, |
||
| 5116 | $courseId, |
||
| 5117 | $session_id_from_get |
||
| 5118 | ); |
||
| 5119 | $time = api_time_to_hms($total_time_login); |
||
| 5120 | |||
| 5121 | $percentage_score = self::get_avg_student_score( |
||
| 5122 | $user_id, |
||
| 5123 | $course_code, |
||
| 5124 | array(), |
||
| 5125 | $session_id_from_get |
||
| 5126 | ); |
||
| 5127 | $courseCodeFromGet = isset($_GET['course']) ? $_GET['course'] : null; |
||
| 5128 | |||
| 5129 | if ($course_code == $courseCodeFromGet && $_GET['session_id'] == $session_id_from_get) { |
||
| 5130 | $html .= '<tr class="row_odd" style="background-color:#FBF09D" >'; |
||
| 5131 | } else { |
||
| 5132 | $html .= '<tr class="row_even">'; |
||
| 5133 | } |
||
| 5134 | |||
| 5135 | $url = api_get_course_url($course_code, $session_id_from_get); |
||
| 5136 | $course_url = Display::url( |
||
| 5137 | $course_title, |
||
| 5138 | $url, |
||
| 5139 | array('target' => SESSION_LINK_TARGET) |
||
| 5140 | ); |
||
| 5141 | |||
| 5142 | if (is_numeric($progress)) { |
||
| 5143 | $progress = $progress.'%'; |
||
| 5144 | } else { |
||
| 5145 | $progress = '0%'; |
||
| 5146 | } |
||
| 5147 | if (is_numeric($percentage_score)) { |
||
| 5148 | $percentage_score = $percentage_score.'%'; |
||
| 5149 | } else { |
||
| 5150 | $percentage_score = '0%'; |
||
| 5151 | } |
||
| 5152 | |||
| 5153 | if (is_numeric($stats_array[$course_code]['best_score'])) { |
||
| 5154 | $bestScore = $stats_array[$course_code]['best_score'].'%'; |
||
| 5155 | } else { |
||
| 5156 | $bestScore = '-'; |
||
| 5157 | } |
||
| 5158 | |||
| 5159 | if (empty($last_connection) || is_bool($last_connection)) { |
||
| 5160 | $last_connection = ''; |
||
| 5161 | } |
||
| 5162 | |||
| 5163 | if ($course_code == $courseCodeFromGet && |
||
| 5164 | $_GET['session_id'] == $session_id_from_get |
||
| 5165 | ) { |
||
| 5166 | $details = Display::url( |
||
| 5167 | Display::return_icon('2rightarrow_na.png', get_lang('Details')), |
||
| 5168 | '#course_session_data' |
||
| 5169 | ); |
||
| 5170 | } else { |
||
| 5171 | $url = api_get_self().'?course='.$course_code.'&session_id='.$session_id_from_get.$extra_params.'#course_session_data'; |
||
| 5172 | $details = Display::url( |
||
| 5173 | Display::return_icon( |
||
| 5174 | '2rightarrow.png', |
||
| 5175 | get_lang('Details') |
||
| 5176 | ), |
||
| 5177 | $url |
||
| 5178 | ); |
||
| 5179 | } |
||
| 5180 | $details .= '</a>'; |
||
| 5181 | |||
| 5182 | $data = [ |
||
| 5183 | 'course_title' => $course_url, |
||
| 5184 | 'published_exercises' => $stats_array[$course_code]['exercises'], // exercise available |
||
| 5185 | 'new_exercises' => $stats_array[$course_code]['unanswered_exercises_by_user'], |
||
| 5186 | 'my_average' => ExerciseLib::convert_to_percentage($stats_array[$course_code]['my_average']), |
||
| 5187 | 'average_exercise_result' => $stats_array[$course_code]['average'] == 0 ? '-' : '('.ExerciseLib::convert_to_percentage($stats_array[$course_code]['average']).')', |
||
| 5188 | 'time_spent' => $time, |
||
| 5189 | 'lp_progress' => $progress, |
||
| 5190 | 'score' => $percentage_score, |
||
| 5191 | 'best_score' => $bestScore, |
||
| 5192 | 'last_connection' => $last_connection, |
||
| 5193 | 'details' => $details, |
||
| 5194 | ]; |
||
| 5195 | |||
| 5196 | foreach ($data as $key => $value) { |
||
| 5197 | if (in_array($key, $trackingColumns['course_session']) |
||
| 5198 | && $trackingColumns['course_session'][$key] |
||
| 5199 | ) { |
||
| 5200 | $html .= Display::tag('td', $value); |
||
| 5201 | } |
||
| 5202 | } |
||
| 5203 | $html .= '</tr>'; |
||
| 5204 | } |
||
| 5205 | $html .= '</tbody></table></div>'; |
||
| 5206 | } |
||
| 5207 | } |
||
| 5208 | |||
| 5209 | return $html; |
||
| 5210 | } |
||
| 5211 | |||
| 5212 | /** |
||
| 5213 | * Shows the user detail progress (when clicking in the details link) |
||
| 5214 | * @param int $user_id |
||
| 5215 | * @param string $course_code |
||
| 5216 | * @param int $session_id |
||
| 5217 | * @return string html code |
||
| 5218 | */ |
||
| 5219 | public static function show_course_detail($user_id, $course_code, $session_id) |
||
| 5220 | { |
||
| 5221 | $html = ''; |
||
| 5222 | if (isset($course_code)) { |
||
| 5223 | $user_id = intval($user_id); |
||
| 5224 | $session_id = intval($session_id); |
||
| 5225 | $course = Database::escape_string($course_code); |
||
| 5226 | $course_info = api_get_course_info($course); |
||
| 5227 | if (empty($course_info)) { |
||
| 5228 | return ''; |
||
| 5229 | } |
||
| 5230 | |||
| 5231 | $html .= '<a name="course_session_data"></a>'; |
||
| 5232 | $html .= Display::page_subheader($course_info['title']); |
||
| 5233 | $html .= '<div class="table-responsive">'; |
||
| 5234 | $html .= '<table class="table table-striped table-hover">'; |
||
| 5235 | |||
| 5236 | //Course details |
||
| 5237 | $html .= ' |
||
| 5238 | <thead> |
||
| 5239 | <tr> |
||
| 5240 | <th>'.get_lang('Exercises').'</th> |
||
| 5241 | <th>'.get_lang('Attempts').'</th> |
||
| 5242 | <th>'.get_lang('BestAttempt').'</th> |
||
| 5243 | <th>'.get_lang('Ranking').'</th> |
||
| 5244 | <th>'.get_lang('BestResultInCourse').'</th> |
||
| 5245 | <th>'.get_lang('Statistics').' '.Display::return_icon('info3.gif', get_lang('OnlyBestResultsPerStudent'), array('align' => 'absmiddle', 'hspace' => '3px')).'</th> |
||
| 5246 | </tr> |
||
| 5247 | </thead> |
||
| 5248 | <tbody>'; |
||
| 5249 | |||
| 5250 | if (empty($session_id)) { |
||
| 5251 | $user_list = CourseManager::get_user_list_from_course_code( |
||
| 5252 | $course, |
||
| 5253 | $session_id, |
||
| 5254 | null, |
||
| 5255 | null, |
||
| 5256 | STUDENT |
||
| 5257 | ); |
||
| 5258 | } else { |
||
| 5259 | $user_list = CourseManager::get_user_list_from_course_code( |
||
| 5260 | $course, |
||
| 5261 | $session_id, |
||
| 5262 | null, |
||
| 5263 | null, |
||
| 5264 | 0 |
||
| 5265 | ); |
||
| 5266 | } |
||
| 5267 | |||
| 5268 | // Show exercise results of invisible exercises? see BT#4091 |
||
| 5269 | $exercise_list = ExerciseLib::get_all_exercises( |
||
| 5270 | $course_info, |
||
| 5271 | $session_id, |
||
| 5272 | false, |
||
| 5273 | null, |
||
| 5274 | false, |
||
| 5275 | 2 |
||
| 5276 | ); |
||
| 5277 | |||
| 5278 | $to_graph_exercise_result = array(); |
||
| 5279 | if (!empty($exercise_list)) { |
||
| 5280 | $score = $weighting = $exe_id = 0; |
||
| 5281 | foreach ($exercise_list as $exercices) { |
||
| 5282 | |||
| 5283 | $exercise_obj = new Exercise($course_info['real_id']); |
||
| 5284 | $exercise_obj->read($exercices['id']); |
||
| 5285 | $visible_return = $exercise_obj->is_visible(); |
||
| 5286 | $score = $weighting = $attempts = 0; |
||
| 5287 | |||
| 5288 | // Getting count of attempts by user |
||
| 5289 | $attempts = Event::count_exercise_attempts_by_user( |
||
| 5290 | api_get_user_id(), |
||
| 5291 | $exercices['id'], |
||
| 5292 | $course_info['real_id'], |
||
| 5293 | $session_id |
||
| 5294 | ); |
||
| 5295 | |||
| 5296 | $html .= '<tr class="row_even">'; |
||
| 5297 | $url = api_get_path(WEB_CODE_PATH)."exercise/overview.php?cidReq={$course_info['code']}&id_session=$session_id&exerciseId={$exercices['id']}"; |
||
| 5298 | |||
| 5299 | if ($visible_return['value'] == true) { |
||
| 5300 | $exercices['title'] = Display::url( |
||
| 5301 | $exercices['title'], |
||
| 5302 | $url, |
||
| 5303 | array('target' => SESSION_LINK_TARGET) |
||
| 5304 | ); |
||
| 5305 | } elseif ($exercices['active'] == -1) { |
||
| 5306 | $exercices['title'] = sprintf(get_lang('XParenthesisDeleted'), $exercices['title']); |
||
| 5307 | } |
||
| 5308 | |||
| 5309 | $html .= Display::tag('td', $exercices['title']); |
||
| 5310 | |||
| 5311 | // Exercise configuration show results or show only score |
||
| 5312 | if ($exercices['results_disabled'] == 0 || $exercices['results_disabled'] == 2) { |
||
| 5313 | //For graphics |
||
| 5314 | $best_exercise_stats = Event::get_best_exercise_results_by_user( |
||
| 5315 | $exercices['id'], |
||
| 5316 | $course_info['real_id'], |
||
| 5317 | $session_id |
||
| 5318 | ); |
||
| 5319 | |||
| 5320 | $to_graph_exercise_result[$exercices['id']] = array( |
||
| 5321 | 'title' => $exercices['title'], |
||
| 5322 | 'data' => $best_exercise_stats |
||
| 5323 | ); |
||
| 5324 | |||
| 5325 | $latest_attempt_url = ''; |
||
| 5326 | $best_score = $position = $percentage_score_result = '-'; |
||
| 5327 | $graph = $normal_graph = null; |
||
| 5328 | |||
| 5329 | // Getting best results |
||
| 5330 | $best_score_data = ExerciseLib::get_best_attempt_in_course( |
||
| 5331 | $exercices['id'], |
||
| 5332 | $course_info['real_id'], |
||
| 5333 | $session_id |
||
| 5334 | ); |
||
| 5335 | |||
| 5336 | $best_score = ''; |
||
| 5337 | if (!empty($best_score_data)) { |
||
| 5338 | $best_score = ExerciseLib::show_score( |
||
| 5339 | $best_score_data['exe_result'], |
||
| 5340 | $best_score_data['exe_weighting'] |
||
| 5341 | ); |
||
| 5342 | } |
||
| 5343 | |||
| 5344 | if ($attempts > 0) { |
||
| 5345 | $exercise_stat = ExerciseLib::get_best_attempt_by_user( |
||
| 5346 | api_get_user_id(), |
||
| 5347 | $exercices['id'], |
||
| 5348 | $course_info['real_id'], |
||
| 5349 | $session_id |
||
| 5350 | ); |
||
| 5351 | if (!empty($exercise_stat)) { |
||
| 5352 | // Always getting the BEST attempt |
||
| 5353 | $score = $exercise_stat['exe_result']; |
||
| 5354 | $weighting = $exercise_stat['exe_weighting']; |
||
| 5355 | $exe_id = $exercise_stat['exe_id']; |
||
| 5356 | |||
| 5357 | $latest_attempt_url .= api_get_path(WEB_CODE_PATH).'exercise/result.php?id='.$exe_id.'&cidReq='.$course_info['code'].'&show_headers=1&id_session='.$session_id; |
||
| 5358 | $percentage_score_result = Display::url( |
||
| 5359 | ExerciseLib::show_score($score, $weighting), |
||
| 5360 | $latest_attempt_url |
||
| 5361 | ); |
||
| 5362 | $my_score = 0; |
||
| 5363 | if (!empty($weighting) && intval($weighting) != 0) { |
||
| 5364 | $my_score = $score / $weighting; |
||
| 5365 | } |
||
| 5366 | //@todo this function slows the page |
||
| 5367 | if (is_int($user_list)) { |
||
| 5368 | $user_list = array($user_list); |
||
| 5369 | } |
||
| 5370 | $position = ExerciseLib::get_exercise_result_ranking( |
||
| 5371 | $my_score, |
||
| 5372 | $exe_id, |
||
| 5373 | $exercices['id'], |
||
| 5374 | $course_info['code'], |
||
| 5375 | $session_id, |
||
| 5376 | $user_list |
||
| 5377 | ); |
||
| 5378 | |||
| 5379 | $graph = self::generate_exercise_result_thumbnail_graph( |
||
| 5380 | $to_graph_exercise_result[$exercices['id']] |
||
| 5381 | ); |
||
| 5382 | $normal_graph = self::generate_exercise_result_graph( |
||
| 5383 | $to_graph_exercise_result[$exercices['id']] |
||
| 5384 | ); |
||
| 5385 | } |
||
| 5386 | } |
||
| 5387 | $html .= Display::div( |
||
| 5388 | $normal_graph, |
||
| 5389 | array( |
||
| 5390 | 'id' => 'main_graph_'.$exercices['id'], |
||
| 5391 | 'class' => 'dialog', |
||
| 5392 | 'style' => 'display:none' |
||
| 5393 | ) |
||
| 5394 | ); |
||
| 5395 | |||
| 5396 | if (empty($graph)) { |
||
| 5397 | $graph = '-'; |
||
| 5398 | } else { |
||
| 5399 | $graph = Display::url( |
||
| 5400 | '<img src="'.$graph.'" >', |
||
| 5401 | $normal_graph, |
||
| 5402 | array( |
||
| 5403 | 'id' => $exercices['id'], |
||
| 5404 | 'class' => 'expand-image', |
||
| 5405 | ) |
||
| 5406 | ); |
||
| 5407 | } |
||
| 5408 | |||
| 5409 | $html .= Display::tag('td', $attempts, array('align'=>'center')); |
||
| 5410 | $html .= Display::tag('td', $percentage_score_result, array('align'=>'center')); |
||
| 5411 | $html .= Display::tag('td', $position, array('align'=>'center')); |
||
| 5412 | $html .= Display::tag('td', $best_score, array('align'=>'center')); |
||
| 5413 | $html .= Display::tag('td', $graph, array('align'=>'center')); |
||
| 5414 | //$html .= Display::tag('td', $latest_attempt_url, array('align'=>'center', 'width'=>'25')); |
||
| 5415 | |||
| 5416 | } else { |
||
| 5417 | // Exercise configuration NO results |
||
| 5418 | $html .= Display::tag('td', $attempts, array('align'=>'center')); |
||
| 5419 | $html .= Display::tag('td', '-', array('align'=>'center')); |
||
| 5420 | $html .= Display::tag('td', '-', array('align'=>'center')); |
||
| 5421 | $html .= Display::tag('td', '-', array('align'=>'center')); |
||
| 5422 | $html .= Display::tag('td', '-', array('align'=>'center')); |
||
| 5423 | } |
||
| 5424 | $html .= '</tr>'; |
||
| 5425 | } |
||
| 5426 | } else { |
||
| 5427 | $html .= '<tr><td colspan="5" align="center">'.get_lang('NoEx').'</td></tr>'; |
||
| 5428 | } |
||
| 5429 | $html .= '</tbody></table></div>'; |
||
| 5430 | |||
| 5431 | $columnHeaders = [ |
||
| 5432 | 'lp' => get_lang('LearningPath'), |
||
| 5433 | 'time' => get_lang('LatencyTimeSpent'), |
||
| 5434 | 'progress' => get_lang('Progress'), |
||
| 5435 | 'score' => get_lang('Score'), |
||
| 5436 | 'best_score' => get_lang('BestScore'), |
||
| 5437 | 'last_connection' => get_lang('LastConnexion'), |
||
| 5438 | ]; |
||
| 5439 | |||
| 5440 | $headers = ''; |
||
| 5441 | $trackingColumns = api_get_configuration_value('tracking_columns'); |
||
| 5442 | if (isset($trackingColumns['my_progress_lp'])) { |
||
| 5443 | foreach ($columnHeaders as $key => $value) { |
||
| 5444 | if (!isset($trackingColumns['my_progress_lp'][$key]) || |
||
| 5445 | $trackingColumns['my_progress_lp'][$key] == false |
||
| 5446 | ) { |
||
| 5447 | unset($columnHeaders[$key]); |
||
| 5448 | } |
||
| 5449 | } |
||
| 5450 | } |
||
| 5451 | |||
| 5452 | $columnHeadersKeys = array_keys($columnHeaders); |
||
| 5453 | foreach ($columnHeaders as $key => $columnName) { |
||
| 5454 | $headers .= Display::tag( |
||
| 5455 | 'th', |
||
| 5456 | $columnName |
||
| 5457 | ); |
||
| 5458 | } |
||
| 5459 | |||
| 5460 | // LP table results |
||
| 5461 | $html .= '<div class="table-responsive">'; |
||
| 5462 | $html .= '<table class="table table-striped table-hover">'; |
||
| 5463 | $html .= '<thead><tr>'; |
||
| 5464 | $html .= $headers; |
||
| 5465 | $html .= '</tr></thead><tbody>'; |
||
| 5466 | |||
| 5467 | $list = new LearnpathList( |
||
| 5468 | api_get_user_id(), |
||
| 5469 | $course_info['code'], |
||
| 5470 | $session_id, |
||
| 5471 | 'lp.publicatedOn ASC', |
||
| 5472 | true, |
||
| 5473 | null, |
||
| 5474 | true |
||
| 5475 | ); |
||
| 5476 | |||
| 5477 | $lp_list = $list->get_flat_list(); |
||
| 5478 | |||
| 5479 | if (!empty($lp_list) > 0) { |
||
| 5480 | foreach ($lp_list as $lp_id => $learnpath) { |
||
| 5481 | $progress = self::get_avg_student_progress( |
||
| 5482 | $user_id, |
||
| 5483 | $course, |
||
| 5484 | array($lp_id), |
||
| 5485 | $session_id |
||
| 5486 | ); |
||
| 5487 | $last_connection_in_lp = self::get_last_connection_time_in_lp( |
||
| 5488 | $user_id, |
||
| 5489 | $course, |
||
| 5490 | $lp_id, |
||
| 5491 | $session_id |
||
| 5492 | ); |
||
| 5493 | $time_spent_in_lp = self::get_time_spent_in_lp( |
||
| 5494 | $user_id, |
||
| 5495 | $course, |
||
| 5496 | array($lp_id), |
||
| 5497 | $session_id |
||
| 5498 | ); |
||
| 5499 | $percentage_score = self::get_avg_student_score( |
||
| 5500 | $user_id, |
||
| 5501 | $course, |
||
| 5502 | array($lp_id), |
||
| 5503 | $session_id |
||
| 5504 | ); |
||
| 5505 | |||
| 5506 | $bestScore = self::get_avg_student_score( |
||
| 5507 | $user_id, |
||
| 5508 | $course, |
||
| 5509 | array($lp_id), |
||
| 5510 | $session_id, |
||
| 5511 | false, |
||
| 5512 | false, |
||
| 5513 | true |
||
| 5514 | ); |
||
| 5515 | |||
| 5516 | if (is_numeric($progress)) { |
||
| 5517 | $progress = $progress.'%'; |
||
| 5518 | } |
||
| 5519 | if (is_numeric($percentage_score)) { |
||
| 5520 | $percentage_score = $percentage_score.'%'; |
||
| 5521 | } else { |
||
| 5522 | $percentage_score = '0%'; |
||
| 5523 | } |
||
| 5524 | |||
| 5525 | if (is_numeric($bestScore)) { |
||
| 5526 | $bestScore = $bestScore.'%'; |
||
| 5527 | } else { |
||
| 5528 | $bestScore = '-'; |
||
| 5529 | } |
||
| 5530 | |||
| 5531 | $time_spent_in_lp = api_time_to_hms($time_spent_in_lp); |
||
| 5532 | $last_connection = '-'; |
||
| 5533 | if (!empty($last_connection_in_lp)) { |
||
| 5534 | $last_connection = api_convert_and_format_date( |
||
| 5535 | $last_connection_in_lp, |
||
| 5536 | DATE_TIME_FORMAT_LONG |
||
| 5537 | ); |
||
| 5538 | } |
||
| 5539 | |||
| 5540 | $url = api_get_path(WEB_CODE_PATH)."lp/lp_controller.php?cidReq={$course_code}&id_session=$session_id&lp_id=$lp_id&action=view"; |
||
| 5541 | $html .= '<tr class="row_even">'; |
||
| 5542 | |||
| 5543 | if (in_array('lp', $columnHeadersKeys)) { |
||
| 5544 | if ($learnpath['lp_visibility'] == 0) { |
||
| 5545 | $html .= Display::tag('td', $learnpath['lp_name']); |
||
| 5546 | } else { |
||
| 5547 | $html .= Display::tag( |
||
| 5548 | 'td', |
||
| 5549 | Display::url( |
||
| 5550 | $learnpath['lp_name'], |
||
| 5551 | $url, |
||
| 5552 | array('target' => SESSION_LINK_TARGET) |
||
| 5553 | ) |
||
| 5554 | ); |
||
| 5555 | } |
||
| 5556 | } |
||
| 5557 | |||
| 5558 | if (in_array('time', $columnHeadersKeys)) { |
||
| 5559 | $html .= Display::tag( |
||
| 5560 | 'td', |
||
| 5561 | $time_spent_in_lp, |
||
| 5562 | array('align' => 'center') |
||
| 5563 | ); |
||
| 5564 | } |
||
| 5565 | |||
| 5566 | if (in_array('progress', $columnHeadersKeys)) { |
||
| 5567 | $html .= Display::tag( |
||
| 5568 | 'td', |
||
| 5569 | $progress, |
||
| 5570 | array('align' => 'center') |
||
| 5571 | ); |
||
| 5572 | } |
||
| 5573 | |||
| 5574 | if (in_array('score', $columnHeadersKeys)) { |
||
| 5575 | $html .= Display::tag('td', $percentage_score); |
||
| 5576 | } |
||
| 5577 | if (in_array('best_score', $columnHeadersKeys)) { |
||
| 5578 | $html .= Display::tag('td', $bestScore); |
||
| 5579 | } |
||
| 5580 | |||
| 5581 | if (in_array('last_connection', $columnHeadersKeys)) { |
||
| 5582 | $html .= Display::tag('td', $last_connection, array('align'=>'center', 'width'=>'180px')); |
||
| 5583 | } |
||
| 5584 | $html .= '</tr>'; |
||
| 5585 | } |
||
| 5586 | } else { |
||
| 5587 | $html .= '<tr> |
||
| 5588 | <td colspan="4" align="center"> |
||
| 5589 | '.get_lang('NoLearnpath').' |
||
| 5590 | </td> |
||
| 5591 | </tr>'; |
||
| 5592 | } |
||
| 5593 | $html .= '</tbody></table></div>'; |
||
| 5594 | |||
| 5595 | $html .= self::displayUserSkills($user_id, $course_info['id'], $session_id); |
||
| 5596 | } |
||
| 5597 | |||
| 5598 | return $html; |
||
| 5599 | } |
||
| 5600 | |||
| 5601 | /** |
||
| 5602 | * Generates an histogram |
||
| 5603 | * @param array $names list of exercise names |
||
| 5604 | * @param array $my_results my results 0 to 100 |
||
| 5605 | * @param array $average average scores 0-100 |
||
| 5606 | * @return string |
||
| 5607 | */ |
||
| 5608 | static function generate_session_exercise_graph($names, $my_results, $average) |
||
| 5762 | |||
| 5763 | /** |
||
| 5764 | * Returns a thumbnail of the function generate_exercise_result_graph |
||
| 5765 | * @param array $attempts |
||
| 5766 | */ |
||
| 5767 | static function generate_exercise_result_thumbnail_graph($attempts) |
||
| 5951 | |||
| 5952 | /** |
||
| 5953 | * Generates a big graph with the number of best results |
||
| 5954 | * @param array |
||
| 5955 | */ |
||
| 5956 | static function generate_exercise_result_graph($attempts) |
||
| 6134 | |||
| 6135 | /** |
||
| 6136 | * @param FormValidator $form |
||
| 6137 | * @return mixed |
||
| 6138 | */ |
||
| 6139 | public static function setUserSearchForm($form) |
||
| 6170 | |||
| 6171 | /** |
||
| 6172 | * Get the progress of a exercise |
||
| 6173 | * @param int $sessionId The session ID (session.id) |
||
| 6174 | * @param int $courseId The course ID (course.id) |
||
| 6175 | * @param int $exerciseId The quiz ID (c_quiz.id) |
||
| 6176 | * @param string $date_from |
||
| 6177 | * @param string $date_to |
||
| 6178 | * @param array $options An array of options you can pass to the query (limit, where and order) |
||
| 6179 | * @return array An array with the data of exercise(s) progress |
||
| 6180 | */ |
||
| 6181 | public static function get_exercise_progress( |
||
| 6405 | |||
| 6406 | /** |
||
| 6407 | * @param User $user |
||
| 6408 | * @param string $tool |
||
| 6409 | * @param Course $course |
||
| 6410 | * @param Session|null $session Optional. |
||
| 6411 | * @return \Chamilo\CourseBundle\Entity\CStudentPublication|null |
||
| 6412 | * @throws \Doctrine\ORM\NonUniqueResultException |
||
| 6413 | */ |
||
| 6414 | public static function getLastStudentPublication( |
||
| 6444 | |||
| 6445 | /** |
||
| 6446 | * Get the HTML code for show a block with the achieved user skill on course/session |
||
| 6447 | * @param int $userId |
||
| 6448 | * @param int $courseId Optional. |
||
| 6449 | * @param int $sessionId Optional. |
||
| 6450 | * @return string |
||
| 6451 | */ |
||
| 6452 | public static function displayUserSkills($userId, $courseId = 0, $sessionId = 0) |
||
| 6517 | } |
||
| 6518 | |||
| 6519 | /** |
||
| 6520 | * @todo move into a proper file |
||
| 6521 | * @package chamilo.tracking |
||
| 6522 | */ |
||
| 6523 | class TrackingCourseLog |
||
| 6524 | { |
||
| 6525 | /** |
||
| 7691 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.