MDL-9628 Simplified and improved the expanding/collapsing of categories. There are...
[moodle-pu.git] / grade / report / grader / preferences_form.php
blobb352f10ecdbb9aaa5481cf098e85c51b2e7fbd1d
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 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
19 $strgradeboundary = get_string('gradeboundary', 'grades');
20 $strconfiggradeboundary = get_string('configgradeboundary', 'grades');
21 $strgradeletter = get_string('gradeletter', 'grades');
22 $strconfiggradeletter = get_string('configgradeletter', 'grades');
23 $strinherit = get_string('inherit', 'grades');
24 $stryes = get_string('yes');
25 $strno = get_string('no');
27 $percentages = array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default',
28 GRADE_REPORT_PREFERENCE_UNUSED => get_string('unused', 'grades'));
29 for ($i=100; $i > -1; $i--) {
30 $percentages[$i] = "$i%";
33 $checkbox_default = array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default', 0 => $strno, 1 => $stryes);
35 /// form definition with preferences defaults
36 //--------------------------------------------------------------------------------
37 $preferences = array();
38 $preferences['prefgeneral'] = array(
39 'studentsperpage' => 'text',
40 'quickgrading' => $checkbox_default,
41 'quickfeedback' => $checkbox_default,
42 'decimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default', 0, 1, 2, 3, 4, 5),
43 'aggregationposition' => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default',
44 GRADE_REPORT_AGGREGATION_POSITION_LEFT => get_string('left', 'grades'),
45 GRADE_REPORT_AGGREGATION_POSITION_RIGHT => get_string('right', 'grades')),
46 'aggregationview' => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default',
47 GRADE_REPORT_AGGREGATION_VIEW_FULL => get_string('fullmode', 'grades'),
48 GRADE_REPORT_AGGREGATION_VIEW_AGGREGATES_ONLY => get_string('aggregatesonly', 'grades'),
49 GRADE_REPORT_AGGREGATION_VIEW_GRADES_ONLY => get_string('gradesonly', 'grades')),
50 'gradedisplaytype' => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default',
51 GRADE_REPORT_GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
52 GRADE_REPORT_GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
53 GRADE_REPORT_GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades')),
54 'meanselection' => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default',
55 GRADE_AGGREGATE_MEAN_ALL => get_string('meanall', 'grades'),
56 GRADE_AGGREGATE_MEAN_GRADED => get_string('meangraded', 'grades')),
57 'enableajax' => $checkbox_default);
59 $preferences['prefshow'] = array('showcalculations' => $checkbox_default,
60 'showeyecons' => $checkbox_default,
61 'showaverages' => $checkbox_default,
62 'showgroups' => $checkbox_default,
63 'showlocks' => $checkbox_default,
64 'showranges' => $checkbox_default,
65 'showuserimage' => $checkbox_default,
66 'showactivityicons' => $checkbox_default);
68 $preferences['prefrows'] = array(
69 'averagesdisplaytype' => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default',
70 GRADE_REPORT_PREFERENCE_INHERIT => $strinherit,
71 GRADE_REPORT_GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
72 GRADE_REPORT_GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
73 GRADE_REPORT_GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades')),
74 'rangesdisplaytype' => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default',
75 GRADE_REPORT_PREFERENCE_INHERIT => $strinherit,
76 GRADE_REPORT_GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
77 GRADE_REPORT_GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
78 GRADE_REPORT_GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades')),
79 'averagesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default',
80 GRADE_REPORT_PREFERENCE_INHERIT => $strinherit, 0, 1, 2, 3, 4, 5),
81 'rangesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT => 'default',
82 GRADE_REPORT_PREFERENCE_INHERIT => $strinherit, 0, 1, 2, 3, 4, 5));
85 for ($i = 1; $i <= 10; $i++) {
86 $preferences['prefletters']['gradeboundary' . $i] = $percentages;
87 $preferences['prefletters']['gradeletter' . $i] = 'text';
90 foreach ($preferences as $group => $prefs) {
91 $mform->addElement('header', $group, get_string($group, 'grades'));
93 foreach ($prefs as $pref => $type) {
94 // Detect and process dynamically numbered preferences
95 if (preg_match('/([^[0-9]+)([0-9]+)/', $pref, $matches)) {
96 $lang_string = $matches[1];
97 $number = ' ' . $matches[2];
98 } else {
99 $lang_string = $pref;
100 $number = null;
103 $full_pref = 'grade_report_' . $pref;
105 $pref_value = get_user_preferences($full_pref);
107 $options = null;
108 if (is_array($type)) {
109 $options = $type;
110 $type = 'select';
111 $default = $options[$CFG->$full_pref];
112 } else {
113 $default = $CFG->$full_pref;
116 $help_string = get_string("config$lang_string", 'grades');
118 // Replace the 'default' value with the site default language string
119 if (!is_null($options) AND $options[GRADE_REPORT_PREFERENCE_DEFAULT] == 'default') {
120 $options[GRADE_REPORT_PREFERENCE_DEFAULT] = get_string('sitedefault', 'grades', $default);
121 } elseif ($type == 'text') {
122 $help_string = get_string("config{$lang_string}default", 'grades', $default);
125 $label = get_string($lang_string, 'grades') . $number;
127 $mform->addElement($type, $full_pref, $label, $options);
128 $mform->setHelpButton($full_pref, array(false, get_string($lang_string, 'grades'), false, true, false, $help_string));
129 $mform->setDefault($full_pref, $pref_value);
130 $mform->setType($full_pref, PARAM_ALPHANUM);
134 $mform->addElement('hidden', 'id');
135 $mform->setType('id', PARAM_INT);
136 $mform->setDefault('id', $course->id);
138 $this->add_action_buttons();
142 /// perform some extra moodle validation
143 function validation($data){
144 $errors= array();
145 if (0 == count($errors)){
146 return true;
147 } else {
148 return $errors;