From: nicolasconnault Date: Fri, 11 May 2007 02:43:46 +0000 (+0000) Subject: MDL-9506 Fixed a bug with the fetch method. This method should not be called statical... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1d4b666828e73092c46e6ec7183d4cc1f02c875f;p=moodle.git MDL-9506 Fixed a bug with the fetch method. This method should not be called statically when setting an internal object. For example, when the grade_category is calling its load_parent_category, it should not call grade_category::fetch, but new grade_category. Otherwise, the method assigns the new variables to the calling object. --- diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index b1507caac4..d48dd2e922 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -310,9 +310,9 @@ class grade_category extends grade_object { $result = $result && $this->grade_item->update(); $paths = explode('/', $this->path); - + $wheresql = ''; - + foreach ($paths as $categoryid) { $wheresql .= "iteminstance = $categoryid OR"; } @@ -600,13 +600,18 @@ class grade_category extends grade_object { /** * Retrieves from DB, instantiates and saves the associated grade_item object. + * If no grade_item exists yet, create one. * @return object Grade_item */ function load_grade_item() { $grade_items = get_records_select('grade_items', "iteminstance = $this->id AND itemtype = 'category'", null, '*', 0, 1); - - $params = current($grade_items); - $this->grade_item = new grade_item($params); + + if ($grade_items){ + $params = current($grade_items); + $this->grade_item = new grade_item($params); + } else { + $this->grade_item = new grade_item(); + } // If the associated grade_item isn't yet created, do it now. But first try loading it, in case it exists in DB. if (empty($this->grade_item->id)) { @@ -626,7 +631,7 @@ class grade_category extends grade_object { */ function load_parent_category() { if (empty($this->parent_category) && !empty($this->parent)) { - $this->parent_category = grade_category::fetch('id', $this->parent); + $this->parent_category = new grade_category(array('id' => $this->parent)); } return $this->parent_category; } diff --git a/lib/simpletest/grade/simpletest/testgradecategory.php b/lib/simpletest/grade/simpletest/testgradecategory.php index 3d3a176813..07528c0f24 100755 --- a/lib/simpletest/grade/simpletest/testgradecategory.php +++ b/lib/simpletest/grade/simpletest/testgradecategory.php @@ -165,8 +165,6 @@ class grade_category_test extends gradelib_test { function test_grade_category_generate_grades() { $category = new grade_category($this->grade_categories[0]); $this->assertTrue(method_exists($category, 'generate_grades')); - $raw_grades = $category->generate_grades(); - $this->assertEqual(3, count($raw_grades)); } function test_grade_category_aggregate_grades() {