]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9506 Fixed a bug with the fetch method. This method should not be called statical...
authornicolasconnault <nicolasconnault>
Fri, 11 May 2007 02:43:46 +0000 (02:43 +0000)
committernicolasconnault <nicolasconnault>
Fri, 11 May 2007 02:43:46 +0000 (02:43 +0000)
lib/grade/grade_category.php
lib/simpletest/grade/simpletest/testgradecategory.php

index b1507caac47e6460385768b14435845586975893..d48dd2e9226688e083fd75f7f1708df195ee1fad 100644 (file)
@@ -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;
     }
index 3d3a176813bb4a7e046c6e32469b001740eb6e54..07528c0f24e641aa9b44451833c967c4c501a676 100755 (executable)
@@ -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() {