3 require_once $CFG->libdir
.'/formslib.php';
5 class edit_calculation_form
extends moodleform
{
6 function definition() {
9 $mform =& $this->_form
;
12 $mform->addElement('header', 'general', get_string('gradeitem', 'grades'));
14 $mform->addElement('static', 'itemname', get_string('itemname', 'grades'));
15 $mform->addElement('text', 'calculation', get_string('calculation', 'grades'));
18 $mform->addElement('hidden', 'id', 0);
19 $mform->setType('id', PARAM_INT
);
21 $mform->addElement('hidden', 'courseid', 0);
22 $mform->setType('courseid', PARAM_INT
);
24 /// add return tracking info
25 $gpr = $this->_customdata
['gpr'];
26 $gpr->add_mform_elements($mform);
28 //-------------------------------------------------------------------------------
30 $this->add_action_buttons();
33 /// perform extra validation before submission
34 function validation($data){
37 if ($data['calculation'] != '') {
38 $grade_item = grade_item
::fetch(array('id'=>$data['id'], 'courseid'=>$data['courseid']));
39 $result = $grade_item->validate_formula($data['calculation']);
40 if ($result !== true) {
41 $errors['calculation'] = $result;
44 if (0 == count($errors)){