From a15428a2f6f4ed5bd558b4bf57a2e7d6b43070fb Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Thu, 24 May 2007 02:08:20 +0000 Subject: [PATCH] MDL-9889 Fixed a couple of bugs that were only detected by PHP5. Nothing major at all. --- lib/grade/grade_category.php | 3 ++- lib/grade/grade_item.php | 6 +++++- lib/grade/grade_tree.php | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 5ffb84531e..1711b7ef96 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -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)); } /** diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index 1da7943f8e..51a9dcf3f0 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -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; diff --git a/lib/grade/grade_tree.php b/lib/grade/grade_tree.php index f63eb03174..8f642cd244 100644 --- a/lib/grade/grade_tree.php +++ b/lib/grade/grade_tree.php @@ -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; -- 2.39.5