From: skodak Date: Tue, 17 Jul 2007 15:22:18 +0000 (+0000) Subject: MDL-10481 minor form cleanup - added prefix for preferences in element names, added... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=83ae2001b9c448831f1addaab89db17a7e5e8b92;p=moodle.git MDL-10481 minor form cleanup - added prefix for preferences in element names, added header + temporary debug delay before redirect --- diff --git a/grade/edit/item.php b/grade/edit/item.php index e5948fe94c..013af496be 100644 --- a/grade/edit/item.php +++ b/grade/edit/item.php @@ -25,14 +25,16 @@ $mform = new edit_item_form(null, array('gpr'=>$gpr)); if ($mform->is_cancelled()) { redirect($returnurl); + } else if (!$mform->is_submitted()) { if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) { // Get Item preferences - $item->gradedisplaytype = get_user_preferences('grade_report_gradedisplaytype' . $id, 'default'); - $item->decimalpoints = get_user_preferences('grade_report_decimalpoints' . $id, 'default'); + $item->pref_gradedisplaytype = get_user_preferences('grade_report_gradedisplaytype' . $id, 'default'); + $item->pref_decimalpoints = get_user_preferences('grade_report_decimalpoints' . $id, 'default'); $item->calculation = grade_item::denormalize_formula($item->calculation, $course->id); $mform->set_data($item); + } else { $mform->set_data(array('courseid'=>$course->id, 'itemtype'=>'manual')); } @@ -56,25 +58,19 @@ if ($mform->is_cancelled()) { } // Handle user preferences - if (!empty($data->gradedisplaytype)) { - if (!grade_report::set_pref('gradedisplaytype', $data->gradedisplaytype, $id)) { - $errors[] = "Could not set preference gradedisplaytype to $value for this grade item"; + if (!empty($data->pref_gradedisplaytype)) { + if (!grade_report::set_pref('gradedisplaytype', $data->pref_gradedisplaytype, $grade_item->id)) { + error("Could not set preference gradedisplaytype to $value for this grade item"); } } - if (!empty($data->decimalpoints)) { - if (!grade_report::set_pref('decimalpoints', $data->decimalpoints, $id)) { - $errors[] = "Could not set preference decimalpoints to $value for this grade item"; + if (!empty($data->pref_decimalpoints)) { + if (!grade_report::set_pref('decimalpoints', $data->pref_decimalpoints, $grade_item->id)) { + errors("Could not set preference decimalpoints to $value for this grade item"); } } - if (empty($errors)) { - // redirect($returnurl); - } else { - foreach ($errors as $error) { - error($error); - } - } + redirect($returnurl, 'temporary debug delay', 10); } $strgrades = get_string('grades'); diff --git a/grade/edit/item_form.php b/grade/edit/item_form.php index edc093d103..241c637ce6 100644 --- a/grade/edit/item_form.php +++ b/grade/edit/item_form.php @@ -72,19 +72,22 @@ class edit_item_form extends moodleform { $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional'=>true)); $mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE); - $mform->addElement('select', 'gradedisplaytype', get_string('gradedisplaytype', 'grades'), +/// user preferences + $mform->addElement('header', 'general', get_string('userpreferences', 'grades')); + + $mform->addElement('select', 'pref_gradedisplaytype', get_string('gradedisplaytype', 'grades'), array('default' => get_string('default', 'grades'), GRADE_REPORT_GRADE_DISPLAY_TYPE_RAW => get_string('raw', 'grades'), GRADE_REPORT_GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'))); - $mform->setHelpButton('gradedisplaytype', array(false, get_string('gradedisplaytype', 'grades'), + $mform->setHelpButton('pref_gradedisplaytype', array(false, get_string('gradedisplaytype', 'grades'), false, true, false, get_string("config_gradedisplaytype", 'grades'))); - $mform->setDefault('gradedisplaytype', 'default'); + $mform->setDefault('pref_gradedisplaytype', 'default'); - $mform->addElement('select', 'decimalpoints', get_string('decimalpoints', 'grades'), + $mform->addElement('select', 'pref_decimalpoints', get_string('decimalpoints', 'grades'), array('default' => get_string('default', 'grades'), 0, 1, 2, 3, 4, 5)); - $mform->setHelpButton('decimalpoints', array(false, get_string('decimalpoints', 'grades'), + $mform->setHelpButton('pref_decimalpoints', array(false, get_string('decimalpoints', 'grades'), false, true, false, get_string("config_decimalpoints", 'grades'))); - $mform->setDefault('decimalpoints', 'default'); + $mform->setDefault('pref_decimalpoints', 'default'); /// hidden params $mform->addElement('hidden', 'id', 0); @@ -130,7 +133,7 @@ class edit_item_form extends moodleform { function validation($data){ $errors= array(); - if ($data['calculation'] != '') { + if (array_key_exists('calculation', $data) and $data['calculation'] != '') { $grade_item = new grade_item(array('id'=>$data['id'], 'itemtype'=>$data['itemtype'], 'courseid'=>$data['courseid'])); $result = $grade_item->validate_formula($data['calculation']); if ($result !== true) {