$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;
}
$this->grade_item = $grade_item;
}
- /**
+
// Notify parent category of need to update.
if ($result) {
$this->load_parent_category();
}
}
}
-*/
return $result;
}
* 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() {
$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;
}
///////////////////////////////////////////////////////////////////////////
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.
* @return boolean Success or failure
*/
function flag_for_update() {
- $result = true;
-
$this->needsupdate = true;
+
+ $result = $this->update();
$category = $this->get_category();
if (!empty($category)) {