Conditions | 24 |
Paths | > 20000 |
Total Lines | 247 |
Code Lines | 162 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
483 | function processStudentList($filter_score, $global, Cquiz $exercise, $courseInfo, $sessionId, $newSessionList) |
||
484 | { |
||
485 | /*if ((isset($exercise['id']) && empty($exercise['id'])) || |
||
486 | !isset($exercise['id']) |
||
487 | ) { |
||
488 | return [ |
||
489 | 'html' => '', |
||
490 | 'export_array_global' => [], |
||
491 | 'total_students' => 0, |
||
492 | ]; |
||
493 | }*/ |
||
494 | |||
495 | $exerciseStatsTable = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); |
||
496 | $courseId = $courseInfo['real_id']; |
||
497 | |||
498 | if (empty($sessionId)) { |
||
499 | $students = CourseManager::get_student_list_from_course_code( |
||
500 | $courseInfo['code'], |
||
501 | false, |
||
502 | 0, |
||
503 | null, |
||
504 | null, |
||
505 | false |
||
506 | ); |
||
507 | } else { |
||
508 | $students = CourseManager::get_student_list_from_course_code( |
||
509 | $courseInfo['code'], |
||
510 | true, |
||
511 | $sessionId, |
||
512 | null, |
||
513 | null, |
||
514 | false |
||
515 | ); |
||
516 | } |
||
517 | |||
518 | $html = null; |
||
519 | $totalStudents = count($students); |
||
520 | |||
521 | if (!$global) { |
||
522 | $html .= "<tr>"; |
||
523 | } |
||
524 | |||
525 | if (!$global) { |
||
526 | $html .= '<td rowspan="'.$totalStudents.'">'; |
||
527 | } else { |
||
528 | $html .= '<td>'; |
||
529 | } |
||
530 | |||
531 | $html .= $exercise->getTitle(); |
||
532 | |||
533 | if ($global && !empty($sessionId)) { |
||
534 | $sessionName = isset($newSessionList[$sessionId]) ? $newSessionList[$sessionId] : null; |
||
535 | $html .= Display::getMdiIcon(ObjectIcon::STAR, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Session')).' ('.$sessionName.')'; |
||
536 | } |
||
537 | |||
538 | $html .= '</td>'; |
||
539 | |||
540 | $globalRow = [ |
||
541 | $courseInfo['title'], |
||
542 | $exercise->getTitle(), |
||
543 | ]; |
||
544 | |||
545 | $total_with_parameter_score = 0; |
||
546 | $taken = 0; |
||
547 | $export_array_global = []; |
||
548 | $studentResult = []; |
||
549 | $export_array = []; |
||
550 | |||
551 | $exerciseId = $exercise->getIid(); |
||
552 | $sessionCondition = api_get_session_condition($sessionId); |
||
553 | foreach ($students as $student) { |
||
554 | $studentId = isset($student['user_id']) ? $student['user_id'] : $student['id_user']; |
||
555 | $studentId = (int) $studentId; |
||
556 | $sql = "SELECT COUNT(exe_id) as count |
||
557 | FROM $exerciseStatsTable |
||
558 | WHERE |
||
559 | c_id = $courseId AND |
||
560 | exe_exo_id = $exerciseId AND |
||
561 | exe_user_id= $studentId |
||
562 | $sessionCondition |
||
563 | "; |
||
564 | $result = Database::query($sql); |
||
565 | $attempts = Database::fetch_array($result); |
||
566 | |||
567 | $sql = "SELECT exe_id, score, max_score |
||
568 | FROM $exerciseStatsTable |
||
569 | WHERE |
||
570 | exe_user_id = $studentId AND |
||
571 | c_id = $courseId AND |
||
572 | exe_exo_id = ".$exerciseId." AND |
||
573 | session_id = $sessionId |
||
574 | ORDER BY score DESC |
||
575 | LIMIT 1"; |
||
576 | $result = Database::query($sql); |
||
577 | $score = 0; |
||
578 | $weighting = 0; |
||
579 | while ($scoreInfo = Database::fetch_array($result)) { |
||
580 | $score = $score + $scoreInfo['score']; |
||
581 | $weighting = $weighting + $scoreInfo['max_score']; |
||
582 | } |
||
583 | |||
584 | $percentageScore = 0; |
||
585 | |||
586 | if (0 != $weighting) { |
||
587 | $percentageScore = round(($score * 100) / $weighting); |
||
588 | } |
||
589 | |||
590 | if ($attempts['count'] > 0) { |
||
591 | $taken++; |
||
592 | } |
||
593 | |||
594 | if ($percentageScore >= $filter_score) { |
||
595 | $total_with_parameter_score++; |
||
596 | } |
||
597 | |||
598 | $tempArray = []; |
||
599 | |||
600 | if (!$global) { |
||
601 | $userInfo = api_get_user_info($studentId); |
||
602 | |||
603 | // User |
||
604 | $userRow = '<td>'; |
||
605 | $userRow .= $userInfo['complete_name']; |
||
606 | $userRow .= '</td>'; |
||
607 | $userRow .= '<td>'.$userInfo['username'].'</td>'; |
||
608 | |||
609 | // Best result. |
||
610 | if (!empty($attempts['count'])) { |
||
611 | $userRow .= '<td>'; |
||
612 | $userRow .= $percentageScore; |
||
613 | $tempArray[] = $percentageScore; |
||
614 | $userRow .= '</td>'; |
||
615 | |||
616 | if ($percentageScore >= $filter_score) { |
||
617 | $userRow .= '<td style="background-color:#DFFFA8">'; |
||
618 | $userRow .= get_lang('Pass').'</td>'; |
||
619 | $tempArray[] = get_lang('Pass'); |
||
620 | } else { |
||
621 | $userRow .= '<td style="background-color:#FC9A9E" >'; |
||
622 | $userRow .= get_lang('Fail').'</td>'; |
||
623 | $tempArray[] = get_lang('Fail'); |
||
624 | } |
||
625 | |||
626 | $userRow .= '<td>'; |
||
627 | $userRow .= $attempts['count']; |
||
628 | $tempArray[] = $attempts['count']; |
||
629 | $userRow .= '</td>'; |
||
630 | } else { |
||
631 | $score = '-'; |
||
632 | $userRow .= '<td>'; |
||
633 | $userRow .= '-'; |
||
634 | $tempArray[] = '-'; |
||
635 | $userRow .= '</td>'; |
||
636 | |||
637 | $userRow .= '<td style="background-color:#FCE89A">'; |
||
638 | $userRow .= get_lang('No attempts'); |
||
639 | $tempArray[] = get_lang('No attempts'); |
||
640 | $userRow .= '</td>'; |
||
641 | $userRow .= '<td>'; |
||
642 | $userRow .= 0; |
||
643 | $tempArray[] = 0; |
||
644 | $userRow .= '</td>'; |
||
645 | } |
||
646 | $userRow .= '</tr>'; |
||
647 | |||
648 | $studentResult[$studentId] = [ |
||
649 | 'html' => $userRow, |
||
650 | 'score' => $score, |
||
651 | 'array' => $tempArray, |
||
652 | 'user' => $userInfo['complete_name'], |
||
653 | 'username' => $userInfo['username'], |
||
654 | ]; |
||
655 | } |
||
656 | } |
||
657 | |||
658 | $row_not_global['exercise'] = $exercise->getTitle(); |
||
659 | |||
660 | if (!$global) { |
||
661 | if (!empty($studentResult)) { |
||
662 | $studentResultEmpty = $studentResultContent = []; |
||
663 | foreach ($studentResult as $row) { |
||
664 | if ('-' == $row['score']) { |
||
665 | $studentResultEmpty[] = $row; |
||
666 | } else { |
||
667 | $studentResultContent[] = $row; |
||
668 | } |
||
669 | } |
||
670 | |||
671 | // Sort only users with content |
||
672 | usort($studentResultContent, 'sort_user'); |
||
673 | $studentResult = array_merge($studentResultContent, $studentResultEmpty); |
||
674 | |||
675 | foreach ($studentResult as $row) { |
||
676 | $html .= $row['html']; |
||
677 | $row_not_global['results'][] = $row['array']; |
||
678 | $row_not_global['users'][] = $row['user']; |
||
679 | $row_not_global['usernames'][] = $row['username']; |
||
680 | } |
||
681 | $export_array[] = $row_not_global; |
||
682 | } |
||
683 | } |
||
684 | |||
685 | if ($global) { |
||
686 | // Exam taken |
||
687 | $html .= '<td>'; |
||
688 | $html .= $taken; |
||
689 | $globalRow[] = $taken; |
||
690 | $html .= '</td>'; |
||
691 | |||
692 | // Exam NOT taken |
||
693 | $html .= '<td>'; |
||
694 | $html .= $not_taken = $totalStudents - $taken; |
||
695 | $globalRow[] = $not_taken; |
||
696 | $html .= '</td>'; |
||
697 | |||
698 | // Exam pass |
||
699 | if (!empty($total_with_parameter_score)) { |
||
700 | $html .= '<td style="background-color:#DFFFA8" >'; |
||
701 | } else { |
||
702 | $html .= '<td style="background-color:#FCE89A" >'; |
||
703 | } |
||
704 | |||
705 | $html .= $total_with_parameter_score; |
||
706 | $globalRow[] = $total_with_parameter_score; |
||
707 | $html .= '</td>'; |
||
708 | |||
709 | // Exam fail |
||
710 | $html .= '<td>'; |
||
711 | |||
712 | $html .= $fail = $taken - $total_with_parameter_score; |
||
713 | $globalRow[] = $fail; |
||
714 | $html .= '</td>'; |
||
715 | |||
716 | $html .= '<td>'; |
||
717 | $html .= $totalStudents; |
||
718 | $globalRow[] = $totalStudents; |
||
719 | |||
720 | $html .= '</td>'; |
||
721 | |||
722 | $html .= '</tr>'; |
||
723 | $export_array_global[] = $globalRow; |
||
724 | } |
||
725 | |||
726 | return [ |
||
727 | 'html' => $html, |
||
728 | 'export_array_global' => $global ? $export_array_global : $export_array, |
||
729 | 'total_students' => $totalStudents, |
||
730 | ]; |
||
734 |