Skip to content

Commit

Permalink
MDL-73378 gradebook: Category grade null when all subgrades are null
Browse files Browse the repository at this point in the history
  • Loading branch information
danielneis committed Oct 31, 2023
1 parent 859df15 commit 3632537
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/grade/grade_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,16 @@ private function aggregate_grades($userid,

}

// 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)) {
Expand Down Expand Up @@ -789,9 +799,13 @@ private function aggregate_grades($userid,
$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;
Expand Down

0 comments on commit 3632537

Please sign in to comment.