outcome related fixes

This commit is contained in:
skodak 2007-08-01 12:40:38 +00:00
parent 4d3145f3d3
commit 9127bc5dbf
8 changed files with 45 additions and 18 deletions

View File

@ -24,7 +24,8 @@ if (!$grade_item = grade_item::fetch(array('id'=>$id, 'courseid'=>$course->id)))
}
// 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
}

View File

@ -202,7 +202,12 @@ function print_grade_tree(&$gtree, $element, $moving, &$gpr) {
$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
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':

View File

@ -29,7 +29,7 @@ if ($mform->is_cancelled()) {
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.'&amp;courseid='.$courseid;
$url = $CFG->wwwroot.'/grade/edit/tree/outcomeitem.php?id='.$id.'&amp;courseid='.$courseid;
redirect($gpr->add_url_params($url));
}

View File

@ -117,6 +117,16 @@ class edit_item_form extends moodleform {
if ($id = $mform->getElementValue('id')) {
$grade_item = grade_item::fetch(array('id'=>$id));
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');
@ -128,7 +138,7 @@ class edit_item_form extends moodleform {
$mform->removeElement('multfactor');
}
}
//remove the aggregation coef element if not needed
if ($grade_item->is_course_item()) {
$mform->removeElement('aggregationcoef');

View File

@ -30,11 +30,11 @@ if ($mform->is_cancelled() || empty($CFG->enableoutcomes)) {
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.'&amp;courseid='.$courseid;
$url = $CFG->wwwroot.'/grade/edit/tree/item.php?id='.$id.'&amp;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);
@ -48,7 +48,7 @@ if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
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));

View File

@ -38,7 +38,7 @@ class edit_outcomeitem_form extends moodleform {
$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);

View File

@ -822,7 +822,8 @@ class grade_tree {
$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.'&amp;id='.$object->id;
$url = $gpr->add_url_params($url);
$calculation_icon = '<a href="'. $url.'"><img src="'.$CFG->pixpath.'/t/calc.gif" class="iconsmall" alt="'

View File

@ -827,6 +827,14 @@ class grade_item extends grade_object {
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
@ -1180,7 +1188,8 @@ class grade_item extends grade_object {
}
// 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();
@ -1260,7 +1269,8 @@ class grade_item extends grade_object {
}
// 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;
}