From cb64c6b257b0e3153eb712861824c8d925df913b Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Thu, 10 May 2007 08:58:00 +0000 Subject: [PATCH] MDL-9506 small fix --- lib/grade/grade_category.php | 29 ++++++++++++++--------------- lib/grade/grade_item.php | 7 ++++--- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 63064ab8ad..b1507caac4 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -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; } diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index 6955db9734..bee72d733c 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -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)) { -- 2.39.5