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'));
19 $mform->addElement('text', 'idnumber', get_string('idnumber'));
21 // allow setting of outcomes on module items too
23 if ($outcomes = grade_outcome
::fetch_all(array('courseid'=>$COURSE->id
), true)) {
24 foreach ($outcomes as $outcome) {
25 $options[$outcome->id
] = $outcome->get_name();
28 $mform->addElement('select', 'outcomeid', get_string('outcome', 'grades'), $options);
30 $options = array(0=>get_string('none'));
31 if ($coursemods = get_course_mods($COURSE->id
)) {
32 foreach ($coursemods as $coursemod) {
33 $mod = get_coursemodule_from_id($coursemod->modname
, $coursemod->id
);
34 $options[$coursemod->id
] = format_string($mod->name
);
37 $mform->addElement('select', 'cmid', get_string('linkedactivity', 'grades'), $options);
38 $mform->setDefault('cmid', 0);
41 // $mform->addElement('text', 'calculation', get_string('calculation', 'grades'));
43 $mform->addElement('text', 'aggregationcoef', get_string('aggregationcoef', 'grades'));
44 $mform->setDefault('aggregationcoef', 0.0);
46 $mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades'));
48 $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional'=>true));
51 $mform->addElement('hidden', 'id', 0);
52 $mform->setType('id', PARAM_INT
);
54 $mform->addElement('hidden', 'courseid', $COURSE->id
);
55 $mform->setType('courseid', PARAM_INT
);
57 /// add return tracking info
58 $gpr = $this->_customdata
['gpr'];
59 $gpr->add_mform_elements($mform);
61 //-------------------------------------------------------------------------------
63 $this->add_action_buttons();
67 /// tweak the form - depending on existing data
68 function definition_after_data() {
71 $mform =& $this->_form
;
73 if ($id = $mform->getElementValue('id')) {
74 $grade_item = grade_item
::fetch(array('id'=>$id));
76 //remove the aggregation coef element if not needed
77 if ($grade_item->is_course_item()) {
78 $mform->removeElement('aggregationcoef');
80 } else if ($grade_item->is_category_item()) {
81 $category = $grade_item->get_item_category();
82 $parent_category = $category->get_parent_category();
83 if (!$parent_category->is_aggregationcoef_used()) {
84 $mform->removeElement('aggregationcoef');
88 $parent_category = $grade_item->get_parent_category();
89 if (!$parent_category->is_aggregationcoef_used()) {
90 $mform->removeElement('aggregationcoef');
95 $course_category = grade_category
::fetch_course_category($COURSE->id
);
96 if (!$course_category->is_aggregationcoef_used()) {
97 $mform->removeElement('aggregationcoef');
103 /// perform extra validation before submission
104 function validation($data){
107 if (0 == count($errors)){