| Conditions | 118 |
| Paths | > 20000 |
| Total Lines | 690 |
| Code Lines | 436 |
| 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 |
||
| 299 | public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) |
||
| 300 | { |
||
| 301 | //variables load in index.php |
||
| 302 | global $certificate_min_score; |
||
| 303 | |||
| 304 | $isAllowedToEdit = api_is_allowed_to_edit(); |
||
| 305 | // determine sorting type |
||
| 306 | $col_adjust = $isAllowedToEdit ? 1 : 0; |
||
| 307 | // By id |
||
| 308 | $this->column = 5; |
||
| 309 | |||
| 310 | switch ($this->column) { |
||
| 311 | // Type |
||
| 312 | case 0 + $col_adjust: |
||
| 313 | $sorting = GradebookDataGenerator::GDG_SORT_TYPE; |
||
| 314 | break; |
||
| 315 | case 1 + $col_adjust: |
||
| 316 | $sorting = GradebookDataGenerator::GDG_SORT_NAME; |
||
| 317 | break; |
||
| 318 | case 2 + $col_adjust: |
||
| 319 | $sorting = GradebookDataGenerator::GDG_SORT_DESCRIPTION; |
||
| 320 | break; |
||
| 321 | case 3 + $col_adjust: |
||
| 322 | $sorting = GradebookDataGenerator::GDG_SORT_WEIGHT; |
||
| 323 | break; |
||
| 324 | case 4 + $col_adjust: |
||
| 325 | $sorting = GradebookDataGenerator::GDG_SORT_DATE; |
||
| 326 | break; |
||
| 327 | case 5 + $col_adjust: |
||
| 328 | $sorting = GradebookDataGenerator::GDG_SORT_ID; |
||
| 329 | break; |
||
| 330 | } |
||
| 331 | |||
| 332 | if ($this->direction == 'DESC') { |
||
| 333 | $sorting |= GradebookDataGenerator::GDG_SORT_DESC; |
||
| 334 | } else { |
||
| 335 | $sorting |= GradebookDataGenerator::GDG_SORT_ASC; |
||
| 336 | } |
||
| 337 | |||
| 338 | // Status of user in course. |
||
| 339 | $user_id = $this->userId; |
||
| 340 | $course_code = api_get_course_id(); |
||
| 341 | $session_id = api_get_session_id(); |
||
| 342 | |||
| 343 | $statusToFilter = 0; |
||
| 344 | if (empty($session_id)) { |
||
| 345 | $statusToFilter = STUDENT; |
||
| 346 | } |
||
| 347 | |||
| 348 | if (empty($this->studentList) && $this->loadStats) { |
||
| 349 | $studentList = CourseManager::get_user_list_from_course_code( |
||
| 350 | $course_code, |
||
| 351 | $session_id, |
||
| 352 | null, |
||
| 353 | null, |
||
| 354 | $statusToFilter |
||
| 355 | ); |
||
| 356 | $this->studentList = $studentList; |
||
| 357 | } |
||
| 358 | |||
| 359 | $this->datagen->userId = $this->userId; |
||
| 360 | $data_array = $this->datagen->get_data( |
||
| 361 | $sorting, |
||
| 362 | $from, |
||
| 363 | $this->per_page, |
||
| 364 | false, |
||
| 365 | $this->studentList, |
||
| 366 | $this->loadStats |
||
| 367 | ); |
||
| 368 | |||
| 369 | // generate the data to display |
||
| 370 | $sortable_data = []; |
||
| 371 | $weight_total_links = 0; |
||
| 372 | $main_cat = Category::load( |
||
| 373 | null, |
||
| 374 | null, |
||
| 375 | $course_code, |
||
| 376 | null, |
||
| 377 | null, |
||
| 378 | $session_id, |
||
| 379 | 'ORDER BY id' |
||
| 380 | ); |
||
| 381 | |||
| 382 | $total_categories_weight = 0; |
||
| 383 | $scoredisplay = ScoreDisplay::instance(); |
||
| 384 | |||
| 385 | $totalUserResult = [0, 0]; |
||
| 386 | $totalBest = [0, 0]; |
||
| 387 | $totalAverage = [0, 0]; |
||
| 388 | |||
| 389 | $type = 'detail'; |
||
| 390 | if ($this->exportToPdf) { |
||
| 391 | $type = 'simple'; |
||
| 392 | } |
||
| 393 | |||
| 394 | $model = ExerciseLib::getCourseScoreModel(); |
||
| 395 | $userExerciseScoreInCategory = api_get_configuration_value( |
||
| 396 | 'gradebook_use_exercise_score_settings_in_categories' |
||
| 397 | ); |
||
| 398 | |||
| 399 | $course_code = api_get_course_id(); |
||
| 400 | $session_id = api_get_session_id(); |
||
| 401 | $defaultData = Session::read($this->getPreloadDataKey()); |
||
| 402 | |||
| 403 | // Categories. |
||
| 404 | if (!empty($data_array)) { |
||
| 405 | foreach ($data_array as $data) { |
||
| 406 | // list of items inside the gradebook (exercises, lps, forums, etc) |
||
| 407 | $row = []; |
||
| 408 | /** @var AbstractLink $item */ |
||
| 409 | $item = $mainCategory = $data[0]; |
||
| 410 | |||
| 411 | // If the item is invisible, wrap it in a span with class invisible |
||
| 412 | $invisibility_span_open = $isAllowedToEdit && $item->is_visible() == '0' ? '<span class="text-muted">' : ''; |
||
| 413 | $invisibility_span_close = $isAllowedToEdit && $item->is_visible() == '0' ? '</span>' : ''; |
||
| 414 | |||
| 415 | // Id |
||
| 416 | if ($this->teacherView) { |
||
| 417 | if ($this->exportToPdf == false) { |
||
| 418 | $row[] = $this->build_id_column($item); |
||
| 419 | } |
||
| 420 | } |
||
| 421 | |||
| 422 | // Type. |
||
| 423 | $row[] = $this->build_type_column($item); |
||
| 424 | |||
| 425 | // Name. |
||
| 426 | if (get_class($item) === 'Category') { |
||
| 427 | $row[] = $invisibility_span_open.'<strong>'.$item->get_name().'</strong>'.$invisibility_span_close; |
||
| 428 | $main_categories[$item->get_id()]['name'] = $item->get_name(); |
||
| 429 | } else { |
||
| 430 | $name = $this->build_name_link($item, $type); |
||
| 431 | $row[] = $invisibility_span_open.$name.$invisibility_span_close; |
||
| 432 | $main_categories[$item->get_id()]['name'] = $name; |
||
| 433 | } |
||
| 434 | |||
| 435 | $this->dataForGraph['categories'][] = $item->get_name(); |
||
| 436 | $main_categories[$item->get_id()]['weight'] = $item->get_weight(); |
||
| 437 | $total_categories_weight += $item->get_weight(); |
||
| 438 | |||
| 439 | // Description. |
||
| 440 | if ($this->exportToPdf == false) { |
||
| 441 | $row[] = $invisibility_span_open.$data[2].$invisibility_span_close; |
||
| 442 | } |
||
| 443 | |||
| 444 | // Weight. |
||
| 445 | $weight = $scoredisplay->display_score( |
||
| 446 | [ |
||
| 447 | $data['3'], |
||
| 448 | $this->currentcat->get_weight(), |
||
| 449 | ], |
||
| 450 | SCORE_SIMPLE, |
||
| 451 | SCORE_BOTH, |
||
| 452 | true |
||
| 453 | ); |
||
| 454 | |||
| 455 | if ($this->teacherView) { |
||
| 456 | $row[] = $invisibility_span_open. |
||
| 457 | Display::tag('p', $weight, ['class' => 'score']). |
||
| 458 | $invisibility_span_close; |
||
| 459 | } else { |
||
| 460 | $row[] = $invisibility_span_open.$weight.$invisibility_span_close; |
||
| 461 | } |
||
| 462 | |||
| 463 | $category_weight = $item->get_weight(); |
||
| 464 | $mainCategoryWeight = $main_cat[0]->get_weight(); |
||
| 465 | |||
| 466 | if ($this->teacherView) { |
||
| 467 | $weight_total_links += $data[3]; |
||
| 468 | } else { |
||
| 469 | $cattotal = Category::load($_GET['selectcat']); |
||
| 470 | $scoretotal = $cattotal[0]->calc_score($this->userId); |
||
| 471 | } |
||
| 472 | |||
| 473 | // Edit (for admins). |
||
| 474 | if ($this->teacherView) { |
||
| 475 | $cat = new Category(); |
||
| 476 | $show_message = $cat->show_message_resource_delete($item->get_course_code()); |
||
| 477 | if ($show_message === false) { |
||
| 478 | $row[] = $this->build_edit_column($item); |
||
| 479 | } |
||
| 480 | } else { |
||
| 481 | $score = $item->calc_score($this->userId); |
||
| 482 | $scoreToDisplay = '-'; |
||
| 483 | if (!empty($score[1])) { |
||
| 484 | $completeScore = $scoredisplay->display_score($score, SCORE_DIV_PERCENT); |
||
| 485 | $score = $score[0] / $score[1] * $item->get_weight(); |
||
| 486 | $score = $scoredisplay->display_score([$score, null], SCORE_SIMPLE); |
||
| 487 | $scoreToDisplay = Display::tip($score, $completeScore); |
||
| 488 | } else { |
||
| 489 | $categoryScore = null; |
||
| 490 | } |
||
| 491 | |||
| 492 | // Students get the results and certificates columns |
||
| 493 | |||
| 494 | $value_data = isset($data[4]) ? $data[4] : null; |
||
| 495 | $best = isset($data['best']) ? $data['best'] : null; |
||
| 496 | $average = isset($data['average']) ? $data['average'] : null; |
||
| 497 | $ranking = isset($data['ranking']) ? $data['ranking'] : null; |
||
| 498 | |||
| 499 | $totalResult = [ |
||
| 500 | $data['result_score'][0], |
||
| 501 | $data['result_score'][1], |
||
| 502 | ]; |
||
| 503 | |||
| 504 | $totalUserResult[0] += $totalResult[0] / ($totalResult[1] ?: 1) * $data[3]; |
||
| 505 | $totalUserResult[1] += $data[3]; |
||
| 506 | |||
| 507 | $totalBest = [ |
||
| 508 | $scoredisplay->format_score($totalBest[0] + $data['best_score'][0]), |
||
| 509 | $scoredisplay->format_score($totalBest[1] + $data['best_score'][1]), |
||
| 510 | ]; |
||
| 511 | |||
| 512 | $totalAverage = [ |
||
| 513 | $data['average_score'][0], |
||
| 514 | $data['average_score'][1], |
||
| 515 | ]; |
||
| 516 | |||
| 517 | // Student result |
||
| 518 | if (empty($model)) { |
||
| 519 | $row[] = $value_data; |
||
| 520 | } else { |
||
| 521 | $row[] = ExerciseLib::show_score( |
||
| 522 | $data['result_score'][0], |
||
| 523 | $data['result_score'][1] |
||
| 524 | ); |
||
| 525 | } |
||
| 526 | |||
| 527 | $mode = SCORE_AVERAGE; |
||
| 528 | if ($userExerciseScoreInCategory) { |
||
| 529 | $mode = SCORE_SIMPLE; |
||
| 530 | |||
| 531 | $result = ExerciseLib::convertScoreToPlatformSetting($totalAverage[0], $totalAverage[1]); |
||
| 532 | $totalAverage[0] = $result['score']; |
||
| 533 | $totalAverage[1] = $result['weight']; |
||
| 534 | |||
| 535 | $result = ExerciseLib::convertScoreToPlatformSetting($totalResult[0], $totalResult[1]); |
||
| 536 | $totalResult[0] = $result['score']; |
||
| 537 | $totalResult[1] = $result['weight']; |
||
| 538 | |||
| 539 | $result = ExerciseLib::convertScoreToPlatformSetting( |
||
| 540 | $data['result_score'][0], |
||
| 541 | $data['result_score'][1] |
||
| 542 | ); |
||
| 543 | $data['my_result_no_float'][0] = $result['score']; |
||
| 544 | } |
||
| 545 | |||
| 546 | $totalResultAverageValue = strip_tags($scoredisplay->display_score($totalResult, $mode)); |
||
| 547 | $totalAverageValue = strip_tags($scoredisplay->display_score($totalAverage, $mode)); |
||
| 548 | |||
| 549 | $this->dataForGraph['my_result'][] = floatval($totalResultAverageValue); |
||
| 550 | $this->dataForGraph['average'][] = floatval($totalAverageValue); |
||
| 551 | $this->dataForGraph['my_result_no_float'][] = $data['result_score'][0]; |
||
| 552 | |||
| 553 | if (empty($model)) { |
||
| 554 | // Ranking |
||
| 555 | if (in_array(1, $this->loadStats)) { |
||
| 556 | $row[] = $ranking; |
||
| 557 | } |
||
| 558 | |||
| 559 | // Best |
||
| 560 | if (in_array(2, $this->loadStats)) { |
||
| 561 | $row[] = $best; |
||
| 562 | } |
||
| 563 | |||
| 564 | // Average |
||
| 565 | if (in_array(3, $this->loadStats)) { |
||
| 566 | $row[] = $average; |
||
| 567 | } |
||
| 568 | } |
||
| 569 | |||
| 570 | if (get_class($item) === 'Category') { |
||
| 571 | if ($this->exportToPdf == false) { |
||
| 572 | $row[] = $this->build_edit_column($item); |
||
| 573 | } |
||
| 574 | } |
||
| 575 | } |
||
| 576 | |||
| 577 | // Category added. |
||
| 578 | $sortable_data[] = $row; |
||
| 579 | |||
| 580 | // Loading children |
||
| 581 | if (get_class($item) === 'Category') { |
||
| 582 | $parent_id = $item->get_id(); |
||
| 583 | |||
| 584 | $cats = Category::load( |
||
| 585 | $parent_id, |
||
| 586 | null, |
||
| 587 | null, |
||
| 588 | null, |
||
| 589 | null, |
||
| 590 | null |
||
| 591 | ); |
||
| 592 | |||
| 593 | if (isset($cats[0])) { |
||
| 594 | /** @var Category $subCategory */ |
||
| 595 | $subCategory = $cats[0]; |
||
| 596 | $allcat = $subCategory->get_subcategories($this->userId, $course_code, $session_id); |
||
| 597 | $alleval = $subCategory->get_evaluations($this->userId); |
||
| 598 | $alllink = $subCategory->get_links($this->userId); |
||
| 599 | |||
| 600 | $sub_cat_info = new GradebookDataGenerator($allcat, $alleval, $alllink); |
||
| 601 | $sub_cat_info->preLoadDataKey = $this->getPreloadDataKey(); |
||
| 602 | $sub_cat_info->userId = $user_id; |
||
| 603 | $data_array2 = $sub_cat_info->get_data( |
||
| 604 | $sorting, |
||
| 605 | $from, |
||
| 606 | $this->per_page, |
||
| 607 | false, |
||
| 608 | $this->studentList |
||
| 609 | ); |
||
| 610 | $total_weight = 0; |
||
| 611 | |||
| 612 | // Links. |
||
| 613 | foreach ($data_array2 as $data) { |
||
| 614 | $row = []; |
||
| 615 | $item = $data[0]; |
||
| 616 | |||
| 617 | //if the item is invisible, wrap it in a span with class invisible |
||
| 618 | $invisibility_span_open = $isAllowedToEdit && $item->is_visible() == '0' ? '<span class="text-muted">' : ''; |
||
| 619 | $invisibility_span_close = $isAllowedToEdit && $item->is_visible() == '0' ? '</span>' : ''; |
||
| 620 | |||
| 621 | if (isset($item)) { |
||
| 622 | $main_categories[$parent_id]['children'][$item->get_id()]['name'] = $item->get_name(); |
||
| 623 | $main_categories[$parent_id]['children'][$item->get_id()]['weight'] = $item->get_weight(); |
||
| 624 | } |
||
| 625 | |||
| 626 | if ($this->teacherView) { |
||
| 627 | if ($this->exportToPdf == false) { |
||
| 628 | $row[] = $this->build_id_column($item); |
||
| 629 | } |
||
| 630 | } |
||
| 631 | |||
| 632 | // Type |
||
| 633 | $row[] = $this->build_type_column($item, ['style' => 'padding-left:5px']); |
||
| 634 | |||
| 635 | // Name. |
||
| 636 | $row[] = $invisibility_span_open.' '. |
||
| 637 | $this->build_name_link($item, $type).$invisibility_span_close; |
||
| 638 | |||
| 639 | // Description. |
||
| 640 | if ($this->exportToPdf == false) { |
||
| 641 | $row[] = $invisibility_span_open.$data[2].$invisibility_span_close; |
||
| 642 | } |
||
| 643 | |||
| 644 | $weight = $data[3]; |
||
| 645 | $total_weight += $weight; |
||
| 646 | |||
| 647 | // Weight |
||
| 648 | $row[] = $invisibility_span_open.$weight.$invisibility_span_close; |
||
| 649 | |||
| 650 | if ($this->teacherView) { |
||
| 651 | //$weight_total_links += intval($data[3]); |
||
| 652 | } else { |
||
| 653 | $cattotal = Category::load($_GET['selectcat']); |
||
| 654 | $scoretotal = $cattotal[0]->calc_score($this->userId); |
||
| 655 | } |
||
| 656 | |||
| 657 | // Admins get an edit column. |
||
| 658 | if (api_is_allowed_to_edit(null, true) && |
||
| 659 | isset($_GET['user_id']) == false && |
||
| 660 | (isset($_GET['action']) && $_GET['action'] != 'export_all' || !isset($_GET['action'])) |
||
| 661 | ) { |
||
| 662 | $cat = new Category(); |
||
| 663 | $show_message = $cat->show_message_resource_delete($item->get_course_code()); |
||
| 664 | if ($show_message === false) { |
||
| 665 | if ($this->exportToPdf == false) { |
||
| 666 | $row[] = $this->build_edit_column($item); |
||
| 667 | } |
||
| 668 | } |
||
| 669 | } else { |
||
| 670 | // Students get the results and certificates columns |
||
| 671 | $eval_n_links = array_merge($alleval, $alllink); |
||
| 672 | |||
| 673 | if (count($eval_n_links) > 0) { |
||
| 674 | $value_data = isset($data[4]) ? $data[4] : null; |
||
| 675 | if (!is_null($value_data)) { |
||
| 676 | // Result |
||
| 677 | $row[] = $value_data; |
||
| 678 | |||
| 679 | $best = isset($data['best']) ? $data['best'] : null; |
||
| 680 | $average = isset($data['average']) ? $data['average'] : null; |
||
| 681 | $ranking = isset($data['ranking']) ? $data['ranking'] : null; |
||
| 682 | |||
| 683 | if (in_array(1, $this->loadStats)) { |
||
| 684 | // Ranking |
||
| 685 | $row[] = $ranking; |
||
| 686 | } |
||
| 687 | |||
| 688 | if (in_array(2, $this->loadStats)) { |
||
| 689 | // Best |
||
| 690 | $row[] = $best; |
||
| 691 | } |
||
| 692 | |||
| 693 | // Average |
||
| 694 | if (in_array(3, $this->loadStats)) { |
||
| 695 | $row[] = $average; |
||
| 696 | } |
||
| 697 | } |
||
| 698 | } |
||
| 699 | |||
| 700 | if (!empty($cats)) { |
||
| 701 | if ($this->exportToPdf == false) { |
||
| 702 | $row[] = null; |
||
| 703 | } |
||
| 704 | } |
||
| 705 | } |
||
| 706 | |||
| 707 | if ($this->exportToPdf == false) { |
||
| 708 | $row['child_of'] = $parent_id; |
||
| 709 | } |
||
| 710 | $sortable_data[] = $row; |
||
| 711 | } |
||
| 712 | |||
| 713 | // "Warning row" |
||
| 714 | if (!empty($data_array)) { |
||
| 715 | if ($this->teacherView) { |
||
| 716 | // Compare the category weight to the sum of all weights inside the category |
||
| 717 | if (intval($total_weight) == $category_weight) { |
||
| 718 | $label = null; |
||
| 719 | $total = GradebookUtils::score_badges( |
||
| 720 | [ |
||
| 721 | $total_weight.' / '.$category_weight, |
||
| 722 | '100', |
||
| 723 | ] |
||
| 724 | ); |
||
| 725 | } else { |
||
| 726 | $label = Display::return_icon( |
||
| 727 | 'warning.png', |
||
| 728 | sprintf(get_lang('TotalWeightMustBeX'), $category_weight) |
||
| 729 | ); |
||
| 730 | $total = Display::badge($total_weight.' / '.$category_weight, 'warning'); |
||
| 731 | } |
||
| 732 | $row = [ |
||
| 733 | null, |
||
| 734 | null, |
||
| 735 | " <h5>".get_lang('SubTotal').'</h5>', |
||
| 736 | null, |
||
| 737 | $total.' '.$label, |
||
| 738 | 'child_of' => $parent_id, |
||
| 739 | ]; |
||
| 740 | $sortable_data[] = $row; |
||
| 741 | } |
||
| 742 | } |
||
| 743 | } |
||
| 744 | } |
||
| 745 | } |
||
| 746 | } //end looping categories |
||
| 747 | |||
| 748 | $main_weight = 0; |
||
| 749 | if (count($main_cat) > 1) { |
||
| 750 | /** @var Category $myCat */ |
||
| 751 | foreach ($main_cat as $myCat) { |
||
| 752 | $myParentId = $myCat->get_parent_id(); |
||
| 753 | if ($myParentId == 0) { |
||
| 754 | $main_weight = (int) $myCat->get_weight(); |
||
| 755 | } |
||
| 756 | } |
||
| 757 | } |
||
| 758 | |||
| 759 | if ($this->teacherView) { |
||
| 760 | // Total for teacher. |
||
| 761 | if (count($main_cat) > 1) { |
||
| 762 | if (intval($total_categories_weight) == $main_weight) { |
||
| 763 | $total = GradebookUtils::score_badges( |
||
| 764 | [ |
||
| 765 | $total_categories_weight.' / '.$main_weight, |
||
| 766 | '100', |
||
| 767 | ] |
||
| 768 | ); |
||
| 769 | } else { |
||
| 770 | $total = Display::badge($total_categories_weight.' / '.$main_weight, 'warning'); |
||
| 771 | } |
||
| 772 | $row = [ |
||
| 773 | null, |
||
| 774 | null, |
||
| 775 | '<strong>'.get_lang('Total').'</strong>', |
||
| 776 | null, |
||
| 777 | $total, |
||
| 778 | ]; |
||
| 779 | $sortable_data[] = $row; |
||
| 780 | } |
||
| 781 | } else { |
||
| 782 | // Total for student. |
||
| 783 | if (count($main_cat) > 1) { |
||
| 784 | $main_weight = (int) $main_cat[0]->get_weight(); |
||
| 785 | $global = null; |
||
| 786 | $average = null; |
||
| 787 | $myTotal = 0; |
||
| 788 | foreach ($this->dataForGraph['my_result_no_float'] as $result) { |
||
| 789 | $myTotal += $result; |
||
| 790 | } |
||
| 791 | |||
| 792 | $totalResult[0] = $myTotal; |
||
| 793 | // Overwrite main weight |
||
| 794 | $totalResult[1] = $main_weight; |
||
| 795 | |||
| 796 | $totalResult = $scoredisplay->display_score( |
||
| 797 | $totalResult, |
||
| 798 | SCORE_DIV |
||
| 799 | ); |
||
| 800 | |||
| 801 | $row = [ |
||
| 802 | null, |
||
| 803 | '<strong>'.get_lang('Total').'</strong>', |
||
| 804 | ]; |
||
| 805 | |||
| 806 | if (!$this->exportToPdf) { |
||
| 807 | $row[] = null; |
||
| 808 | } |
||
| 809 | |||
| 810 | $row[] = $main_weight; |
||
| 811 | $row[] = $totalResult; |
||
| 812 | $categoryId = $main_cat[0]->get_id(); |
||
| 813 | |||
| 814 | if (in_array(1, $this->loadStats)) { |
||
| 815 | if (isset($defaultData[$categoryId]) && isset($defaultData[$categoryId]['ranking'])) { |
||
| 816 | $totalRanking = $defaultData[$categoryId]['ranking']; |
||
| 817 | $invalidateRanking = $defaultData[$categoryId]['ranking_invalidate']; |
||
| 818 | } else { |
||
| 819 | $totalRanking = []; |
||
| 820 | $invalidateRanking = true; |
||
| 821 | $average = 0; |
||
| 822 | $main_cat[0]->setStudentList($this->studentList); |
||
| 823 | foreach ($this->studentList as $student) { |
||
| 824 | $score = $main_cat[0]->calc_score( |
||
| 825 | $student['user_id'], |
||
| 826 | null, |
||
| 827 | api_get_course_id(), |
||
| 828 | api_get_session_id() |
||
| 829 | ); |
||
| 830 | if (!empty($score[0])) { |
||
| 831 | $invalidateRanking = false; |
||
| 832 | } |
||
| 833 | $totalRanking[$student['user_id']] = $score[0]; |
||
| 834 | $average += $score[0]; |
||
| 835 | } |
||
| 836 | $defaultData[$categoryId]['ranking'] = $totalRanking; |
||
| 837 | $defaultData[$categoryId]['ranking_invalidate'] = $invalidateRanking; |
||
| 838 | Session::write($this->getPreloadDataKey(), $defaultData); |
||
| 839 | } |
||
| 840 | |||
| 841 | $totalRanking = AbstractLink::getCurrentUserRanking($user_id, $totalRanking); |
||
| 842 | $totalRanking = $scoredisplay->display_score( |
||
| 843 | $totalRanking, |
||
| 844 | SCORE_DIV, |
||
| 845 | SCORE_BOTH, |
||
| 846 | true, |
||
| 847 | true |
||
| 848 | ); |
||
| 849 | |||
| 850 | if ($invalidateRanking) { |
||
| 851 | $totalRanking = null; |
||
| 852 | } |
||
| 853 | $row[] = $totalRanking; |
||
| 854 | } |
||
| 855 | |||
| 856 | if (in_array(2, $this->loadStats)) { |
||
| 857 | if (isset($defaultData[$categoryId]) && isset($defaultData[$categoryId]['best'])) { |
||
| 858 | $totalBest = $defaultData[$categoryId]['best']; |
||
| 859 | } else { |
||
| 860 | // Overwrite main weight |
||
| 861 | $totalBest[1] = $main_weight; |
||
| 862 | $defaultData[$categoryId]['best'] = $totalBest; |
||
| 863 | } |
||
| 864 | $totalBest = $scoredisplay->display_score( |
||
| 865 | $totalBest, |
||
| 866 | SCORE_DIV, |
||
| 867 | SCORE_BOTH, |
||
| 868 | true |
||
| 869 | ); |
||
| 870 | $row[] = $totalBest; |
||
| 871 | } |
||
| 872 | |||
| 873 | if (in_array(3, $this->loadStats)) { |
||
| 874 | if (isset($defaultData[$categoryId]) && isset($defaultData[$categoryId]['average'])) { |
||
| 875 | $totalAverage = $defaultData[$categoryId]['average']; |
||
| 876 | } else { |
||
| 877 | // Overwrite main weight |
||
| 878 | $totalAverage[0] = $average / count($this->studentList); |
||
| 879 | $totalAverage[1] = $main_weight; |
||
| 880 | $defaultData[$categoryId]['average'] = $totalBest; |
||
| 881 | } |
||
| 882 | |||
| 883 | $totalAverage = $scoredisplay->display_score( |
||
| 884 | $totalAverage, |
||
| 885 | SCORE_DIV, |
||
| 886 | SCORE_BOTH, |
||
| 887 | true |
||
| 888 | ); |
||
| 889 | |||
| 890 | $row[] = $totalAverage; |
||
| 891 | } |
||
| 892 | |||
| 893 | if (!empty($row)) { |
||
| 894 | $sortable_data[] = $row; |
||
| 895 | } |
||
| 896 | } |
||
| 897 | } |
||
| 898 | |||
| 899 | Session::write('default_data', $defaultData); |
||
| 900 | |||
| 901 | // Warning messages |
||
| 902 | $view = isset($_GET['view']) ? $_GET['view'] : null; |
||
| 903 | if ($this->teacherView) { |
||
| 904 | if (isset($_GET['selectcat']) && |
||
| 905 | $_GET['selectcat'] > 0 && |
||
| 906 | $view != 'presence' |
||
| 907 | ) { |
||
| 908 | $id_cat = (int) $_GET['selectcat']; |
||
| 909 | $category = Category::load($id_cat); |
||
| 910 | $weight_category = (int) $this->build_weight($category[0]); |
||
| 911 | $course_code = $this->build_course_code($category[0]); |
||
| 912 | $weight_total_links = round($weight_total_links); |
||
| 913 | |||
| 914 | if ($weight_total_links > $weight_category || |
||
| 915 | $weight_total_links < $weight_category || |
||
| 916 | $weight_total_links > $weight_category |
||
| 917 | ) { |
||
| 918 | $warning_message = sprintf(get_lang('TotalWeightMustBeX'), $weight_category); |
||
| 919 | $modify_icons = |
||
| 920 | '<a href="gradebook_edit_cat.php?editcat='.$id_cat.'&cidReq='.$course_code.'&id_session='.api_get_session_id().'">'. |
||
| 921 | Display::return_icon('edit.png', $warning_message, [], ICON_SIZE_SMALL).'</a>'; |
||
| 922 | $warning_message .= $modify_icons; |
||
| 923 | echo Display::return_message($warning_message, 'warning', false); |
||
| 924 | } |
||
| 925 | |||
| 926 | $content_html = DocumentManager::replace_user_info_into_html( |
||
| 927 | api_get_user_id(), |
||
| 928 | api_get_course_info($course_code), |
||
| 929 | api_get_session_id() |
||
| 930 | ); |
||
| 931 | |||
| 932 | if (!empty($content_html)) { |
||
| 933 | $new_content = explode('</head>', $content_html['content']); |
||
| 934 | } |
||
| 935 | |||
| 936 | if (empty($new_content[0])) { |
||
| 937 | // Set default certificate |
||
| 938 | $courseData = api_get_course_info($course_code); |
||
| 939 | DocumentManager::generateDefaultCertificate($courseData); |
||
| 940 | } |
||
| 941 | } |
||
| 942 | |||
| 943 | if (empty($_GET['selectcat'])) { |
||
| 944 | $categories = Category::load(); |
||
| 945 | $weight_categories = $certificate_min_scores = $course_codes = []; |
||
| 946 | foreach ($categories as $category) { |
||
| 947 | $course_code_category = $this->build_course_code($category); |
||
| 948 | if (!empty($course_code)) { |
||
| 949 | if ($course_code_category == $course_code) { |
||
| 950 | $weight_categories[] = intval($this->build_weight($category)); |
||
| 951 | $certificate_min_scores[] = intval($this->build_certificate_min_score($category)); |
||
| 952 | $course_codes[] = $course_code; |
||
| 953 | break; |
||
| 954 | } |
||
| 955 | } else { |
||
| 956 | $weight_categories[] = intval($this->build_weight($category)); |
||
| 957 | $certificate_min_scores[] = intval($this->build_certificate_min_score($category)); |
||
| 958 | $course_codes[] = $course_code_category; |
||
| 959 | } |
||
| 960 | } |
||
| 961 | |||
| 962 | if (is_array($weight_categories) && |
||
| 963 | is_array($certificate_min_scores) && |
||
| 964 | is_array($course_codes) |
||
| 965 | ) { |
||
| 966 | $warning_message = ''; |
||
| 967 | for ($x = 0; $x < count($weight_categories); $x++) { |
||
| 968 | $weight_category = intval($weight_categories[$x]); |
||
| 969 | $certificate_min_score = intval($certificate_min_scores[$x]); |
||
| 970 | $course_code = $course_codes[$x]; |
||
| 971 | |||
| 972 | if (empty($certificate_min_score) || |
||
| 973 | ($certificate_min_score > $weight_category) |
||
| 974 | ) { |
||
| 975 | $warning_message .= $course_code. |
||
| 976 | ' - '.get_lang('CertificateMinimunScoreIsRequiredAndMustNotBeMoreThan'). |
||
| 977 | ' '.$weight_category.'<br />'; |
||
| 978 | } |
||
| 979 | } |
||
| 980 | |||
| 981 | if (!empty($warning_message)) { |
||
| 982 | echo Display::return_message($warning_message, 'warning', false); |
||
| 983 | } |
||
| 984 | } |
||
| 985 | } |
||
| 986 | } |
||
| 987 | |||
| 988 | return $sortable_data; |
||
| 989 | } |
||
| 1284 |