MDL-9506 Finished implementing the propagation of needsupdate flag up the hierarchy when a lower element justifies it. All unit tests pass. The next task is to implement the generation of raw grades and final grades based on this needsupdate setting.

This commit is contained in:
nicolasconnault 2007-05-11 03:29:00 +00:00
parent 1d4b666828
commit 77d2540eea
3 changed files with 24 additions and 15 deletions

View File

@ -226,14 +226,14 @@ class grade_category extends grade_object {
*/
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();
@ -302,24 +302,25 @@ class grade_category extends grade_object {
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;
}

View File

@ -40,7 +40,7 @@ class grade_item extends grade_object {
* 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.

View File

@ -73,6 +73,7 @@ class grade_item_test extends gradelib_test {
$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);
@ -93,6 +94,7 @@ class grade_item_test extends gradelib_test {
$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));
@ -120,7 +122,13 @@ class grade_item_test extends gradelib_test {
$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);