* @var int $parent
*/
var $parent;
+
+ /**
+ * The grade_category object referenced by $this->parent (PK).
+ * @var object $parent_category
+ */
+ var $parent_category;
/**
* The number of parents this category has.
return $result;
}
-
+
+ /**
+ * Sets this category's and its parent's grade_item.needsupdate to true.
+ * 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.
+ * @return boolean Success or failure
+ */
+ function flag_for_update() {
+ $result = true;
+
+ $this->load_grade_item();
+ $this->grade_item->needsupdate = true;
+ $this->load_parent_category();
+ if (!empty($this->parent_category)) {
+ $result = $result && $this->parent_category->flag_for_update();
+ }
+
+ return $result;
+ }
+
/**
* Generates and saves raw_grades, based on this category's immediate children, then uses the
* associated grade_item to generate matching final grades. These immediate children must first have their own
return $this->grade_item;
}
+
+ /**
+ * Uses $this->parent to instantiate $this->parent_category based on the
+ * referenced record in the DB.
+ * @return object Parent_category
+ */
+ function load_parent_category() {
+ if (empty($this->parent_category) && !empty($this->parent)) {
+ $this->parent_category = grade_category::fetch('id', $this->parent);
+ }
+ return $this->parent_category;
+ }
}
?>
* 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');
+ var $nonfields = array('table', 'nonfields', 'calculation', 'grade_grades_raw', 'scale', 'category');
/**
* The course this grade_item belongs to.
*/
var $categoryid;
+ /**
+ * The grade_category object referenced by $this->categoryid.
+ * @var object $category
+ */
+ var $category;
+
/**
* The name of this grade_item (pushed by the module).
* @var string $itemname
*/
var $iteminfo;
+ /**
+ * Arbitrary idnumber provided by the module responsible.
+ * @var string $idnumber
+ */
+ var $idnumber;
+
/**
* The type of grade (0 = value, 1 = scale, 2 = text)
* @var int $gradetype
}
/**
- * Returns the grade_category object this grade_item belongs to (if any).
+ * Returns the grade_category object this grade_item belongs to (if any) and sets $this->category.
*
* @return mixed grade_category object if applicable, NULL otherwise
*/
- function get_category() {
- if (!empty($this->categoryid)) {
- return grade_category::fetch('id', $this->categoryid);
- } else {
- return null;
+ function load_category() {
+ if (empty($this->category) && !empty($this->categoryid)) {
+ $this->category = grade_category::fetch('id', $this->categoryid);
}
+ return $this->category;
}
/**
}
return $gradevalue;
}
+
+ /**
+ * Sets this grade_item's needsupdate to true. Also looks at parent category, if any, and calls
+ * its flag_for_update() method.
+ * This is triggered whenever any change in any grade_raw may cause grade_finals
+ * for this grade_item 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.
+ * @return boolean Success or failure
+ */
+ function flag_for_update() {
+ $result = true;
+
+ $this->needsupdate = true;
+ $this->load_parent_category();
+ if (!empty($this->parent_category)) {
+ $result = $result && $this->parent_category->flag_for_update();
+ }
+
+ return $result;
+ }
}
?>
$this->assertEqual($calculation, $new_calculation->calculation);
}
- function test_grade_item_get_category() {
+ function test_grade_item_load_category() {
$grade_item = new grade_item($this->grade_items[0]);
- $this->assertTrue(method_exists($grade_item, 'get_category'));
+ $this->assertTrue(method_exists($grade_item, 'load_category'));
- $category = $grade_item->get_category();
- $this->assertEqual($this->grade_categories[1]->fullname, $category->fullname);
+ $grade_item->load_category();
+ $this->assertEqual($this->grade_categories[1]->fullname, $grade_item->category->fullname);
}
/**