diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index 09a897b2693..6ef41d8cc6c 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -1760,11 +1760,15 @@ class grade_item extends grade_object { // add missing final grade values // not graded (null) is counted as 0 - the spreadsheet way + $allinputsnull = true; foreach($useditems as $gi) { - if (!array_key_exists('gi'.$gi, $params)) { + if (!array_key_exists('gi'.$gi, $params) || is_null($params['gi'.$gi])) { $params['gi'.$gi] = 0; } else { $params['gi'.$gi] = (float)$params['gi'.$gi]; + if ($gi != $this->id) { + $allinputsnull = false; + } } } @@ -1789,16 +1793,24 @@ class grade_item extends grade_object { return true; } - // do the calculation - $this->formula->set_params($params); - $result = $this->formula->evaluate(); - - if ($result === false) { + if ($allinputsnull) { $grade->finalgrade = null; + $result = true; } else { - // normalize - $grade->finalgrade = $this->bounded_grade($result); + + // do the calculation + $this->formula->set_params($params); + $result = $this->formula->evaluate(); + + if ($result === false) { + $grade->finalgrade = null; + + } else { + // normalize + $grade->finalgrade = $this->bounded_grade($result); + } + } // update in db if changed