From 9127bc5dbf83f9c745e86e567338b71526d7460a Mon Sep 17 00:00:00 2001 From: skodak Date: Wed, 1 Aug 2007 12:40:38 +0000 Subject: [PATCH] outcome related fixes --- grade/edit/tree/calculation.php | 3 ++- grade/edit/tree/index.php | 7 ++++++- grade/edit/tree/item.php | 2 +- grade/edit/tree/item_form.php | 26 ++++++++++++++++++-------- grade/edit/tree/outcomeitem.php | 6 +++--- grade/edit/tree/outcomeitem_form.php | 2 +- grade/lib.php | 3 ++- lib/grade/grade_item.php | 14 ++++++++++++-- 8 files changed, 45 insertions(+), 18 deletions(-) diff --git a/grade/edit/tree/calculation.php b/grade/edit/tree/calculation.php index 6474ea86e5..0edf689a3c 100644 --- a/grade/edit/tree/calculation.php +++ b/grade/edit/tree/calculation.php @@ -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 } diff --git a/grade/edit/tree/index.php b/grade/edit/tree/index.php index d4ab40c7df..da73d2c954 100644 --- a/grade/edit/tree/index.php +++ b/grade/edit/tree/index.php @@ -202,7 +202,12 @@ function print_grade_tree(&$gtree, $element, $moving, &$gpr) { $icon = ''.get_string('modulename', $object->itemmodule).''; } else if ($object->itemtype == 'manual') { //TODO: add manual grading icon - $icon = ''.get_string('manualgrade', 'grades').''; // TODO: localize + if (empty($object->outcomeid)) { + $icon = ''.get_string('manualgrade', 'grades').''; // TODO: localize + } else { + $icon = ''.get_string('outcome', 'grades').''; + + } } break; case 'courseitem': diff --git a/grade/edit/tree/item.php b/grade/edit/tree/item.php index e32af6f64f..18f4abefd1 100644 --- a/grade/edit/tree/item.php +++ b/grade/edit/tree/item.php @@ -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.'&courseid='.$courseid; + $url = $CFG->wwwroot.'/grade/edit/tree/outcomeitem.php?id='.$id.'&courseid='.$courseid; redirect($gpr->add_url_params($url)); } diff --git a/grade/edit/tree/item_form.php b/grade/edit/tree/item_form.php index 7e3d9e9c32..71bc94fdea 100644 --- a/grade/edit/tree/item_form.php +++ b/grade/edit/tree/item_form.php @@ -117,18 +117,28 @@ class edit_item_form extends moodleform { 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'); diff --git a/grade/edit/tree/outcomeitem.php b/grade/edit/tree/outcomeitem.php index 32020be9d5..8101f2e52f 100644 --- a/grade/edit/tree/outcomeitem.php +++ b/grade/edit/tree/outcomeitem.php @@ -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.'&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); @@ -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)); diff --git a/grade/edit/tree/outcomeitem_form.php b/grade/edit/tree/outcomeitem_form.php index eb9a5058a8..49e70ed706 100644 --- a/grade/edit/tree/outcomeitem_form.php +++ b/grade/edit/tree/outcomeitem_form.php @@ -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); diff --git a/grade/lib.php b/grade/lib.php index 0d939e1890..11fccb7805 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -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.'&id='.$object->id; $url = $gpr->add_url_params($url); $calculation_icon = '