MDL-10544 placeholder for outcome edit forms grade/edit/outcome/
[moodle-pu.git] / grade / edit / tree / calculation_form.php
blobae0e7fbe8b69ab39299ae15bd9d2f54351e86b1a
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 /// add return tracking info
25 $gpr = $this->_customdata['gpr'];
26 $gpr->add_mform_elements($mform);
28 //-------------------------------------------------------------------------------
29 // buttons
30 $this->add_action_buttons();
33 /// perform extra validation before submission
34 function validation($data){
35 $errors= array();
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)){
45 return true;
46 } else {
47 return $errors;