*/
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();
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;
}
* 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.
$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);
$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));
$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);