From c51000cb5cb67c34825ade9abc51a091a8646f44 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 27 Jul 2018 17:57:34 -0500 Subject: [PATCH] Fix export gradebook to pdf - refs BT#14687 #2609 --- .../gradebook/lib/fe/gradebooktable.class.php | 113 ++++++++---------- 1 file changed, 51 insertions(+), 62 deletions(-) diff --git a/main/gradebook/lib/fe/gradebooktable.class.php b/main/gradebook/lib/fe/gradebooktable.class.php index aa629dc0be..45e06729a8 100755 --- a/main/gradebook/lib/fe/gradebooktable.class.php +++ b/main/gradebook/lib/fe/gradebooktable.class.php @@ -683,83 +683,72 @@ class GradebookTable extends SortableTable SCORE_DIV ); - $totalRanking = []; - $invalidateRanking = true; - $average = 0; - foreach ($this->studentList as $student) { - $score = $main_cat[0]->calc_score($student['user_id']); - if (!empty($score[0])) { - $invalidateRanking = false; - } - $totalRanking[$student['user_id']] = $score[0]; - $average += $score[0]; - } - - $totalRanking = AbstractLink::getCurrentUserRanking($user_id, $totalRanking); - - $totalRanking = $scoredisplay->display_score( - $totalRanking, - SCORE_DIV, - SCORE_BOTH, - true - ); + $row = [ + null, + '

'.get_lang('Total').'

', + ]; - if ($invalidateRanking) { - $totalRanking = null; - } + if (!$this->exportToPdf) { + $row[] = null; + } - // Overwrite main weight - $totalBest[1] = $main_weight; + $row[] = $main_weight; + $row[] = $totalResult; - $totalBest = $scoredisplay->display_score( - $totalBest, - SCORE_DIV, - SCORE_BOTH, - true - ); + if (in_array(1, $this->loadStats)) { + $totalRanking = []; + $invalidateRanking = true; + $average = 0; + foreach ($this->studentList as $student) { + $score = $main_cat[0]->calc_score($student['user_id']); + if (!empty($score[0])) { + $invalidateRanking = false; + } + $totalRanking[$student['user_id']] = $score[0]; + $average += $score[0]; + } - if ($this->exportToPdf || $this->loadStats) { - // Overwrite main weight - $totalAverage[0] = $average / count($this->studentList); - $totalAverage[1] = $main_weight; + $totalRanking = AbstractLink::getCurrentUserRanking($user_id, $totalRanking); - $totalAverage = $scoredisplay->display_score( - $totalAverage, - SCORE_DIV, - SCORE_BOTH, - true - ); - } + $totalRanking = $scoredisplay->display_score( + $totalRanking, + SCORE_DIV, + SCORE_BOTH, + true + ); - if ($this->exportToPdf) { - $row = [ - null, - '

'.get_lang('Total').'

', - $main_weight, - $totalResult, - $totalRanking, - $totalBest, - $totalAverage, - ]; - } else { - $row = [ - null, - '

'.get_lang('Total').'

', - null, - $main_weight, - $totalResult, - ]; + if ($invalidateRanking) { + $totalRanking = null; + } - if (in_array(1, $this->loadStats)) { $row[] = $totalRanking; } if (in_array(2, $this->loadStats)) { + // Overwrite main weight + $totalBest[1] = $main_weight; + + $totalBest = $scoredisplay->display_score( + $totalBest, + SCORE_DIV, + SCORE_BOTH, + true + ); $row[] = $totalBest; } if (in_array(3, $this->loadStats)) { + // Overwrite main weight + $totalAverage[0] = $average / count($this->studentList); + $totalAverage[1] = $main_weight; + + $totalAverage = $scoredisplay->display_score( + $totalAverage, + SCORE_DIV, + SCORE_BOTH, + true + ); + $row[] = $totalAverage; } - } $sortable_data[] = $row; }