gradebook MDL-23181 committing grade item patch
authorAndrew Davis <andrew@affinitysoftware.net>
Wed, 14 Jul 2010 08:51:19 +0000 (08:51 +0000)
committerAndrew Davis <andrew@affinitysoftware.net>
Wed, 14 Jul 2010 08:51:19 +0000 (08:51 +0000)
lib/grade/grade_item.php

index 09a897b..6ef41d8 100644 (file)
@@ -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