MLD-9506 Grade_grades_raw object now infers grademax and grademin from scale, if scaleid is given at the time of insert of update.

This commit is contained in:
nicolasconnault 2007-05-09 08:56:08 +00:00
parent f67e327e37
commit 6c76ea8dfa
3 changed files with 37 additions and 2 deletions

View File

@ -206,6 +206,9 @@ class grade_grades_raw extends grade_object {
if (!empty($this->scale->id)) {
$this->scaleid = $this->scale->id;
$this->grademin = 0;
$this->scale->load_items();
$this->grademax = count($this->scale->scale_items);
}
$result = parent::update();
@ -226,6 +229,23 @@ class grade_grades_raw extends grade_object {
return false;
}
}
/**
* In addition to perform parent::insert(), this infers the grademax from the scale if such is given, and
* sets grademin to 0 if scale is given.
* @return int ID of the new grades_grade_raw record.
*/
function insert() {
// Retrieve scale and infer grademax from it
if (!empty($this->scaleid)) {
$this->load_scale();
$this->scale->load_items();
$this->grademax = count ($this->scale->scale_items);
$this->grademin = 0;
}
return parent::insert();
}
}
?>

View File

@ -67,6 +67,19 @@ class grade_raw_test extends gradelib_test {
$this->assertEqual($grade_grades_raw->id, $last_grade_grades_raw->id + 1);
$this->assertFalse(empty($grade_grades_raw->timecreated));
$this->assertFalse(empty($grade_grades_raw->timemodified));
// try a scale raw grade
$grade_grades_raw = new grade_grades_raw();
$grade_grades_raw->itemid = $this->grade_items[0]->id;
$grade_grades_raw->userid = 1;
$grade_grades_raw->gradevalue = 6;
$grade_grades_raw->scaleid = $this->scale[0]->id;
$grade_grades_raw->insert();
$this->assertEqual(7, $grade_grades_raw->grademax);
$this->assertEqual(0, $grade_grades_raw->grademin);
}
function test_grade_grades_raw_update() {

View File

@ -196,7 +196,8 @@ class gradelib_test extends UnitTestCase {
/// Adding fields to table grade_grades_text
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('gradesid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
$table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
@ -207,7 +208,8 @@ class gradelib_test extends UnitTestCase {
/// Adding keys to table grade_grades_text
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('gradesid', XMLDB_KEY_FOREIGN, array('gradesid'), 'grade_grades_raw', array('id'));
$table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
$table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
$table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
/// Launch create table for grade_grades_text