3 require_once($CFG->libdir
.'/formslib.php');
6 * First implementation of the preferences in the form of a moodleform.
7 * TODO add "reset to site defaults" button
9 class grader_report_preferences_form
extends moodleform
{
11 function definition() {
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_REPORT_MEAN_ALL
=> get_string('meanall', 'grades'),
56 GRADE_REPORT_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 'shownumberofgrades' => $checkbox_default,
70 'averagesdisplaytype' => array(GRADE_REPORT_PREFERENCE_DEFAULT
=> 'default',
71 GRADE_REPORT_PREFERENCE_INHERIT
=> $strinherit,
72 GRADE_REPORT_GRADE_DISPLAY_TYPE_REAL
=> get_string('real', 'grades'),
73 GRADE_REPORT_GRADE_DISPLAY_TYPE_PERCENTAGE
=> get_string('percentage', 'grades'),
74 GRADE_REPORT_GRADE_DISPLAY_TYPE_LETTER
=> get_string('letter', 'grades')),
75 'rangesdisplaytype' => array(GRADE_REPORT_PREFERENCE_DEFAULT
=> 'default',
76 GRADE_REPORT_PREFERENCE_INHERIT
=> $strinherit,
77 GRADE_REPORT_GRADE_DISPLAY_TYPE_REAL
=> get_string('real', 'grades'),
78 GRADE_REPORT_GRADE_DISPLAY_TYPE_PERCENTAGE
=> get_string('percentage', 'grades'),
79 GRADE_REPORT_GRADE_DISPLAY_TYPE_LETTER
=> get_string('letter', 'grades')),
80 'averagesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT
=> 'default',
81 GRADE_REPORT_PREFERENCE_INHERIT
=> $strinherit, 0, 1, 2, 3, 4, 5),
82 'rangesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT
=> 'default',
83 GRADE_REPORT_PREFERENCE_INHERIT
=> $strinherit, 0, 1, 2, 3, 4, 5));
86 for ($i = 1; $i <= 10; $i++
) {
87 $preferences['prefletters']['gradeletter' . $i] = 'text';
88 $preferences['prefletters']['gradeboundary' . $i] = $percentages;
91 foreach ($preferences as $group => $prefs) {
92 $mform->addElement('header', $group, get_string($group, 'grades'));
94 foreach ($prefs as $pref => $type) {
95 // Detect and process dynamically numbered preferences
96 if (preg_match('/([^[0-9]+)([0-9]+)/', $pref, $matches)) {
97 $lang_string = $matches[1];
98 $number = ' ' . $matches[2];
100 $lang_string = $pref;
104 $full_pref = 'grade_report_' . $pref;
106 $pref_value = get_user_preferences($full_pref);
109 if (is_array($type)) {
112 $default = $options[$CFG->$full_pref];
114 $default = $CFG->$full_pref;
117 $help_string = get_string("config$lang_string", 'grades');
119 // Replace the 'default' value with the site default language string
120 if (!is_null($options) AND $options[GRADE_REPORT_PREFERENCE_DEFAULT
] == 'default') {
121 $options[GRADE_REPORT_PREFERENCE_DEFAULT
] = get_string('sitedefault', 'grades', $default);
122 } elseif ($type == 'text') {
123 $help_string = get_string("config{$lang_string}default", 'grades', $default);
126 $label = get_string($lang_string, 'grades') . $number;
128 $mform->addElement($type, $full_pref, $label, $options);
129 $mform->setHelpButton($full_pref, array(false, get_string($lang_string, 'grades'), false, true, false, $help_string));
130 $mform->setDefault($full_pref, $pref_value);
131 $mform->setType($full_pref, PARAM_ALPHANUM
);
135 $mform->addElement('hidden', 'id');
136 $mform->setType('id', PARAM_INT
);
137 $mform->setDefault('id', $course->id
);
139 $this->add_action_buttons();
143 /// perform some extra moodle validation
144 function validation($data){
146 if (0 == count($errors)){