]> git.mjollnir.org Git - moodle.git/commitdiff
grade category edit form improved, fixed aggregation
authorskodak <skodak>
Sun, 8 Jul 2007 21:37:55 +0000 (21:37 +0000)
committerskodak <skodak>
Sun, 8 Jul 2007 21:37:55 +0000 (21:37 +0000)
grade/report/grader/edit_category_form.php
lib/grade/grade_category.php

index 74e03f8e02a863bafb537922c3d6630f606dac7f..6ac37c8360e6d79c7e71d34879a06241ac34b51b 100644 (file)
@@ -9,7 +9,25 @@ class edit_category_form extends moodleform {
         // visible elements
         $mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
 
-        //TODO: add other elements
+        $options = array(GRADE_AGGREGATE_MEAN_ALL   =>get_string('aggregatemeanall', 'grades'),
+                         GRADE_AGGREGATE_MEDIAN     =>get_string('aggregatemedian', 'grades'),
+                         GRADE_AGGREGATE_MEAN_GRADED=>get_string('aggregatemeangraded', 'grades'),
+                         GRADE_AGGREGATE_MIN        =>get_string('aggregatemin', 'grades'),
+                         GRADE_AGGREGATE_MAX        =>get_string('aggregatemax', 'grades'),
+                         GRADE_AGGREGATE_MODE       =>get_string('aggregatemode', 'grades'));
+        $mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $options);
+        $mform->setDefault('gradetype', GRADE_AGGREGATE_MEAN_ALL);
+
+        $options = array();
+        $options[0] = get_string('none');
+        for ($i=1; $i<=20; $i++) {
+            $options[$i] = $i;
+        }
+        $mform->addElement('select', 'keephigh', get_string('keephigh', 'grades'), $options);
+        $mform->disabledIf('keephigh', 'droplow', 'noteq', 0);
+
+        $mform->addElement('select', 'droplow', get_string('droplow', 'grades'), $options);
+        $mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
 
         // hidden params
         $mform->addElement('hidden', 'id', 0);
@@ -22,6 +40,27 @@ class edit_category_form extends moodleform {
         // buttons
         $this->add_action_buttons();
     }
+
+
+/// tweak the form - depending on existing data
+    function definition_after_data() {
+        global $CFG;
+
+        $mform =& $this->_form;
+
+        if ($id = $mform->getElementValue('id')) {
+            $grade_category = grade_category::fetch(array('id'=>$id));
+            $grade_item = $grade_category->load_grade_item();
+
+            if ($grade_item->is_calculated()) {
+                // following elements are ignored when calculation formula used
+                $mform->removeElement('aggregation');
+                $mform->removeElement('keephigh');
+                $mform->removeElement('droplow');
+            }
+        }
+    }
+
 }
 
 ?>
\ No newline at end of file
index 97173fa556e84318d1deb69a50f5844f4f9542d3..2def407a2e45472c659be10d90d48fa8c1749d8d 100644 (file)
@@ -482,6 +482,7 @@ class grade_category extends grade_object {
                 $modes = array_keys($freq, $top);  // search for all modes (have the same highest count)
                 rsort($modes, SORT_NUMERIC);       // get highes mode
                 $rawgrade = reset($modes);
+                break;
 
             case GRADE_AGGREGATE_MEAN_GRADED: // Arithmetic average of all final grades, unfinished are not calculated
             default: