MDL-11340 Almost complete: Just need the "Add grade letter" button
[moodle-pu.git] / grade / report / grader / preferences_form.php
blob56740ba47e7e4d1819076fd938619f0b6f96fe8d
1 <?php //$Id$
3 require_once($CFG->libdir.'/formslib.php');
5 /**
6 * First implementation of the preferences in the form of a moodleform.
7 * TODO add "reset to site defaults" button
8 */
9 class grader_report_preferences_form extends moodleform {
11 function definition() {
12 global $USER, $CFG;
14 $mform =& $this->_form;
15 $course = $this->_customdata['course'];
17 $context = get_context_instance(CONTEXT_COURSE, $course->id);
18 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
20 $strgradeboundary = get_string('gradeboundary', 'grades');
21 $strconfiggradeboundary = get_string('configgradeboundary', 'grades');
22 $strgradeletter = get_string('gradeletter', 'grades');
23 $strconfiggradeletter = get_string('configgradeletter', 'grades');
24 $strinherit = get_string('inherit', 'grades');
25 $stryes = get_string('yes');
26 $strno = get_string('no');
29 $checkbox_default = array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default', 0 => $strno, 1 => $stryes);
31 /// form definition with preferences defaults
32 //--------------------------------------------------------------------------------
33 $preferences = array();
35 // Initialise the preferences arrays with grade:manage capabilities
36 if (has_capability('moodle/grade:manage', $context)) {
37 $preferences['prefgeneral'] = array(
38 'decimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default', 0, 1, 2, 3, 4, 5),
39 'aggregationview' => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default',
40 GRADE_REPORT_AGGREGATION_VIEW_FULL => get_string('fullmode', 'grades'),
41 GRADE_REPORT_AGGREGATION_VIEW_AGGREGATES_ONLY => get_string('aggregatesonly', 'grades'),
42 GRADE_REPORT_AGGREGATION_VIEW_GRADES_ONLY => get_string('gradesonly', 'grades')),
43 'meanselection' => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default',
44 GRADE_REPORT_MEAN_ALL => get_string('meanall', 'grades'),
45 GRADE_REPORT_MEAN_GRADED => get_string('meangraded', 'grades')));
48 $preferences['prefshow'] = array('showcalculations' => $checkbox_default,
49 'showeyecons' => $checkbox_default,
50 'showaverages' => $checkbox_default,
51 'showgroups' => $checkbox_default,
52 'showlocks' => $checkbox_default);
54 $preferences['prefrows'] = array(
55 'averagesdisplaytype' => array(GRADE_REPORT_GRADE_DISPLAY_TYPE_DEFAULT => 'default',
56 GRADE_REPORT_GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
57 GRADE_REPORT_GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
58 GRADE_REPORT_GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades')),
59 'rangesdisplaytype' => array(GRADE_REPORT_GRADE_DISPLAY_TYPE_DEFAULT => 'default',
60 GRADE_REPORT_GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
61 GRADE_REPORT_GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
62 GRADE_REPORT_GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades')),
63 'averagesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default',
64 GRADE_REPORT_PREFERENCE_INHERIT => $strinherit, 0, 1, 2, 3, 4, 5),
65 'rangesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default',
66 GRADE_REPORT_PREFERENCE_INHERIT => $strinherit, 0, 1, 2, 3, 4, 5));
70 // quickgrading and quickfeedback are conditional on grade:edit capability
71 if (has_capability('moodle/grade:edit', $context)) {
72 $preferences['prefgeneral']['quickgrading'] = $checkbox_default;
73 $preferences['prefgeneral']['quickfeedback'] = $checkbox_default;
76 // View capability is the lowest permission. Users with grade:manage or grade:edit must also have grader:view
77 if (has_capability('gradereport/grader:view', $context)) {
78 $preferences['prefgeneral']['studentsperpage'] = 'text';
79 $preferences['prefgeneral']['aggregationposition'] = array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default',
80 GRADE_REPORT_AGGREGATION_POSITION_LEFT => get_string('left', 'grades'),
81 GRADE_REPORT_AGGREGATION_POSITION_RIGHT => get_string('right', 'grades'));
82 $preferences['prefgeneral']['enableajax'] = $checkbox_default;
84 $preferences['prefshow']['showuserimage'] = $checkbox_default;
85 $preferences['prefshow']['showactivityicons'] = $checkbox_default;
86 $preferences['prefshow']['showranges'] = $checkbox_default;
88 $preferences['prefrows']['shownumberofgrades'] = $checkbox_default;
92 foreach ($preferences as $group => $prefs) {
93 $mform->addElement('header', $group, get_string($group, 'grades'));
95 foreach ($prefs as $pref => $type) {
96 // Detect and process dynamically numbered preferences
97 if (preg_match('/([^[0-9]+)([0-9]+)/', $pref, $matches)) {
98 $lang_string = $matches[1];
99 $number = ' ' . $matches[2];
100 } else {
101 $lang_string = $pref;
102 $number = null;
105 $full_pref = 'grade_report_' . $pref;
107 $pref_value = get_user_preferences($full_pref);
109 $options = null;
110 if (is_array($type)) {
111 $options = $type;
112 $type = 'select';
113 $default = $options[$CFG->$full_pref];
114 } else {
115 $default = $CFG->$full_pref;
118 $help_string = get_string("config$lang_string", 'grades');
120 // Replace the 'default' value with the site default language string
121 if (!is_null($options) AND $options[GRADE_REPORT_PREFERENCE_DEFAULT] == 'default') {
122 $options[GRADE_REPORT_PREFERENCE_DEFAULT] = get_string('sitedefault', 'grades', $default);
123 } elseif ($type == 'text') {
124 $help_string = get_string("config{$lang_string}default", 'grades', $default);
127 $label = get_string($lang_string, 'grades') . $number;
129 $mform->addElement($type, $full_pref, $label, $options);
130 $mform->setHelpButton($full_pref, array(false, get_string($lang_string, 'grades'), false, true, false, $help_string));
131 $mform->setDefault($full_pref, $pref_value);
132 $mform->setType($full_pref, PARAM_ALPHANUM);
136 $mform->addElement('hidden', 'id');
137 $mform->setType('id', PARAM_INT);
138 $mform->setDefault('id', $course->id);
140 $this->add_action_buttons();
144 /// perform some extra moodle validation
145 function validation($data){
146 $errors= array();
147 if (0 == count($errors)){
148 return true;
149 } else {
150 return $errors;