// 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;
+ }
}
}
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