diff --git a/main/gradebook/lib/be/evaluation.class.php b/main/gradebook/lib/be/evaluation.class.php index ea0ef8d125..49e09948cc 100755 --- a/main/gradebook/lib/be/evaluation.class.php +++ b/main/gradebook/lib/be/evaluation.class.php @@ -536,6 +536,7 @@ class Evaluation implements GradebookItem public function calc_score($stud_id = null, $type = null) { $allowStats = api_get_configuration_value('allow_gradebook_stats'); + if ($allowStats) { $evaluation = $this->entity; if (!empty($evaluation)) { @@ -602,10 +603,12 @@ class Evaluation implements GradebookItem Session::write('calc_score', [$key => $results]); } - $score = 0; - /** @var Result $res */ - foreach ($results as $res) { - $score = $res->get_score(); + $score = null; + if (!empty($results)) { + /** @var Result $res */ + foreach ($results as $res) { + $score = $res->get_score(); + } } return [$score, $this->get_max()]; diff --git a/main/gradebook/lib/fe/flatviewtable.class.php b/main/gradebook/lib/fe/flatviewtable.class.php index 8c44606ce9..60cd75f667 100755 --- a/main/gradebook/lib/fe/flatviewtable.class.php +++ b/main/gradebook/lib/fe/flatviewtable.class.php @@ -93,7 +93,6 @@ class FlatViewTable extends SortableTable { $headerName = $this->datagen->get_header_names(); $total_users = $this->datagen->get_total_users_count(); - $customdisplays = ScoreDisplay::instance()->get_custom_score_display_settings(); if (empty($customdisplays)) { diff --git a/main/gradebook/lib/flatview_data_generator.class.php b/main/gradebook/lib/flatview_data_generator.class.php index e437145355..5f293c16f6 100755 --- a/main/gradebook/lib/flatview_data_generator.class.php +++ b/main/gradebook/lib/flatview_data_generator.class.php @@ -924,7 +924,6 @@ class FlatViewDataGenerator ]; $item_value_total += $item_value; $final_score += $score[0]; - //$final_score = ($final_score / $item_total) * 100; } $total_score = [$final_score, $item_total]; $row[] = [ @@ -942,21 +941,29 @@ class FlatViewDataGenerator for ($count = 0; $count < count($this->evals_links); $count++) { $item = $this->evals_links[$count]; $score = $item->calc_score($user[0]); - $divide = 0 == $score[1] ? 1 : $score[1]; - $item_value += $score[0] / $divide * $item->get_weight(); - $item_total += $item->get_weight(); - $score_denom = (0 == $score[1]) ? 1 : $score[1]; - $score_final = ($score[0] / $score_denom) * 100; - $row[] = [ - $score_final, - trim( + $score_final = null; + $displayScore = null; + + if (null !== $score) { + $divide = 0 == $score[1] ? 1 : $score[1]; + $item_value += $score[0] / $divide * $item->get_weight(); + $item_total += $item->get_weight(); + $score_denom = (0 == $score[1]) ? 1 : $score[1]; + $score_final = ($score[0] / $score_denom) * 100; + + $displayScore = trim( $scoreDisplay->display_score( $score, SCORE_CUSTOM, null, true ) - ), + ); + } + + $row[] = [ + $score_final, + $displayScore, ]; } $total_score = [$item_value, $item_total]; diff --git a/main/gradebook/lib/scoredisplay.class.php b/main/gradebook/lib/scoredisplay.class.php index 95e149798c..bbff9ed4b7 100755 --- a/main/gradebook/lib/scoredisplay.class.php +++ b/main/gradebook/lib/scoredisplay.class.php @@ -302,19 +302,21 @@ class ScoreDisplay ) { $my_score = $score == 0 ? [] : $score; - if ($type == SCORE_BAR) { - $percentage = $my_score[0] / $my_score[1] * 100; + switch ($type) { + case SCORE_BAR: + $percentage = $my_score[0] / $my_score[1] * 100; - return Display::bar_progress($percentage); - } - if ($type == SCORE_NUMERIC) { - $percentage = $my_score[0] / $my_score[1] * 100; + return Display::bar_progress($percentage); + break; + case SCORE_NUMERIC: - return round($percentage); - } + $percentage = $my_score[0] / $my_score[1] * 100; - if ($type == SCORE_SIMPLE) { - return $this->format_score($my_score[0], $ignoreDecimals); + return round($percentage); + break; + case SCORE_SIMPLE: + return $this->format_score($my_score[0], $ignoreDecimals); + break; } if ($this->custom_enabled && isset($this->custom_display_conv)) {