}
// module items and items without grade can not have calculation
-if ($grade_item->is_normal_item() or ($grade_item->gradetype != GRADE_TYPE_VALUE and $grade_item->gradetype != GRADE_TYPE_SCALE)) {
+if (($grade_item->is_normal_item() and !$grade_item->is_outcome_item())
+ or ($grade_item->gradetype != GRADE_TYPE_VALUE and $grade_item->gradetype != GRADE_TYPE_SCALE)) {
redirect($returnurl, get_string('erornocalculationallowed', 'grades')); //TODO: localize
}
$icon = '<img src="'.$CFG->modpixpath.'/'.$object->itemmodule.'/icon.gif" class="icon" alt="'.get_string('modulename', $object->itemmodule).'"/>';
} else if ($object->itemtype == 'manual') {
//TODO: add manual grading icon
- $icon = '<img src="'.$CFG->pixpath.'/t/edit.gif" class="icon" alt="'.get_string('manualgrade', 'grades').'"/>'; // TODO: localize
+ if (empty($object->outcomeid)) {
+ $icon = '<img src="'.$CFG->pixpath.'/t/edit.gif" class="icon" alt="'.get_string('manualgrade', 'grades').'"/>'; // TODO: localize
+ } else {
+ $icon = '<img src="'.$CFG->pixpath.'/i/outcomes.gif" class="icon" alt="'.get_string('outcome', 'grades').'"/>';
+
+ }
}
break;
case 'courseitem':
if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
// redirect if outcomeid present
if (!empty($item->outcomeid) && !empty($CFG->enableoutcomes)) {
- $url = $CFG->wwwroot.'/grade/edit/tree/outcome.php?id='.$id.'&courseid='.$courseid;
+ $url = $CFG->wwwroot.'/grade/edit/tree/outcomeitem.php?id='.$id.'&courseid='.$courseid;
redirect($gpr->add_url_params($url));
}
if ($id = $mform->getElementValue('id')) {
$grade_item = grade_item::fetch(array('id'=>$id));
- if ($grade_item->is_normal_item()) {
- // following items are set up from modules and should not be overrided by user
- $mform->hardFreeze('itemname,idnumber,gradetype,grademax,grademin,scaleid');
- $mform->removeElement('calculation');
-
- } else if ($grade_item->is_manual_item()) {
- // manual grade item does not use these - uses only final grades
+ if ($grade_item->is_outcome_item()) {
+ // we have to prevent incompatible modifications of outcomes
$mform->removeElement('plusfactor');
$mform->removeElement('multfactor');
+ $mform->removeElement('grademax');
+ $mform->removeElement('grademin');
+ $mform->removeElement('gradetype');
+ $mform->hardFreeze('scaleid');
+ } else {
+ if ($grade_item->is_normal_item()) {
+ // following items are set up from modules and should not be overrided by user
+ $mform->hardFreeze('itemname,idnumber,gradetype,grademax,grademin,scaleid');
+ $mform->removeElement('calculation');
+
+ } else if ($grade_item->is_manual_item()) {
+ // manual grade item does not use these - uses only final grades
+ $mform->removeElement('plusfactor');
+ $mform->removeElement('multfactor');
+
+ }
}
-
//remove the aggregation coef element if not needed
if ($grade_item->is_course_item()) {
$mform->removeElement('aggregationcoef');
if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
// redirect if outcomeid present
if (empty($item->outcomeid)) {
- $url = $CFG->wwwroot.'/grade/edit/tree/outcome.php?id='.$id.'&courseid='.$courseid;
+ $url = $CFG->wwwroot.'/grade/edit/tree/item.php?id='.$id.'&courseid='.$courseid;
redirect($gpr->add_url_params($url));
}
-// $item->calculation = grade_item::denormalize_formula($item->calculation, $course->id);
+ $item->calculation = grade_item::denormalize_formula($item->calculation, $course->id);
if ($item->itemtype == 'mod') {
$cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid);
if ($data = $mform->get_data(false)) {
if (array_key_exists('calculation', $data)) {
-// $data->calculation = grade_item::normalize_formula($data->calculation, $course->id);
+ $data->calculation = grade_item::normalize_formula($data->calculation, $course->id);
}
$grade_item = new grade_item(array('id'=>$id, 'courseid'=>$courseid));
$mform->setDefault('cmid', 0);
-// $mform->addElement('text', 'calculation', get_string('calculation', 'grades'));
+ $mform->addElement('text', 'calculation', get_string('calculation', 'grades'));
$mform->addElement('text', 'aggregationcoef', get_string('aggregationcoef', 'grades'));
$mform->setDefault('aggregationcoef', 0.0);
$streditcalculation = get_string('editcalculation', 'grades');
// show calculation icon only when calculation possible
- if (!$object->is_normal_item() and ($object->gradetype == GRADE_TYPE_SCALE or $object->gradetype == GRADE_TYPE_VALUE)) {
+ if ((!$object->is_normal_item() or $object->is_outcome_item())
+ and ($object->gradetype == GRADE_TYPE_SCALE or $object->gradetype == GRADE_TYPE_VALUE)) {
$url = $CFG->wwwroot.'/grade/edit/tree/calculation.php?courseid='.$this->courseid.'&id='.$object->id;
$url = $gpr->add_url_params($url);
$calculation_icon = '<a href="'. $url.'"><img src="'.$CFG->pixpath.'/t/calc.gif" class="iconsmall" alt="'
return ($this->itemtype == 'manual');
}
+ /**
+ * Is this an outcome item?
+ * @return boolean
+ */
+ function is_outcome_item() {
+ return !empty($this->outcomeid);
+ }
+
/**
* Is the grade item normal - associated with module, plugin or something else?
* @return boolean
}
// if we can update the raw grade, do update it
- if (!$this->is_normal_item() or $this->plusfactor != 0 or $this->multfactor != 1
+ if ($this->is_outcome_item() or !$this->is_normal_item()
+ or $this->plusfactor != 0 or $this->multfactor != 1
or !events_is_registered('grade_updated', $this->itemtype.'/'.$this->itemmodule)) {
if (!$grade->overridden) {
$grade->overridden = time();
}
// calculated grades can not be updated; course and category can not be updated because they are aggregated
- if ($this->is_calculated() or !$this->is_normal_item() or $this->gradetype == GRADE_TYPE_NONE or $this->is_locked()) {
+ if ($this->is_calculated() or $this->is_outcome_item() or !$this->is_normal_item()
+ or $this->gradetype == GRADE_TYPE_NONE or $this->is_locked()) {
return false;
}