]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9506 small fix
authornicolasconnault <nicolasconnault>
Thu, 10 May 2007 08:58:00 +0000 (08:58 +0000)
committernicolasconnault <nicolasconnault>
Thu, 10 May 2007 08:58:00 +0000 (08:58 +0000)
lib/grade/grade_category.php
lib/grade/grade_item.php

index 63064ab8ada99ee206e6567ba44bbf9819639bfe..b1507caac47e6460385768b14435845586975893 100644 (file)
@@ -193,17 +193,10 @@ class grade_category extends grade_object {
 
         $result = parent::update();
        
-       /**
-        // Notify parent category of need to update.
+        // Use $this->path to update all parent categories
         if ($result && $qualifies) {
-            $this->load_parent_category();
-            if (!empty($this->parent_category)) {
-                if (!$this->parent_category->flag_for_update()) {
-                    return false;
-                }
-            }
+            $this->flag_for_update();
         } 
-*/
         return $result;
     }
     
@@ -256,7 +249,7 @@ class grade_category extends grade_object {
             
             $this->grade_item = $grade_item;
         }
-  /**      
+        
         // Notify parent category of need to update.
         if ($result) {
             $this->load_parent_category();
@@ -266,7 +259,6 @@ class grade_category extends grade_object {
                 }
             }
         } 
-*/
         return $result;
     }
     
@@ -299,7 +291,8 @@ class grade_category extends grade_object {
      * This is triggered whenever any change in any lower level may cause grade_finals
      * for this category to require an update. The flag needs to be propagated up all
      * levels until it reaches the top category. This is then used to determine whether or not
-     * to regenerate the raw and final grades for each category grade_item.
+     * to regenerate the raw and final grades for each category grade_item. This is accomplished
+     * thanks to the path variable, so we don't need to use recursion.
      * @return boolean Success or failure
      */
     function flag_for_update() {
@@ -316,11 +309,17 @@ class grade_category extends grade_object {
         
         $result = $result && $this->grade_item->update();
 
-        $this->load_parent_category();
-        if (!empty($this->parent_category)) {
-            $result = $result && $this->parent_category->flag_for_update();
+        $paths = explode('/', $this->path);
+
+        $wheresql = '';
+
+        foreach ($paths as $categoryid) {
+            $wheresql .= "iteminstance = $categoryid OR";
         }
 
+        $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 6955db9734491c8d71ca3e29de7b4a97e996f34e..bee72d733c1161b02f96a852ab9db3cff0bae144 100644 (file)
@@ -24,7 +24,8 @@
 ///////////////////////////////////////////////////////////////////////////
 
 require_once('grade_object.php');
-
+global $db;
+$db->debug = true;
 /**
  * Class representing a grade item. It is responsible for handling its DB representation,
  * modifying and returning its metadata.
@@ -759,9 +760,9 @@ class grade_item extends grade_object {
      * @return boolean Success or failure
      */
     function flag_for_update() {
-        $result = true;
-
         $this->needsupdate = true;
+
+        $result = $this->update();
         $category = $this->get_category();
 
         if (!empty($category)) {