Merge branch 'MDL-26571_lesson_scale' of git://github.com/andyjdavis/moodle
[moodle.git] / mod / lesson / lib.php
index 095568e..813ff4c 100644 (file)
@@ -490,7 +490,13 @@ function lesson_grade_item_update($lesson, $grades=NULL) {
             if (!is_array($grade)) {
                 $grades[$key] = $grade = (array) $grade;
             }
-            $grades[$key]['rawgrade'] = ($grade['rawgrade'] * $lesson->grade / 100);
+            //check raw grade isnt null otherwise we erroneously insert a grade of 0
+            if ($grade['rawgrade'] !== null) {
+                $grades[$key]['rawgrade'] = ($grade['rawgrade'] * $lesson->grade / 100);
+            } else {
+                //setting rawgrade to null just in case user is deleting a grade
+                $grades[$key]['rawgrade'] = null;
+            }
         }
     }