3 require_once $CFG->libdir
.'/formslib.php';
5 class edit_category_form
extends moodleform
{
6 var $aggregation_types = array();
7 var $keepdrop_options = array();
9 function definition() {
11 $mform =& $this->_form
;
13 $this->aggregation_types
= array(GRADE_AGGREGATE_MEAN
=>get_string('aggregatemean', 'grades'),
14 GRADE_AGGREGATE_MEDIAN
=>get_string('aggregatemedian', '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 GRADE_AGGREGATE_WEIGHTED_MEAN
=>get_string('aggregateweightedmean', 'grades'),
19 GRADE_AGGREGATE_EXTRACREDIT_MEAN
=>get_string('aggregateextracreditmean', 'grades'));
22 $mform->addElement('header', 'general', get_string('gradecategory', 'grades'));
23 $mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
25 if ($CFG->grade_aggregation
== -1) {
27 $mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $this->aggregation_types
);
28 $mform->setHelpButton('aggregation', array('aggregation', get_string('aggregation', 'grades'), 'grade'));
29 $mform->setDefault('aggregation', GRADE_AGGREGATE_MEAN
);
31 $mform->addElement('static', 'aggregation', get_string('aggregation', 'grades'));
34 if ($CFG->grade_aggregateonlygraded
== -1) {
35 $mform->addElement('advcheckbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades'));
36 $mform->setHelpButton('aggregateonlygraded', array(false, get_string('aggregateonlygraded', 'grades'),
37 false, true, false, get_string('aggregateonlygradedhelp', 'grades')));
39 $mform->addElement('static', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades'));
42 if (!empty($CFG->enableoutcomes
) && $CFG->grade_aggregateoutcomes
== -1) {
43 $mform->addElement('advcheckbox', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades'));
44 $mform->setHelpButton('aggregateoutcomes', array(false, get_string('aggregateoutcomes', 'grades'),
45 false, true, false, get_string('aggregateoutcomeshelp', 'grades')));
47 $mform->addElement('static', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades'));
50 if ($CFG->grade_aggregatesubcats
== -1) {
51 $mform->addElement('advcheckbox', 'aggregatesubcats', get_string('aggregatesubcats', 'grades'));
52 $mform->setHelpButton('aggregatesubcats', array(false, get_string('aggregatesubcats', 'grades'),
53 false, true, false, get_string('aggregatesubcatshelp', 'grades')));
55 $mform->addElement('static', 'aggregatesubcats', get_string('aggregatesubcats', 'grades'));
58 $this->keepdrop_options
= array();
59 $this->keepdrop_options
[0] = get_string('none');
60 for ($i=1; $i<=20; $i++
) {
61 $this->keepdrop_options
[$i] = $i;
64 $keepdrop_present = 0;
66 if ($CFG->grade_keephigh
== -1) {
67 $mform->addElement('select', 'keephigh', get_string('keephigh', 'grades'), $this->keepdrop_options
);
68 $mform->setHelpButton('keephigh', array(false, get_string('keephigh', 'grades'),
69 false, true, false, get_string('keephighhelp', 'grades')));
72 $mform->addElement('static', 'keephigh', get_string('keephigh', 'grades'));
75 if ($CFG->grade_droplow
== -1) {
76 $mform->addElement('select', 'droplow', get_string('droplow', 'grades'), $options);
77 $mform->setHelpButton('droplow', array(false, get_string('droplow', 'grades'),
78 false, true, false, get_string('droplowhelp', 'grades')));
79 $mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
82 $mform->addElement('static', 'droplow', get_string('droplow', 'grades'));
85 if ($keepdrop_present == 2) {
86 $mform->disabledIf('keephigh', 'droplow', 'noteq', 0);
87 $mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
91 $mform->addElement('header', 'general', get_string('userpreferences', 'grades'));
92 $options = array(GRADE_REPORT_PREFERENCE_DEFAULT
=> get_string('default', 'grades'),
93 GRADE_REPORT_AGGREGATION_VIEW_FULL
=> get_string('fullmode', 'grades'),
94 GRADE_REPORT_AGGREGATION_VIEW_AGGREGATES_ONLY
=> get_string('aggregatesonly', 'grades'),
95 GRADE_REPORT_AGGREGATION_VIEW_GRADES_ONLY
=> get_string('gradesonly', 'grades'));
96 $label = get_string('aggregationview', 'grades') . ' (' . get_string('default', 'grades')
97 . ': ' . $options[$CFG->grade_report_aggregationview
] . ')';
98 $mform->addElement('select', 'pref_aggregationview', $label, $options);
99 $mform->setHelpButton('pref_aggregationview', array(false, get_string('aggregationview', 'grades'),
100 false, true, false, get_string('configaggregationview', 'grades')));
101 $mform->setDefault('pref_aggregationview', GRADE_REPORT_PREFERENCE_DEFAULT
);
104 $mform->addElement('hidden', 'id', 0);
105 $mform->setType('id', PARAM_INT
);
107 $mform->addElement('hidden', 'courseid', 0);
108 $mform->setType('courseid', PARAM_INT
);
110 /// add return tracking info
111 $gpr = $this->_customdata
['gpr'];
112 $gpr->add_mform_elements($mform);
114 //-------------------------------------------------------------------------------
116 $this->add_action_buttons();
120 /// tweak the form - depending on existing data
121 function definition_after_data() {
124 $mform =& $this->_form
;
126 $checkbox_values = array(get_string('no'), get_string('yes'));
128 if ($CFG->grade_aggregation
!= -1) {
129 $agg_el =& $mform->getElement('aggregation');
130 $agg_el->setValue($this->aggregation_types
[$CFG->grade_aggregation
]);
133 if ($CFG->grade_aggregateonlygraded
!= -1) {
134 $agg_el =& $mform->getElement('aggregateonlygraded');
135 $agg_el->setValue($checkbox_values[$CFG->grade_aggregateonlygraded
]);
138 if ($CFG->grade_aggregateoutcomes
!= -1) {
139 $agg_el =& $mform->getElement('aggregateoutcomes');
140 $agg_el->setValue($checkbox_values[$CFG->grade_aggregateoutcomes
]);
143 if ($CFG->grade_aggregatesubcats
!= -1) {
144 $agg_el =& $mform->getElement('aggregatesubcats');
145 $agg_el->setValue($checkbox_values[$CFG->grade_aggregatesubcats
]);
148 if ($CFG->grade_keephigh
!= -1) {
149 $agg_el =& $mform->getElement('keephigh');
150 $agg_el->setValue($this->keepdrop_options
[$CFG->grade_keephigh
]);
153 if ($CFG->grade_droplow
!= -1) {
154 $agg_el =& $mform->getElement('droplow');
155 $agg_el->setValue($this->keepdrop_options
[$CFG->grade_droplow
]);
158 if ($id = $mform->getElementValue('id')) {
159 $grade_category = grade_category
::fetch(array('id'=>$id));
160 $grade_item = $grade_category->load_grade_item();
162 if ($grade_item->is_calculated()) {
163 // following elements are ignored when calculation formula used
164 if ($mform->elementExists('aggregation')) {
165 $mform->removeElement('aggregation');
167 if ($mform->elementExists('keephigh')) {
168 $mform->removeElement('keephigh');
170 if ($mform->elementExists('droplow')) {
171 $mform->removeElement('droplow');
173 if ($mform->elementExists('aggregateonlygraded')) {
174 $mform->removeElement('aggregateonlygraded');
176 if ($mform->elementExists('aggregateoutcomes')) {
177 $mform->removeElement('aggregateoutcomes');
179 if ($mform->elementExists('aggregatesubcats')) {
180 $mform->removeElement('aggregatesubcats');