renaming constant
[moodle-pu.git] / grade / edit / edit_calculation_form.php
blobdac6f10eaeb69a0edd5cc036838721bd18eb2159
1 <?php //$Id$
3 require_once $CFG->libdir.'/formslib.php';
5 class edit_calculation_form extends moodleform {
6 function definition() {
7 global $COURSE;
9 $mform =& $this->_form;
11 /// visible elements
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'));
17 /// hidden params
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 //-------------------------------------------------------------------------------
25 // buttons
26 $this->add_action_buttons();
29 /// perform extra validation before submission
30 function validation($data){
31 $errors= array();
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)){
41 return true;
42 } else {
43 return $errors;