MDL-10724 Finished help strings for grade and outcome item edit forms
[moodle-pu.git] / grade / edit / tree / grade_form.php
blob40c679517c18857b067050e1792b912517486e7f
1 <?php //$Id$
3 require_once $CFG->libdir.'/formslib.php';
5 class edit_grade_form extends moodleform {
7 function definition() {
8 global $CFG, $COURSE;
10 $mform =& $this->_form;
12 $grade_item = $this->_customdata['grade_item'];
13 $gpr = $this->_customdata['gpr'];
15 /// information fields
16 $mform->addElement('static', 'user', get_string('user'));
17 $mform->addElement('static', 'itemname', get_string('itemname', 'grades'));
19 /// actual grade - numeric or scale
20 if ($grade_item->gradetype == GRADE_TYPE_VALUE) {
21 // numeric grade
22 $mform->addElement('text', 'finalgrade', get_string('finalgrade', 'grades'));
23 $mform->setHelpButton('finalgrade', array(false, get_string('finalgrade', 'grades'),
24 false, true, false, get_string('finalgradehelp', 'grades')));
26 } else if ($grade_item->gradetype == GRADE_TYPE_SCALE) {
27 // scale grade
28 $scaleopt = array();
30 if (empty($grade_item->outcomeid)) {
31 $scaleopt[-1] = get_string('nograde');
32 } else {
33 $scaleopt[-1] = get_string('nooutcome', 'grades');
36 $i = 1;
37 if ($scale = get_record('scale', 'id', $grade_item->scaleid)) {
38 foreach (split(",", $scale->scale) as $option) {
39 $scaleopt[$i] = $option;
40 $i++;
44 $mform->addElement('select', 'finalgrade', get_string('finalgrade', 'grades'), $scaleopt);
45 $mform->setHelpButton('finalgrade', array(false, get_string('finalgrade', 'grades'),
46 false, true, false, get_string('finalgradehelp', 'grades')));
49 $mform->addElement('advcheckbox', 'overridden', get_string('overridden', 'grades'));
50 $mform->setHelpButton('overridden', array(false, get_string('overridden', 'grades'),
51 false, true, false, get_string('overriddenhelp', 'grades')));
52 $mform->addElement('advcheckbox', 'excluded', get_string('excluded', 'grades'));
53 $mform->setHelpButton('excluded', array(false, get_string('excluded', 'grades'),
54 false, true, false, get_string('excludedhelp', 'grades')));
56 /// hiding
57 /// advcheckbox is not compatible with disabledIf !!
58 $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades'));
59 $mform->setHelpButton('hidden', array('hidden', get_string('hidden', 'grades'), 'grade'));
60 $mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional'=>true));
61 $mform->setHelpButton('hiddenuntil', array('hiddenuntil', get_string('hiddenuntil', 'grades'), 'grade'));
62 $mform->disabledIf('hiddenuntil', 'hidden', 'checked');
64 /// locking
65 $mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades'));
66 $mform->setHelpButton('locked', array('locked', get_string('locked', 'grades'), 'grade'));
67 $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional'=>true));
68 $mform->setHelpButton('locktime', array('locktime', get_string('locktime', 'grades'), 'grade'));
69 $mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE);
71 // Feedback format is automatically converted to html if user has enabled editor
72 $mform->addElement('htmleditor', 'feedback', get_string('feedback', 'grades'),
73 array('rows'=>'15', 'course'=>$COURSE->id, 'cols'=>'45'));
74 $mform->setHelpButton('feedback', array(false, get_string('feedback', 'grades'),
75 false, true, false, get_string('feedbackhelp', 'grades')));
76 $mform->setType('text', PARAM_RAW); // to be cleaned before display, no XSS risk
77 $mform->addElement('format', 'feedbackformat', get_string('format'));
78 $mform->setHelpButton('feedbackformat', array('textformat', get_string('helpformatting')));
80 // hidden params
81 $mform->addElement('hidden', 'id', 0);
82 $mform->setType('id', PARAM_INT);
84 $mform->addElement('hidden', 'itemid', 0);
85 $mform->setType('itemid', PARAM_INT);
87 $mform->addElement('hidden', 'userid', 0);
88 $mform->setType('userid', PARAM_INT);
90 $mform->addElement('hidden', 'courseid', $COURSE->id);
91 $mform->setType('courseid', PARAM_INT);
93 /// add return tracking info
94 $gpr->add_mform_elements($mform);
96 //-------------------------------------------------------------------------------
97 // buttons
98 $this->add_action_buttons();
101 function definition_after_data() {
102 global $CFG, $COURSE;
104 $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
106 $mform =& $this->_form;
107 $grade_item = $this->_customdata['grade_item'];
109 // fill in user name if user still exists
110 $userid = $mform->getElementValue('userid');
111 if ($user = get_record('user', 'id', $userid)) {
112 $username = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$userid.'">'.fullname($user).'</a>';
113 $user_el =& $mform->getElement('user');
114 $user_el->setValue($username);
117 // add activity name + link
118 if ($grade_item->itemtype == 'mod') {
119 $cm = get_coursemodule_from_instance($grade_item->itemmodule, $grade_item->iteminstance, $grade_item->courseid);
120 $itemname = '<a href="'.$CFG->wwwroot.'/mod/'.$grade_item->itemmodule.'/view.php?id='.$cm->id.'">'.$grade_item->get_name().'</a>';
121 } else {
122 $itemname = $grade_item->get_name();
124 $itemname_el =& $mform->getElement('itemname');
125 $itemname_el->setValue($itemname);
127 // access control - disable not allowed elements
128 if (!has_capability('moodle/grade:manage', $context)) {
129 $mform->hardFreeze('excluded');
132 if (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:hide', $context)) {
133 $mform->hardFreeze('hidden');
134 $mform->hardFreeze('hiddenuntil');
137 $old_grade_grade = new grade_grade(array('itemid'=>$grade_item->id, 'userid'=>$userid));
138 if (empty($old_grade_grade->id)) {
139 $old_grade_grade->locked = $grade_item->locked;
140 $old_grade_grade->locktime = $grade_item->locktime;
143 if (($old_grade_grade->locked or $old_grade_grade->locktime)
144 and (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:unlock', $context))) {
145 $mform->hardFreeze('locked');
146 $mform->hardFreeze('locktime');
148 } else if ((!$old_grade_grade->locked and !$old_grade_grade->locktime)
149 and (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:lock', $context))) {
150 $mform->hardFreeze('locked');
151 $mform->hardFreeze('locktime');