$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) {
$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);
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'),
//$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);
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();
+//-------------------------------------------------------------------------------
+ $this->set_data($category);
}
$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))) {
$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;
$mform =& $this->_form;
+ $item = $this->_customdata['current'];
+
/// visible elements
$mform->addElement('header', 'general', get_string('gradeitem', 'grades'));
//$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);
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();
+//-------------------------------------------------------------------------------
+ $this->set_data($item);
}
$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';