Skip to content

Commit 952861f

Browse files
Merge pull request #6251 from christianbeeznest/fide-22574
Gradebook: Fix error gradebook display for student - refs #BT22574
2 parents 720cec1 + 4ddb145 commit 952861f

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

public/main/gradebook/lib/fe/gradebooktable.class.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ public function preloadData()
275275
return $defaultData;
276276
}
277277

278+
private function safeScore(array $score = null): array
279+
{
280+
$score = $score ?? [];
281+
return [
282+
$score[0] ?? 0,
283+
$score[1] ?? 1
284+
];
285+
}
286+
278287
/**
279288
* Function used by SortableTable to generate the data to display.
280289
*
@@ -507,18 +516,21 @@ public function get_table_data($from = 1, $perPage = null, $column = null, $dire
507516
$mode = SCORE_AVERAGE;
508517
if ($userExerciseScoreInCategory) {
509518
$mode = SCORE_SIMPLE;
510-
$result = ExerciseLib::convertScoreToPlatformSetting($totalAverage[0], $totalAverage[1]);
519+
list($avgScore, $avgWeight) = $this->safeScore($totalAverage);
520+
$result = ExerciseLib::convertScoreToPlatformSetting($avgScore, $avgWeight);
521+
511522
$totalAverage[0] = $result['score'];
512523
$totalAverage[1] = $result['weight'];
513524

514-
$result = ExerciseLib::convertScoreToPlatformSetting($totalResult[0], $totalResult[1]);
525+
list($resScore, $resWeight) = $this->safeScore($totalResult);
526+
$result = ExerciseLib::convertScoreToPlatformSetting($resScore, $resWeight);
527+
515528
$totalResult[0] = $result['score'];
516529
$totalResult[1] = $result['weight'];
517530

518-
$result = ExerciseLib::convertScoreToPlatformSetting(
519-
$data['result_score'][0],
520-
$data['result_score'][1]
521-
);
531+
list($safeScore, $safeWeight) = $this->safeScore($data['result_score'] ?? []);
532+
$result = ExerciseLib::convertScoreToPlatformSetting($safeScore, $safeWeight);
533+
522534
$data['my_result_no_float'][0] = $result['score'];
523535
}
524536

0 commit comments

Comments
 (0)