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 /// form definition with preferences defaults
21 //--------------------------------------------------------------------------------
22 $preferences = array('bulkcheckboxes' => 'advcheckbox',
23 'enableajax' => 'advcheckbox',
24 'showcalculations' => 'advcheckbox',
25 'showeyecons' => 'advcheckbox',
26 'showaverages' => 'advcheckbox',
27 'showgroups' => 'advcheckbox',
28 'showlocks' => 'advcheckbox',
29 'showranges' => 'advcheckbox',
30 'quickgrading' => 'advcheckbox',
31 'quickfeedback' => 'advcheckbox',
32 'showuserimage' => 'advcheckbox',
33 'meanselection' => array(GRADE_AGGREGATE_MEAN_ALL
=> get_string('meanall', 'grades'),
34 GRADE_AGGREGATE_MEAN_GRADED
=> get_string('meangraded', 'grades')),
35 'aggregationposition' => array(GRADE_REPORT_AGGREGATION_POSITION_LEFT
=> get_string('left', 'grades'),
36 GRADE_REPORT_AGGREGATION_POSITION_RIGHT
=> get_string('right', 'grades')),
37 'aggregationview' => array(GRADE_REPORT_AGGREGATION_VIEW_FULL
=> get_string('full', 'grades'),
38 GRADE_REPORT_AGGREGATION_VIEW_COMPACT
=> get_string('compact', 'grades')),
39 'gradedisplaytype' => array(GRADE_REPORT_GRADE_DISPLAY_TYPE_REAL
=> get_string('real', 'grades'),
40 GRADE_REPORT_GRADE_DISPLAY_TYPE_PERCENTAGE
=> get_string('percentage', 'grades')),
41 'averagesdisplaytype' => array(GRADE_REPORT_PREFERENCE_INHERIT
=> get_string('inherit', 'grades'),
42 GRADE_REPORT_GRADE_DISPLAY_TYPE_REAL
=> get_string('real', 'grades'),
43 GRADE_REPORT_GRADE_DISPLAY_TYPE_PERCENTAGE
=> get_string('percentage', 'grades')),
44 'rangesdisplaytype' => array(GRADE_REPORT_PREFERENCE_INHERIT
=> get_string('inherit', 'grades'),
45 GRADE_REPORT_GRADE_DISPLAY_TYPE_REAL
=> get_string('real', 'grades'),
46 GRADE_REPORT_GRADE_DISPLAY_TYPE_PERCENTAGE
=> get_string('percentage', 'grades')),
47 'averagesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_INHERIT
=> get_string('inherit', 'grades'),
49 'rangesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_INHERIT
=> get_string('inherit', 'grades'),
51 'decimalpoints' => array(0, 1, 2, 3, 4, 5),
52 'studentsperpage' => 'text');
54 foreach ($preferences as $pref => $type) {
55 $full_pref = 'grade_report_' . $pref;
56 $pref_value = get_user_preferences($full_pref, $CFG->$full_pref);
59 if (is_array($type)) {
64 $mform->addElement($type, $full_pref, get_string($pref, 'grades'), $options);
65 $mform->setHelpButton($full_pref, array(false, get_string($pref, 'grades'), false, true, false, get_string("config$pref", 'grades')));
66 $mform->setDefault($full_pref, $pref_value);
67 $mform->setType($full_pref, PARAM_ALPHANUM
);
70 $mform->addElement('hidden', 'id');
71 $mform->setType('id', PARAM_INT
);
72 $mform->setDefault('id', $course->id
);
74 $this->add_action_buttons();
78 /// perform some extra moodle validation
79 function validation($data){
81 if (0 == count($errors)){