From a3cd0ec489f3b376202b988bf46b7ee92463ca71 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 18 Feb 2021 08:47:33 +0100 Subject: [PATCH] Gradebook - Fix export results only score BT#18440 --- main/gradebook/gradebook_flatview.php | 2 +- main/gradebook/lib/GradebookUtils.php | 12 ++++---- .../lib/flatview_data_generator.class.php | 29 ++++++++++++------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/main/gradebook/gradebook_flatview.php b/main/gradebook/gradebook_flatview.php index 9168980dbd..b53f46eb21 100755 --- a/main/gradebook/gradebook_flatview.php +++ b/main/gradebook/gradebook_flatview.php @@ -214,7 +214,7 @@ if (!empty($_GET['export_report']) && if (empty($_SESSION['export_user_fields'])) { $_SESSION['export_user_fields'] = false; } - if (!api_is_allowed_to_edit(false, false) && !api_is_course_tutor()) { + if (!api_is_allowed_to_edit() && !api_is_course_tutor()) { $user_id = api_get_user_id(); } diff --git a/main/gradebook/lib/GradebookUtils.php b/main/gradebook/lib/GradebookUtils.php index 13145fc8f7..f6d25cda56 100644 --- a/main/gradebook/lib/GradebookUtils.php +++ b/main/gradebook/lib/GradebookUtils.php @@ -628,9 +628,10 @@ class GradebookUtils $offset = isset($_GET['offset']) ? (int) $_GET['offset'] : 0; // step 2: generate rows: students $datagen->category = $cat; - $count = (($offset + 10) > $datagen->get_total_items_count()) ? ($datagen->get_total_items_count() - $offset) : GRADEBOOK_ITEM_LIMIT; - $header_names = $datagen->get_header_names($offset, $count, true); - $data_array = $datagen->get_data( + $totalItems = $datagen->get_total_items_count(); + $count = (($offset + 10) > $totalItems) ? ($totalItems - $offset) : GRADEBOOK_ITEM_LIMIT; + $headers = $datagen->get_header_names($offset, $count, true); + $list = $datagen->get_data( FlatViewDataGenerator::FVDG_SORT_LASTNAME, 0, null, @@ -641,12 +642,11 @@ class GradebookUtils ); $result = []; - foreach ($data_array as $data) { + foreach ($list as $data) { $result[] = array_slice($data, 1); } - $return = [$header_names, $result]; - return $return; + return [$headers, $result]; } /** diff --git a/main/gradebook/lib/flatview_data_generator.class.php b/main/gradebook/lib/flatview_data_generator.class.php index 2b3951a9fa..adb71a6e96 100755 --- a/main/gradebook/lib/flatview_data_generator.class.php +++ b/main/gradebook/lib/flatview_data_generator.class.php @@ -566,7 +566,10 @@ class FlatViewDataGenerator $items_count, $items_start, $show_all, - $row + $row, + null, + [], + $ignore_score_color ); $item_value_total += $result['item_value_total']; $evaluationsAdded = $result['evaluations_added']; @@ -582,7 +585,8 @@ class FlatViewDataGenerator $show_all, $row, $mainCategoryId, - $evaluationsAdded + $evaluationsAdded, + $ignore_score_color ); $item_total += $result['item_total']; @@ -655,7 +659,8 @@ class FlatViewDataGenerator $show_all, &$row, $parentCategoryIdFilter = null, - $evaluationsAlreadyAdded = [] + $evaluationsAlreadyAdded = [], + $ignoreScoreDecorations = false ) { // Generate actual data array $scoreDisplay = ScoreDisplay::instance(); @@ -688,13 +693,10 @@ class FlatViewDataGenerator $evaluationsAdded[] = $item->get_id(); $score = $item->calc_score($user_id); - $real_score = $score; $divide = isset($score[1]) && !empty($score[1]) && $score[1] > 0 ? $score[1] : 1; - // Sub cat weight $item_value = isset($score[0]) ? $score[0] / $divide : null; - // Fixing total when using one or multiple gradebooks. if (empty($parentCategoryIdFilter)) { if (0 == $this->category->get_parent_id()) { @@ -718,7 +720,8 @@ class FlatViewDataGenerator $complete_score = $scoreDisplay->display_score( $score, SCORE_DIV_PERCENT, - SCORE_ONLY_SCORE + SCORE_ONLY_SCORE, + $ignoreScoreDecorations ); if ('false' === $showPercentage) { @@ -728,17 +731,23 @@ class FlatViewDataGenerator } $real_score = $scoreDisplay->display_score( $real_score, - $defaultShowPercentageValue + $defaultShowPercentageValue, + null, + $ignoreScoreDecorations ); $temp_score = $scoreDisplay->display_score( [$item_value, null], - SCORE_DIV_SIMPLE_WITH_CUSTOM + SCORE_DIV_SIMPLE_WITH_CUSTOM, + null, + $ignoreScoreDecorations ); $temp_score = Display::tip($real_score, $temp_score); } else { $temp_score = $scoreDisplay->display_score( $real_score, - $defaultStyle + $defaultStyle, + null, + $ignoreScoreDecorations ); $temp_score = Display::tip($temp_score, $complete_score); }