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 //-------------------------------------------------------------------------------
26 $this->add_action_buttons();
29 /// perform extra validation before submission
30 function validation($data){
33 if ($data['calculation'] != '') {
34 $grade_item = grade_item
::fetch(array('id'=>$data['id'], 'courseid'=>$data['courseid']));
35 $result = $grade_item->validate_formula($data['calculation']);
36 if ($result !== true) {
37 $errors['calculation'] = $result;
40 if (0 == count($errors)){