From d9be236f5d9c75749ce9def62f9880e6b9cf9c00 Mon Sep 17 00:00:00 2001 From: skodak Date: Thu, 7 May 2009 08:39:29 +0000 Subject: [PATCH] MDL-19091 removed custom scales from different courses + added BC hack; backported from MOODLE_19_STABLE --- grade/edit/tree/category.php | 3 +-- grade/edit/tree/category_form.php | 19 +++++++++++++++++-- grade/edit/tree/item.php | 13 +++++-------- grade/edit/tree/item_form.php | 19 +++++++++++++++++-- lang/en_utf8/grades.php | 1 + 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/grade/edit/tree/category.php b/grade/edit/tree/category.php index a6fd5c673b..4a3aabc6b3 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 8e5038a4b9..5ceb1033a1 100644 --- a/grade/edit/tree/category_form.php +++ b/grade/edit/tree/category_form.php @@ -33,6 +33,8 @@ class edit_category_form extends moodleform { global $CFG, $COURSE, $DB; $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'), @@ -128,9 +130,20 @@ class edit_category_form extends moodleform { //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE); $options = array(0=>get_string('usenoscale', 'grades')); - if ($scales = $DB->get_records('scale')) { + if ($scales = grade_scale::fetch_all_local($COURSE->id)) { + foreach ($scales as $scale) { + $options[$scale->id] = $scale->get_name(); + } + } + if ($scales = grade_scale::fetch_all_global()) { foreach ($scales as $scale) { - $options[$scale->id] = format_string($scale->name); + $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); @@ -239,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 cca77c9ebb..ac30d0ca35 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 ($mform->is_cancelled()) { + redirect($returnurl); -if ($data = $mform->get_data()) { +} 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 4dd0cd2026..1bcc6a8071 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,9 +59,20 @@ class edit_item_form extends moodleform { //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE); $options = array(0=>get_string('usenoscale', 'grades')); - if ($scales = $DB->get_records('scale')) { + if ($scales = grade_scale::fetch_all_local($COURSE->id)) { + foreach ($scales as $scale) { + $options[$scale->id] = $scale->get_name(); + } + } + if ($scales = grade_scale::fetch_all_global()) { foreach ($scales as $scale) { - $options[$scale->id] = format_string($scale->name); + $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); @@ -184,6 +197,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 55035d98b8..1167cadc73 100644 --- a/lang/en_utf8/grades.php +++ b/lang/en_utf8/grades.php @@ -310,6 +310,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'; -- 2.39.5