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
8 * TODO show site defaults near each setting
10 class grader_report_preferences_form
extends moodleform
{
12 function definition() {
15 $mform =& $this->_form
;
16 $course = $this->_customdata
['course'];
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 $strdefault = get_string('default', 'grades');
25 $strinherit = get_string('inherit', 'grades');
26 $stryes = get_string('yes');
27 $strno = get_string('no');
29 $percentages = array(GRADE_REPORT_PREFERENCE_DEFAULT
=> $strdefault,
30 GRADE_REPORT_PREFERENCE_UNUSED
=> get_string('unused', 'grades'));
31 for ($i=100; $i > -1; $i--) {
32 $percentages[$i] = "$i%";
35 $checkbox_default = array(GRADE_REPORT_PREFERENCE_DEFAULT
=> $strdefault, 0 => $strno, 1 => $stryes);
37 /// form definition with preferences defaults
38 //--------------------------------------------------------------------------------
39 $preferences = array('bulkcheckboxes' => $checkbox_default,
40 'enableajax' => $checkbox_default,
41 'showcalculations' => $checkbox_default,
42 'showeyecons' => $checkbox_default,
43 'showaverages' => $checkbox_default,
44 'showgroups' => $checkbox_default,
45 'showlocks' => $checkbox_default,
46 'showranges' => $checkbox_default,
47 'quickgrading' => $checkbox_default,
48 'quickfeedback' => $checkbox_default,
49 'showuserimage' => $checkbox_default,
50 'meanselection' => array(GRADE_REPORT_PREFERENCE_DEFAULT
=> $strdefault,
51 GRADE_AGGREGATE_MEAN_ALL
=> get_string('meanall', 'grades'),
52 GRADE_AGGREGATE_MEAN_GRADED
=> get_string('meangraded', 'grades')),
53 'aggregationposition' => array(GRADE_REPORT_PREFERENCE_DEFAULT
=> $strdefault,
54 GRADE_REPORT_AGGREGATION_POSITION_LEFT
=> get_string('left', 'grades'),
55 GRADE_REPORT_AGGREGATION_POSITION_RIGHT
=> get_string('right', 'grades')),
56 'aggregationview' => array(GRADE_REPORT_PREFERENCE_DEFAULT
=> $strdefault,
57 GRADE_REPORT_AGGREGATION_VIEW_FULL
=> get_string('full', 'grades'),
58 GRADE_REPORT_AGGREGATION_VIEW_COMPACT
=> get_string('compact', 'grades')),
59 'gradedisplaytype' => array(GRADE_REPORT_PREFERENCE_DEFAULT
=> $strdefault,
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 'averagesdisplaytype' => array(GRADE_REPORT_PREFERENCE_DEFAULT
=> $strdefault,
64 GRADE_REPORT_PREFERENCE_INHERIT
=> $strinherit,
65 GRADE_REPORT_GRADE_DISPLAY_TYPE_REAL
=> get_string('real', 'grades'),
66 GRADE_REPORT_GRADE_DISPLAY_TYPE_PERCENTAGE
=> get_string('percentage', 'grades'),
67 GRADE_REPORT_GRADE_DISPLAY_TYPE_LETTER
=> get_string('letter', 'grades')),
68 'rangesdisplaytype' => array(GRADE_REPORT_PREFERENCE_DEFAULT
=> $strdefault,
69 GRADE_REPORT_PREFERENCE_INHERIT
=> $strinherit,
70 GRADE_REPORT_GRADE_DISPLAY_TYPE_REAL
=> get_string('real', 'grades'),
71 GRADE_REPORT_GRADE_DISPLAY_TYPE_PERCENTAGE
=> get_string('percentage', 'grades'),
72 GRADE_REPORT_GRADE_DISPLAY_TYPE_LETTER
=> get_string('letter', 'grades')),
73 'averagesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT
=> $strdefault,
74 GRADE_REPORT_PREFERENCE_INHERIT
=> $strinherit,
76 'rangesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT
=> $strdefault,
77 GRADE_REPORT_PREFERENCE_INHERIT
=> $strinherit,
79 'decimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT
=> $strdefault,
81 'studentsperpage' => 'text');
83 for ($i = 1; $i <= 10; $i++
) {
84 $preferences['gradeboundary' . $i] = $percentages;
85 $preferences['gradeletter' . $i] = 'text';
88 foreach ($preferences as $pref => $type) {
89 if (preg_match('/([^[0-9]+)([0-9]+)/', $pref, $matches)) {
90 $lang_string = $matches[1];
91 $number = ' ' . $matches[2];
97 $full_pref = 'grade_report_' . $pref;
99 $pref_value = get_user_preferences($full_pref);
102 if (is_array($type)) {
105 $default = $options[$CFG->$full_pref];
107 $default = $CFG->$full_pref;
109 $default_label = get_string($lang_string, 'grades') . $number . ' (' . $strdefault . ': ' . $default . ')';
111 $mform->addElement($type, $full_pref, $default_label, $options);
112 $mform->setHelpButton($full_pref, array(false, get_string($lang_string, 'grades'), false, true, false,
113 get_string("config$lang_string", 'grades')));
114 $mform->setDefault($full_pref, $pref_value);
115 $mform->setType($full_pref, PARAM_ALPHANUM
);
118 $mform->addElement('hidden', 'id');
119 $mform->setType('id', PARAM_INT
);
120 $mform->setDefault('id', $course->id
);
122 $this->add_action_buttons();
126 /// perform some extra moodle validation
127 function validation($data){
129 if (0 == count($errors)){