]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9506 Finished implementing the propagation of needsupdate flag up the hierarchy...
authornicolasconnault <nicolasconnault>
Fri, 11 May 2007 03:29:00 +0000 (03:29 +0000)
committernicolasconnault <nicolasconnault>
Fri, 11 May 2007 03:29:00 +0000 (03:29 +0000)
lib/grade/grade_category.php
lib/grade/grade_item.php
lib/simpletest/grade/simpletest/testgradeitem.php

index d48dd2e9226688e083fd75f7f1708df195ee1fad..c4c7db977f6160921ab48f6adabf170d1de55458 100644 (file)
@@ -226,14 +226,14 @@ class grade_category extends grade_object {
      */
     function insert() {
         $result = parent::insert();
+        
+        $this->path = grade_category::build_path($this);
 
         // Build path and depth variables
         if (!empty($this->parent)) {
-            $this->path = grade_category::build_path($this);
             $this->depth = $this->get_depth_from_path();
         } else {
             $this->depth = 1;
-            $this->path = "/$this->id";
         }
         
         $this->update();
@@ -302,24 +302,25 @@ class grade_category extends grade_object {
 
         if (empty($this->grade_item)) {
             die("Associated grade_item object does not exist for this grade_category!" . print_object($this)); 
-            // TODO Send error message, this is a critical error: each category MUST have a matching grade_item object
+            // TODO Send error message, this is a critical error: each category MUST have a matching grade_item object and load_grade_item() is supposed to create one!
         }
-
-        $this->grade_item->needsupdate = true;
-        
-        $result = $result && $this->grade_item->update();
+        $this->path = grade_category::build_path($this);
 
         $paths = explode('/', $this->path);
         
-        $wheresql = '';
+        // Remove the first index, which is always empty
+        unset($paths[0]);
         
-        foreach ($paths as $categoryid) {
-            $wheresql .= "iteminstance = $categoryid OR";
+        if (!empty($paths)) {
+            $wheresql = '';
+            
+            foreach ($paths as $categoryid) {
+                $wheresql .= "iteminstance = $categoryid OR ";
+            }
+            $wheresql = substr($wheresql, 0, strrpos($wheresql, 'OR'));
+            $grade_items = set_field_select('grade_items', 'needsupdate', '1', $wheresql);
+            $this->grade_item->update_from_db();
         }
-
-        $wheresql = substr($wheresql, 0, strrpos($wheresql, 'OR'));
-        
-        // TODO use this sql fragment to set needsupdate to true for all grade_items whose iteminstance matches the categoryids
         return $result;
     }
 
index 823759d3427364f7111a34b79ff1f3d0d4fe4328..ab8e8df81e4aeaf39373f9cfd482f5c38311bace 100644 (file)
@@ -40,7 +40,7 @@ class grade_item extends grade_object {
      * Array of class variables that are not part of the DB table fields
      * @var array $nonfields
      */
-    var $nonfields = array('table', 'nonfields', 'calculation', 'grade_grades_raw', 'scale', 'category');
+    var $nonfields = array('table', 'nonfields', 'calculation', 'grade_grades_raw', 'grade_grades_final', 'scale', 'category', 'outcome');
   
     /**
      * The course this grade_item belongs to.
index a64f5204bbe16d51ba78e680d172d11b45d6138e..2d1bb26d18181d13f4fba3812e71c1d7103c8ebf 100755 (executable)
@@ -73,6 +73,7 @@ class grade_item_test extends gradelib_test {
         $grade_item->insert();
 
         // Now check the needsupdate variable, it should have been set to true
+        $category->grade_item->update_from_db();
         $this->assertTrue($category->grade_item->needsupdate);
 
         $last_grade_item = end($this->grade_items);
@@ -93,6 +94,7 @@ class grade_item_test extends gradelib_test {
         $this->assertTrue($grade_item->delete());
 
         // Now check the needsupdate variable, it should have been set to true
+        $category->grade_item->update_from_db();
         $this->assertTrue($category->grade_item->needsupdate);
 
         $this->assertFalse(get_record('grade_items', 'id', $grade_item->id));
@@ -120,7 +122,13 @@ class grade_item_test extends gradelib_test {
         $this->assertTrue($grade_item->update(true));
         
         // Now check the needsupdate variable, it should have been set to true
+        $category->grade_item->update_from_db();
         $this->assertTrue($category->grade_item->needsupdate);
+
+        // Also check parent
+        $category->load_parent_category();
+        $category->parent_category->load_grade_item();
+        $this->assertTrue($category->parent_category->grade_item->needsupdate);
         
         $iteminfo = get_field('grade_items', 'iteminfo', 'id', $this->grade_items[0]->id);
         $this->assertEqual($grade_item->iteminfo, $iteminfo);