grade category edit form improved, fixed aggregation

This commit is contained in:
skodak 2007-07-08 21:37:55 +00:00
parent 854386bc04
commit d5fab31f08
2 changed files with 41 additions and 1 deletions

View 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');
}
}
}
}
?>

View 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: