MDL-73378 gradebook: Category grade null when all subgrades are null

This commit is contained in:
Daniel Neis Araujo
2023-10-31 13:55:10 -03:00
parent 933c9c0756
commit fcaf6f601e
+17 -3
View File
@@ -722,6 +722,16 @@ class grade_category extends grade_object {
}
// First, check if all grades are null, because the final grade will be null
// even when aggreateonlygraded is true.
$allnull = true;
foreach ($grade_values as $v) {
if (!is_null($v)) {
$allnull = false;
break;
}
}
// For items with no value, and not excluded - either set their grade to 0 or exclude them.
foreach ($items as $itemid=>$value) {
if (!isset($grade_values[$itemid]) and !in_array($itemid, $excluded)) {
@@ -789,9 +799,13 @@ class grade_category extends grade_object {
$result['grademin'] = 0;
}
// Recalculate the grade back to requested range.
$finalgrade = grade_grade::standardise_score($agg_grade, 0, 1, $result['grademin'], $result['grademax']);
$grade->finalgrade = $this->grade_item->bounded_grade($finalgrade);
if ($allnull) {
$grade->finalgrade = null;
} else {
// Recalculate the grade back to requested range.
$finalgrade = grade_grade::standardise_score($agg_grade, 0, 1, $result['grademin'], $result['grademax']);
$grade->finalgrade = $this->grade_item->bounded_grade($finalgrade);
}
$oldrawgrademin = $grade->rawgrademin;
$oldrawgrademax = $grade->rawgrademax;