]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19091 removed custom scales from different courses + added BC hack; backported...
authorskodak <skodak>
Thu, 7 May 2009 08:39:29 +0000 (08:39 +0000)
committerskodak <skodak>
Thu, 7 May 2009 08:39:29 +0000 (08:39 +0000)
grade/edit/tree/category.php
grade/edit/tree/category_form.php
grade/edit/tree/item.php
grade/edit/tree/item_form.php
lang/en_utf8/grades.php

index a6fd5c673bfb734969092dbea45a5814b1c1f641..4a3aabc6b388c67657317c2c96e4bf0cd15742e0 100644 (file)
@@ -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);
index 8e5038a4b93e6563b7528c55dc9bb909e078f6cc..5ceb1033a16386959992f9dd48e575c6aa051023 100644 (file)
@@ -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);
     }
 
 
index cca77c9ebbb920f5c891987f1346c31fc952c6a3..ac30d0ca351c9ed9c3b1af445b8cd63245d6ed84 100644 (file)
@@ -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;
index 4dd0cd20264b9512e8a0346d20f153c7774bdb62..1bcc6a80710e713f59fc3439f7ce8b46c7a2c45c 100644 (file)
@@ -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);
     }
 
 
index 55035d98b8f47dd26dfd259190eb068030941423..1167cadc73cfc795b947f802a5a9928f6cd6a027 100644 (file)
@@ -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';