MDL-10075 - changes done following Petr's patch and optional_param with default ltr
[moodle-pu.git] / grade / edit / category_form.php
blob0b0890ca0fd062c61cc2f2a649229687eecf0cc9
1 <?php //$Id$
3 require_once $CFG->libdir.'/formslib.php';
5 class edit_category_form extends moodleform {
6 function definition() {
7 global $CFG;
8 $mform =& $this->_form;
10 // visible elements
11 $mform->addElement('header', 'general', get_string('gradecategory', 'grades'));
12 $mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
14 $options = array(GRADE_AGGREGATE_MEAN_ALL =>get_string('aggregatemeanall', 'grades'),
15 GRADE_AGGREGATE_MEAN_GRADED =>get_string('aggregatemeangraded', 'grades'),
16 GRADE_AGGREGATE_MEDIAN_ALL =>get_string('aggregatemedianall', 'grades'),
17 GRADE_AGGREGATE_MEDIAN_GRADED =>get_string('aggregatemediangraded', 'grades'),
18 GRADE_AGGREGATE_MIN_ALL =>get_string('aggregateminall', 'grades'),
19 GRADE_AGGREGATE_MIN_GRADED =>get_string('aggregatemingraded', 'grades'),
20 GRADE_AGGREGATE_MAX_ALL =>get_string('aggregatemaxall', 'grades'),
21 GRADE_AGGREGATE_MAX_GRADED =>get_string('aggregatemaxgraded', 'grades'),
22 GRADE_AGGREGATE_MODE_ALL =>get_string('aggregatemodeall', 'grades'),
23 GRADE_AGGREGATE_MODE_GRADED =>get_string('aggregatemodegraded', 'grades'),
24 GRADE_AGGREGATE_WEIGHTED_MEAN_ALL =>get_string('aggregateweightedmeanall', 'grades'),
25 GRADE_AGGREGATE_WEIGHTED_MEAN_GRADED =>get_string('aggregateweightedmeangraded', 'grades'),
26 GRADE_AGGREGATE_EXTRACREDIT_MEAN_ALL =>get_string('aggregateextracreditmeanall', 'grades'),
27 GRADE_AGGREGATE_EXTRACREDIT_MEAN_GRADED=>get_string('aggregateextracreditmeangraded', 'grades'));
29 $mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $options);
30 $mform->setDefault('gradetype', GRADE_AGGREGATE_MEAN_ALL);
32 $options = array();
33 $options[0] = get_string('none');
34 for ($i=1; $i<=20; $i++) {
35 $options[$i] = $i;
37 $mform->addElement('select', 'keephigh', get_string('keephigh', 'grades'), $options);
38 $mform->disabledIf('keephigh', 'droplow', 'noteq', 0);
40 $mform->addElement('select', 'droplow', get_string('droplow', 'grades'), $options);
41 $mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
43 // user preferences
44 $mform->addElement('header', 'general', get_string('userpreferences', 'grades'));
45 $options = array(GRADE_REPORT_PREFERENCE_DEFAULT => get_string('default', 'grades'),
46 GRADE_REPORT_AGGREGATION_VIEW_FULL => get_string('full', 'grades'),
47 GRADE_REPORT_AGGREGATION_VIEW_COMPACT => get_string('compact', 'grades'));
48 $label = get_string('aggregationview', 'grades') . ' (' . get_string('default', 'grades')
49 . ': ' . $options[$CFG->grade_report_aggregationview] . ')';
50 $mform->addElement('select', 'pref_aggregationview', $label, $options);
51 $mform->setHelpButton('pref_aggregationview', array(false, get_string('aggregationview', 'grades'),
52 false, true, false, get_string("configaggregationview", 'grades')));
53 $mform->setDefault('pref_aggregationview', GRADE_REPORT_PREFERENCE_DEFAULT);
55 // hidden params
56 $mform->addElement('hidden', 'id', 0);
57 $mform->setType('id', PARAM_INT);
59 $mform->addElement('hidden', 'courseid', 0);
60 $mform->setType('courseid', PARAM_INT);
62 /// add return tracking info
63 $gpr = $this->_customdata['gpr'];
64 $gpr->add_mform_elements($mform);
66 //-------------------------------------------------------------------------------
67 // buttons
68 $this->add_action_buttons();
72 /// tweak the form - depending on existing data
73 function definition_after_data() {
74 global $CFG;
76 $mform =& $this->_form;
78 if ($id = $mform->getElementValue('id')) {
79 $grade_category = grade_category::fetch(array('id'=>$id));
80 $grade_item = $grade_category->load_grade_item();
82 if ($grade_item->is_calculated()) {
83 // following elements are ignored when calculation formula used
84 if ($mform->elementExists('aggregation')) {
85 $mform->removeElement('aggregation');
87 if ($mform->elementExists('keephigh')) {
88 $mform->removeElement('keephigh');
90 if ($mform->elementExists('droplow')) {
91 $mform->removeElement('droplow');