return false;
}
}
+
+ /**
+ * Extends grade_object->insert() to prevent a final grade from being inserted if it already exists
+ * (If a final grade already has the same userid/itemid key combination). It will update it instead.
+ *
+ */
+ function insert() {
+ $exists = count_records('grade_grades_final', 'userid', $this->userid, 'itemid', $this->itemid);
+ if ($exists) {
+ return $this->update();
+ } else {
+ return parent::insert();
+ }
+ }
}
?>
$this->outcomeid = $this->outcome->id;
}
+ // 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;
+ $this->gradetype = GRADE_TYPE_SCALE;
+ }
+
if (!empty($this->scale->id)) {
$this->scaleid = $this->scale->id;
}
* @return int ID of the new grade_item 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;
+ $this->gradetype = GRADE_TYPE_SCALE;
+ }
+
$result = parent::insert();
// Notify parent category of need to update. Note that a grade_item may not have a categoryid.
$final_grade->gradevalue = $this->adjust_grade($raw_grade);
$final_grade->itemid = $this->id;
$final_grade->userid = $raw_grade->userid;
+
if ($final_grade->gradevalue > $this->grademax) {
debugging("FINAL GRADE EXCEEDED grademax FIRST");
return false;
// //
///////////////////////////////////////////////////////////////////////////
+require_once $CFG->libdir . '/grade/grade_category.php';
+require_once $CFG->libdir . '/grade/grade_item.php';
+require_once $CFG->libdir . '/grade/grade_grades_final.php';
+require_once $CFG->libdir . '/grade/grade_grades_raw.php';
+
/**
* This class represents a complete tree of categories, grade_items and final grades,
* organises as an array primarily, but which can also be converted to other formats.
$this->tree_array = $this->get_tree($include_grades);
}
- $this->first_sortorder = key($this->tree_array);
+ if (!empty($this->tree_array)) {
+ $this->first_sortorder = key($this->tree_array);
+ }
}
/**
// Get ordered list of grade_items (not category type)
$query = "SELECT * FROM $items_table WHERE itemtype <> 'category' $itemconstraint ORDER BY sortorder";
$grade_items = get_records_sql($query);
-
+
+ if (empty($grade_items)) {
+ return null;
+ }
+
// For every grade_item that doesn't have a parent category, create category fillers
foreach ($grade_items as $itemid => $item) {
if (empty($item->categoryid)) {
$item = new grade_item($item);
- $fillers[$item->sortorder] = $item;
+ if (empty($item->sortorder)) {
+ $fillers[] = $item;
+ } else {
+ $fillers[$item->sortorder] = $item;
+ }
}
}
-
+
// Get all top categories
$query = "SELECT $category_table.*, sortorder FROM $category_table, $items_table
WHERE iteminstance = $category_table.id $catconstraint ORDER BY sortorder";
$topcats = get_records_sql($query);
if (empty($topcats)) {
- return null;
+ $topcats = $grade_items;
+ $topcats[0] = new stdClass();
+ $topcats[0]->sortorder = 0;
+ $topcats[0]->courseid = $this->courseid;
}
// If any of these categories has grade_items as children, create a topcategory filler with colspan=count(children)