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();
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();
+ }
}
?>
$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() {
/// 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);
/// 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