diff --git a/grade/report/grader/edit_category_form.php b/grade/report/grader/edit_category_form.php index 74e03f8e02a..6ac37c8360e 100644 --- a/grade/report/grader/edit_category_form.php +++ b/grade/report/grader/edit_category_form.php @@ -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 diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 97173fa556e..2def407a2e4 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -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: