3 require_once $CFG->libdir
.'/formslib.php';
5 class edit_category_form
extends moodleform
{
6 function definition() {
7 $mform =& $this->_form
;
10 $mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
12 $options = array(GRADE_AGGREGATE_MEAN_ALL
=>get_string('aggregatemeanall', 'grades'),
13 GRADE_AGGREGATE_MEDIAN
=>get_string('aggregatemedian', 'grades'),
14 GRADE_AGGREGATE_MEAN_GRADED
=>get_string('aggregatemeangraded', 'grades'),
15 GRADE_AGGREGATE_MIN
=>get_string('aggregatemin', 'grades'),
16 GRADE_AGGREGATE_MAX
=>get_string('aggregatemax', 'grades'),
17 GRADE_AGGREGATE_MODE
=>get_string('aggregatemode', 'grades'));
18 $mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $options);
19 $mform->setDefault('gradetype', GRADE_AGGREGATE_MEAN_ALL
);
22 $options[0] = get_string('none');
23 for ($i=1; $i<=20; $i++
) {
26 $mform->addElement('select', 'keephigh', get_string('keephigh', 'grades'), $options);
27 $mform->disabledIf('keephigh', 'droplow', 'noteq', 0);
29 $mform->addElement('select', 'droplow', get_string('droplow', 'grades'), $options);
30 $mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
33 $mform->addElement('hidden', 'id', 0);
34 $mform->setType('id', PARAM_INT
);
36 $mform->addElement('hidden', 'courseid', 0);
37 $mform->setType('courseid', PARAM_INT
);
39 //-------------------------------------------------------------------------------
41 $this->add_action_buttons();
45 /// tweak the form - depending on existing data
46 function definition_after_data() {
49 $mform =& $this->_form
;
51 if ($id = $mform->getElementValue('id')) {
52 $grade_category = grade_category
::fetch(array('id'=>$id));
53 $grade_item = $grade_category->load_grade_item();
55 if ($grade_item->is_calculated()) {
56 // following elements are ignored when calculation formula used
57 if ($mform->elementExists('aggregation')) {
58 $mform->removeElement('aggregation');
60 if ($mform->elementExists('keephigh')) {
61 $mform->removeElement('keephigh');
63 if ($mform->elementExists('droplow')) {
64 $mform->removeElement('droplow');