MDL-10364 Added the showcalculations preference and re-factored preferences_form...
[moodle-pu.git] / grade / report / grader / preferences_form.php
blob44e56b4e055df5d2aa82ff1dc3d954e2cf20e840
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 submit button
8 * TODO add "reset to site defaults" button
9 * TODO show site defaults near each setting
11 class grader_report_preferences_form extends moodleform {
13 function definition() {
14 global $USER, $CFG;
16 $mform =& $this->_form;
17 $course = $this->_customdata['course'];
19 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
21 /// form definition with preferences defaults
22 //--------------------------------------------------------------------------------
23 $preferences = array('bulkcheckboxes' => 'checkbox',
24 'enableajax' => 'checkbox',
25 'showcalculations' => 'checkbox',
26 'showeyecons' => 'checkbox',
27 'showgrandtotals' => 'checkbox',
28 'showgroups' => 'checkbox',
29 'showlocks' => 'checkbox',
30 'shownotes' => 'checkbox',
31 'showscales' => 'checkbox',
32 'aggregationposition' => array(get_string('left', 'grades'), get_string('right', 'grades')),
33 'aggregationview' => array(get_string('full', 'grades'), get_string('compact', 'grades')),
34 'gradedisplaytype' => array(get_string('raw', 'grades'), get_string('percentage', 'grades')),
35 'grandtotalsdisplaytype' => array(get_string('raw', 'grades'), get_string('percentage', 'grades')),
36 'feedbackformat' => array(get_string('text', 'grades'), get_string('html', 'grades')),
37 'decimalpoints' => array(0, 1, 2, 3, 4, 5),
38 'studentsperpage' => 'text');
40 foreach ($preferences as $pref => $type) {
41 $full_pref = 'grade_report_' . $pref;
42 $pref_value = get_user_preferences($full_pref, $CFG->$full_pref);
44 $options = null;
45 if (is_array($type)) {
46 $options = $type;
47 $type = 'select';
50 $mform->addElement($type, $full_pref, get_string($pref, 'grades'), $options);
51 $mform->setHelpButton($full_pref, array(false, get_string($pref, 'grades'), false, true, false, get_string("config_$pref", 'grades')));
52 $mform->setDefault($full_pref, $pref_value);
53 $mform->setType($full_pref, PARAM_INT);
56 $mform->addElement('hidden', 'id');
57 $mform->setType('id', PARAM_INT);
58 $mform->setDefault('id', $course->id);
60 $this->add_action_buttons();
64 /// perform some extra moodle validation
65 function validation($data){
66 $errors= array();
67 if (0 == count($errors)){
68 return true;
69 } else {
70 return $errors;