weekly release 4.1dev
[moodle.git] / grade / edit / settings / form.php
CommitLineData
e060e33d 1<?php
e060e33d 2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
8ad36f4c 16
a153c9f2
AD
17/**
18 * A form for editing course grade settings
19 *
20 * @package core_grades
21 * @copyright 2007 Petr Skoda
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
bfebaf64
MD
25if (!defined('MOODLE_INTERNAL')) {
26 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
27}
28
e0724506 29require_once($CFG->libdir.'/formslib.php');
30
31/**
32 * First implementation of the preferences in the form of a moodleform.
33 * TODO add "reset to site defaults" button
34 */
35class course_settings_form extends moodleform {
36
37 function definition() {
54c4a2cb 38 global $USER, $CFG;
e0724506 39
40 $mform =& $this->_form;
d24832f9 41
d4060472 42 $systemcontext = context_system::instance();
10957cf0 43 $can_view_admin_links = false;
44 if (has_capability('moodle/grade:manage', $systemcontext)) {
45 $can_view_admin_links = true;
46 }
e0724506 47
10957cf0 48 // General settings
49 $strchangedefaults = get_string('changedefaults', 'grades');
50 $mform->addElement('header', 'general', get_string('generalsettings', 'grades'));
51 if ($can_view_admin_links) {
d1aa1e48 52 $link = '<a href="' . $CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=gradessettings">' . $strchangedefaults . '</a>';
47809801 53 $mform->addElement('static', 'generalsettingslink', null, $link);
10957cf0 54 }
55 $options = array(-1 => get_string('default', 'grades'),
56 GRADE_REPORT_AGGREGATION_POSITION_FIRST => get_string('positionfirst', 'grades'),
57 GRADE_REPORT_AGGREGATION_POSITION_LAST => get_string('positionlast', 'grades'));
58 $default_gradedisplaytype = $CFG->grade_aggregationposition;
59 foreach ($options as $key=>$option) {
60 if ($key == $default_gradedisplaytype) {
61 $options[-1] = get_string('defaultprev', 'grades', $option);
62 break;
63 }
64 }
65 $mform->addElement('select', 'aggregationposition', get_string('aggregationposition', 'grades'), $options);
6e2d05ae 66 $mform->addHelpButton('aggregationposition', 'aggregationposition', 'grades');
10957cf0 67
ebea19cb
FM
68 if ($CFG->grade_minmaxtouse == GRADE_MIN_MAX_FROM_GRADE_ITEM) {
69 $default = get_string('gradeitemminmax', 'grades');
70 } else if ($CFG->grade_minmaxtouse == GRADE_MIN_MAX_FROM_GRADE_GRADE) {
71 $default = get_string('gradegrademinmax', 'grades');
72 } else {
73 throw new coding_exception('Invalid $CFG->grade_minmaxtouse value.');
74 }
75
76 $options = array(
77 -1 => get_string('defaultprev', 'grades', $default),
78 GRADE_MIN_MAX_FROM_GRADE_ITEM => get_string('gradeitemminmax', 'grades'),
79 GRADE_MIN_MAX_FROM_GRADE_GRADE => get_string('gradegrademinmax', 'grades')
80 );
81 $mform->addElement('select', 'minmaxtouse', get_string('minmaxtouse', 'grades'), $options);
82 $mform->addHelpButton('minmaxtouse', 'minmaxtouse', 'grades');
83
10957cf0 84 // Grade item settings
85 $mform->addElement('header', 'grade_item_settings', get_string('gradeitemsettings', 'grades'));
fb69f811 86 $mform->setExpanded('grade_item_settings');
10957cf0 87 if ($can_view_admin_links) {
d1aa1e48 88 $link = '<a href="' . $CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=gradeitemsettings">' . $strchangedefaults . '</a>';
47809801 89 $mform->addElement('static', 'gradeitemsettingslink', null, $link);
10957cf0 90 }
e0724506 91
92 $options = array(-1 => get_string('default', 'grades'),
93 GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
86a9e60c 94 GRADE_DISPLAY_TYPE_REAL_PERCENTAGE => get_string('realpercentage', 'grades'),
95 GRADE_DISPLAY_TYPE_REAL_LETTER => get_string('realletter', 'grades'),
afa0968d 96 GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
97 GRADE_DISPLAY_TYPE_PERCENTAGE_REAL => get_string('percentagereal', 'grades'),
86a9e60c 98 GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER => get_string('percentageletter', 'grades'),
afa0968d 99 GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'),
100 GRADE_DISPLAY_TYPE_LETTER_REAL => get_string('letterreal', 'grades'),
101 GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE => get_string('letterpercentage', 'grades'));
86a9e60c 102
e0724506 103 $default_gradedisplaytype = $CFG->grade_displaytype;
104 foreach ($options as $key=>$option) {
105 if ($key == $default_gradedisplaytype) {
106 $options[-1] = get_string('defaultprev', 'grades', $option);
107 break;
108 }
109 }
110 $mform->addElement('select', 'displaytype', get_string('gradedisplaytype', 'grades'), $options);
56f9c6ce 111 $mform->addHelpButton('displaytype', 'gradedisplaytype', 'grades');
afa0968d 112 $mform->setDefault('displaytype', -1);
e0724506 113
114 $options = array(-1=> get_string('defaultprev', 'grades', $CFG->grade_decimalpoints), 0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5);
115 $mform->addElement('select', 'decimalpoints', get_string('decimalpoints', 'grades'), $options);
1155b8db 116 $mform->addHelpButton('decimalpoints', 'decimalpoints', 'grades');
e0724506 117
26ed0305 118// add setting options for plugins
119 $types = array('report', 'export', 'import');
120
121 foreach($types as $type) {
bd3b3bba 122 foreach (core_component::get_plugin_list('grade'.$type) as $plugin => $plugindir) {
26ed0305 123 // Include all the settings commands for this plugin if there are any
17da2e6f 124 if (file_exists($plugindir.'/lib.php')) {
125 require_once($plugindir.'/lib.php');
26ed0305 126 $functionname = 'grade_'.$type.'_'.$plugin.'_settings_definition';
127 if (function_exists($functionname)) {
b5e7b2bf 128 $mform->addElement('header', 'grade_'.$type.$plugin, get_string('pluginname', 'grade'.$type.'_'.$plugin, NULL));
fb69f811 129 $mform->setExpanded('grade_'.$type.$plugin);
10957cf0 130 if ($can_view_admin_links) {
d1aa1e48 131 $link = '<a href="' . $CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=gradereport' . $plugin . '">' . $strchangedefaults . '</a>';
47809801 132 $mform->addElement('static', 'gradeitemsettingslink', null, $link);
d24832f9 133 }
26ed0305 134 $functionname($mform);
135 }
136 }
137 }
138 }
139
140 $mform->addElement('hidden', 'id');
141 $mform->setType('id', PARAM_INT);
e0724506 142
c94ba3ee 143 $this->add_action_buttons(false);
e0724506 144 }
145}
6c3ef410 146