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