3 require_once $CFG->libdir
.'/formslib.php';
5 class edit_outcomeitem_form
extends moodleform
{
6 function definition() {
9 $mform =& $this->_form
;
12 $mform->addElement('header', 'general', get_string('gradeoutcomeitem', 'grades'));
14 $mform->addElement('text', 'itemname', get_string('itemname', 'grades'));
15 $mform->addRule('itemname', get_string('required'), 'required', null, 'client');
17 $mform->addElement('text', 'iteminfo', get_string('iteminfo', 'grades'));
18 $mform->setHelpButton('iteminfo', array(false, get_string('iteminfo', 'grades'),
19 false, true, false, get_string('iteminfohelp', 'grades')));
21 $mform->addElement('text', 'idnumber', get_string('idnumber'));
22 $mform->setHelpButton('idnumber', array(false, get_string('idnumber'),
23 false, true, false, get_string('idnumberhelp', 'grades')));
25 // allow setting of outcomes on module items too
27 if ($outcomes = grade_outcome
::fetch_all_available($COURSE->id
)) {
28 foreach ($outcomes as $outcome) {
29 $options[$outcome->id
] = $outcome->get_name();
32 $mform->addElement('select', 'outcomeid', get_string('outcome', 'grades'), $options);
33 $mform->setHelpButton('outcomeid', array(false, get_string('outcomeid', 'grades'),
34 false, true, false, get_string('outcomeidhelp', 'grades')));
35 $mform->addRule('outcomeid', get_string('required'), 'required');
37 $options = array(0=>get_string('none'));
38 if ($coursemods = get_course_mods($COURSE->id
)) {
39 foreach ($coursemods as $coursemod) {
40 $mod = get_coursemodule_from_id($coursemod->modname
, $coursemod->id
);
41 $options[$coursemod->id
] = format_string($mod->name
);
44 $mform->addElement('select', 'cmid', get_string('linkedactivity', 'grades'), $options);
45 $mform->setHelpButton('cmid', array(false, get_string('linkedactivity', 'grades'),
46 false, true, false, get_string('linkedactivityhelp', 'grades')));
47 $mform->setDefault('cmid', 0);
49 //$mform->addElement('text', 'calculation', get_string('calculation', 'grades'));
51 $mform->addElement('text', 'aggregationcoef', get_string('aggregationcoef', 'grades'));
52 $mform->setDefault('aggregationcoef', 0.0);
55 /// advcheckbox is not compatible with disabledIf !!
56 $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades'));
57 $mform->setHelpButton('hidden', array('hidden', get_string('hidden', 'grades'), 'grade'));
58 $mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional'=>true));
59 $mform->setHelpButton('hiddenuntil', array('hiddenuntil', get_string('hiddenuntil', 'grades'), 'grade'));
60 $mform->disabledIf('hiddenuntil', 'hidden', 'checked');
63 $mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades'));
64 $mform->setHelpButton('locked', array('locked', get_string('locked', 'grades'), 'grade'));
65 $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional'=>true));
66 $mform->setHelpButton('locktime', array('locktime', get_string('locktime', 'grades'), 'grade'));
69 $mform->addElement('hidden', 'id', 0);
70 $mform->setType('id', PARAM_INT
);
72 $mform->addElement('hidden', 'courseid', $COURSE->id
);
73 $mform->setType('courseid', PARAM_INT
);
75 /// add return tracking info
76 $gpr = $this->_customdata
['gpr'];
77 $gpr->add_mform_elements($mform);
79 //-------------------------------------------------------------------------------
81 $this->add_action_buttons();
85 /// tweak the form - depending on existing data
86 function definition_after_data() {
89 $mform =& $this->_form
;
91 if ($id = $mform->getElementValue('id')) {
92 $grade_item = grade_item
::fetch(array('id'=>$id));
94 //remove the aggregation coef element if not needed
95 if ($grade_item->is_course_item()) {
96 $mform->removeElement('aggregationcoef');
98 } else if ($grade_item->is_category_item()) {
99 $category = $grade_item->get_item_category();
100 $parent_category = $category->get_parent_category();
101 if (!$parent_category->is_aggregationcoef_used()) {
102 $mform->removeElement('aggregationcoef');
106 $parent_category = $grade_item->get_parent_category();
107 if (!$parent_category->is_aggregationcoef_used()) {
108 $mform->removeElement('aggregationcoef');
113 $course_category = grade_category
::fetch_course_category($COURSE->id
);
114 if (!$course_category->is_aggregationcoef_used()) {
115 $mform->removeElement('aggregationcoef');
121 /// perform extra validation before submission
122 function validation($data){
125 if (array_key_exists('idnumber', $data)) {
127 $grade_item = new grade_item(array('id'=>$data['id'], 'courseid'=>$data['courseid']));
131 if (!grade_verify_idnumber($data['idnumber'], $grade_item, null)) {
132 $errors['idnumber'] = get_string('idnumbertaken');
136 if (0 == count($errors)){