]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9889 Fixed a couple of bugs that were only detected by PHP5. Nothing major at...
authornicolasconnault <nicolasconnault>
Thu, 24 May 2007 02:08:20 +0000 (02:08 +0000)
committernicolasconnault <nicolasconnault>
Thu, 24 May 2007 02:08:20 +0000 (02:08 +0000)
lib/grade/grade_category.php
lib/grade/grade_item.php
lib/grade/grade_tree.php

index 5ffb84531e5b3ae19e89b14da34c0e8e7663aee8..1711b7ef968ee962983e684684a23b60af41a93b 100644 (file)
@@ -653,7 +653,8 @@ class grade_category extends grade_object {
                 return null;
             }
         }
-        return get_class($this->children[0]);
+        reset($this->children);
+        return get_class(current($this->children));
     }
 
     /**
index 1da7943f8e8642b93418a6eb1117110db6c7ab8b..51a9dcf3f01ca296aae74b689d657c4216050d04 100644 (file)
@@ -555,7 +555,8 @@ class grade_item extends grade_object {
             $final_grade->itemid = $this->id;
             $final_grade->userid = $raw_grade->userid;
             if ($final_grade->gradevalue > $this->grademax) {
-                die("FINAL GRADE EXCEEDED grademax FIRST");
+                debugging("FINAL GRADE EXCEEDED grademax FIRST");
+                return false;
             }
             $success = $success & $final_grade->insert();
             $this->grade_grades_final[$final_grade->userid] = $final_grade;
@@ -577,6 +578,9 @@ class grade_item extends grade_object {
             
         if (empty($grade_calculation)) { // There is no calculation in DB
             return false;
+        } elseif (empty($this->calculation) || !is_object($this->calculation)) { // The calculation isn't yet loaded
+            $this->calculation = $grade_calculation;
+            return $grade_calculation;
         } elseif ($grade_calculation->calculation != $this->calculation->calculation) { // The object's calculation is not in sync with the DB (new value??)
             $this->calculation = $grade_calculation;
             return $grade_calculation;
index f63eb031741130ea36f56f604c5fd11342c37786..8f642cd244329415c0441a91ccfec569cf4714a8 100644 (file)
@@ -162,12 +162,12 @@ class grade_tree {
      * @return string Type
      */
     function get_element_type($element) {
-        if (!empty($element->element['object'])) {
+        if (is_object($element)) {
+            $object = $element;
+        } elseif (!empty($element->element['object'])) {
             $object = $element->element['object']; 
         } elseif (!empty($element['object'])) {
             $object = $element['object'];
-        } elseif (is_object($element)) {
-            $object = $element;
         } else {
             debugging("Invalid element given to grade_tree::get_element_type.");
             return false;