]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10481 minor form cleanup - added prefix for preferences in element names, added...
authorskodak <skodak>
Tue, 17 Jul 2007 15:22:18 +0000 (15:22 +0000)
committerskodak <skodak>
Tue, 17 Jul 2007 15:22:18 +0000 (15:22 +0000)
grade/edit/item.php
grade/edit/item_form.php

index e5948fe94c92a7cfa595fc48eab402252f6dfe1b..013af496becb89b7388c617fb54a38c5a3263b20 100644 (file)
@@ -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');
index edc093d10314ad9df4b757d834f3baaf2c4a843c..241c637ce6da9ab1639d33f6b27ad94bd407cde9 100644 (file)
@@ -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) {