diff --git a/grade/edit/tree/category.php b/grade/edit/tree/category.php index 15da050e7b3..95ccb79f220 100644 --- a/grade/edit/tree/category.php +++ b/grade/edit/tree/category.php @@ -44,7 +44,6 @@ $gpr = new grade_plugin_return(); $returnurl = $gpr->get_return_url('index.php?id='.$course->id); -$mform = new edit_category_form(null, array('gpr'=>$gpr)); $heading = get_string('categoryedit', 'grades'); if ($id) { @@ -75,7 +74,7 @@ if ($id) { $category = $grade_category->get_record_data(); } -$mform->set_data($category); +$mform = new edit_category_form(null, array('current'=>$category, 'gpr'=>$gpr)); if ($mform->is_cancelled()) { redirect($returnurl); diff --git a/grade/edit/tree/category_form.php b/grade/edit/tree/category_form.php index e464b0b58b8..7834401779e 100644 --- a/grade/edit/tree/category_form.php +++ b/grade/edit/tree/category_form.php @@ -32,6 +32,8 @@ class edit_category_form extends moodleform { global $CFG, $COURSE; $mform =& $this->_form; + $category = $this->_customdata['current']; + $this->aggregation_options = array(GRADE_AGGREGATE_MEAN =>get_string('aggregatemean', 'grades'), GRADE_AGGREGATE_WEIGHTED_MEAN =>get_string('aggregateweightedmean', 'grades'), GRADE_AGGREGATE_WEIGHTED_MEAN2 =>get_string('aggregateweightedmean2', 'grades'), @@ -127,11 +129,23 @@ class edit_category_form extends moodleform { //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE); $options = array(0=>get_string('usenoscale', 'grades')); - if ($scales = get_records('scale')) { + if ($scales = grade_scale::fetch_all_local($COURSE->id)) { foreach ($scales as $scale) { - $options[$scale->id] = format_string($scale->name); + $options[$scale->id] = $scale->get_name(); } } + if ($scales = grade_scale::fetch_all_global()) { + foreach ($scales as $scale) { + $options[$scale->id] = $scale->get_name(); + } + } + // ugly BC hack - it was possbile to use custom scale from other courses :-( + if (!empty($category->grade_item_scaleid) and !isset($options[$category->grade_item_scaleid])) { + if ($scale = grade_scale::fetch(array('id'=>$category->grade_item_scaleid))) { + $options[$scale->id] = $scale->get_name().' '.get_string('incorrectcustomscale', 'grades'); + } + } + $mform->addElement('select', 'grade_item_scaleid', get_string('scale'), $options); $mform->setHelpButton('grade_item_scaleid', array('scaleid', get_string('scaleid', 'grades'), 'grade'), true); $mform->disabledIf('grade_item_scaleid', 'grade_item_gradetype', 'noteq', GRADE_TYPE_SCALE); @@ -238,6 +252,8 @@ class edit_category_form extends moodleform { //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); +//------------------------------------------------------------------------------- + $this->set_data($category); } diff --git a/grade/edit/tree/item.php b/grade/edit/tree/item.php index 7de1c671601..8de555ec331 100644 --- a/grade/edit/tree/item.php +++ b/grade/edit/tree/item.php @@ -43,12 +43,6 @@ require_capability('moodle/grade:manage', $context); $gpr = new grade_plugin_return(); $returnurl = $gpr->get_return_url('index.php?id='.$course->id); -$mform = new edit_item_form(null, array('gpr'=>$gpr)); - -if ($mform->is_cancelled()) { - redirect($returnurl); -} - $heading = get_string('itemsedit', 'grades'); if ($grade_item = grade_item::fetch(array('id'=>$id, 'courseid'=>$courseid))) { @@ -97,9 +91,12 @@ if ($parent_category->aggregation == GRADE_AGGREGATE_SUM or $parent_category->ag $item->aggregationcoef = format_float($item->aggregationcoef, 4); } -$mform->set_data($item); +$mform = new edit_item_form(null, array('current'=>$item, 'gpr'=>$gpr)); -if ($data = $mform->get_data(false)) { +if ($mform->is_cancelled()) { + redirect($returnurl); + +} else if ($data = $mform->get_data(false)) { if (!isset($data->aggregationcoef)) { $data->aggregationcoef = 0; diff --git a/grade/edit/tree/item_form.php b/grade/edit/tree/item_form.php index 1a99da31344..d8eba5604b1 100644 --- a/grade/edit/tree/item_form.php +++ b/grade/edit/tree/item_form.php @@ -33,6 +33,8 @@ class edit_item_form extends moodleform { $mform =& $this->_form; + $item = $this->_customdata['current']; + /// visible elements $mform->addElement('header', 'general', get_string('gradeitem', 'grades')); @@ -57,11 +59,23 @@ class edit_item_form extends moodleform { //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE); $options = array(0=>get_string('usenoscale', 'grades')); - if ($scales = get_records('scale')) { + if ($scales = grade_scale::fetch_all_local($COURSE->id)) { foreach ($scales as $scale) { - $options[$scale->id] = format_string($scale->name); + $options[$scale->id] = $scale->get_name(); } } + if ($scales = grade_scale::fetch_all_global()) { + foreach ($scales as $scale) { + $options[$scale->id] = $scale->get_name(); + } + } + // ugly BC hack - it was possbile to use custom scale from other courses :-( + if (!empty($item->scaleid) and !isset($options[$item->scaleid])) { + if ($scale = grade_scale::fetch(array('id'=>$item->scaleid))) { + $options[$scale->id] = $scale->get_name().get_string('incorrectcustomscale', 'grades'); + } + } + $mform->addElement('select', 'scaleid', get_string('scale'), $options); $mform->setHelpButton('scaleid', array('scaleid', get_string('scaleid', 'grades'), 'grade'), true); $mform->disabledIf('scaleid', 'gradetype', 'noteq', GRADE_TYPE_SCALE); @@ -184,6 +198,8 @@ class edit_item_form extends moodleform { //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); +//------------------------------------------------------------------------------- + $this->set_data($item); } diff --git a/lang/en_utf8/grades.php b/lang/en_utf8/grades.php index df9f0dd8947..adb955a0a1f 100644 --- a/lang/en_utf8/grades.php +++ b/lang/en_utf8/grades.php @@ -306,6 +306,7 @@ $string['importsuccess'] = 'Grade import success'; $string['importxml'] = 'Import XML'; $string['includescalesinaggregation'] = 'Include scales in aggregation'; $string['incorrectcourseid'] = 'Course ID was incorrect'; +$string['incorrectcustomscale'] = '(Incorrect custom scale, please change.)'; $string['incorrectminmax'] = 'The minimum must be lower than the maximum'; $string['inherit'] = 'Inherit'; $string['intersectioninfo'] = 'Student/Grade info';