Merge branch 'MDL-48795_27' of https://github.com/apsdehal/moodle into MOODLE_27_STABLE
[moodle.git] / mod / quiz / settings.php
blob97a6a88d5c17b9ec4bd28854a1a55e22ff3794a0
1 <?php
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.
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/>.
17 /**
18 * Administration settings definitions for the quiz module.
20 * @package mod_quiz
21 * @copyright 2010 Petr Skoda
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
28 require_once($CFG->dirroot . '/mod/quiz/lib.php');
30 // First get a list of quiz reports with there own settings pages. If there none,
31 // we use a simpler overall menu structure.
32 $reports = core_component::get_plugin_list_with_file('quiz', 'settings.php', false);
33 $reportsbyname = array();
34 foreach ($reports as $report => $reportdir) {
35 $strreportname = get_string($report . 'report', 'quiz_'.$report);
36 $reportsbyname[$strreportname] = $report;
38 core_collator::ksort($reportsbyname);
40 // First get a list of quiz reports with there own settings pages. If there none,
41 // we use a simpler overall menu structure.
42 $rules = core_component::get_plugin_list_with_file('quizaccess', 'settings.php', false);
43 $rulesbyname = array();
44 foreach ($rules as $rule => $ruledir) {
45 $strrulename = get_string('pluginname', 'quizaccess_' . $rule);
46 $rulesbyname[$strrulename] = $rule;
48 core_collator::ksort($rulesbyname);
50 // Create the quiz settings page.
51 if (empty($reportsbyname) && empty($rulesbyname)) {
52 $pagetitle = get_string('modulename', 'quiz');
53 } else {
54 $pagetitle = get_string('generalsettings', 'admin');
56 $quizsettings = new admin_settingpage('modsettingquiz', $pagetitle, 'moodle/site:config');
58 if ($ADMIN->fulltree) {
59 // Introductory explanation that all the settings are defaults for the add quiz form.
60 $quizsettings->add(new admin_setting_heading('quizintro', '', get_string('configintro', 'quiz')));
62 // Time limit.
63 $quizsettings->add(new admin_setting_configtext_with_advanced('quiz/timelimit',
64 get_string('timelimitsec', 'quiz'), get_string('configtimelimitsec', 'quiz'),
65 array('value' => '0', 'adv' => false), PARAM_INT));
67 // What to do with overdue attempts.
68 $quizsettings->add(new mod_quiz_admin_setting_overduehandling('quiz/overduehandling',
69 get_string('overduehandling', 'quiz'), get_string('overduehandling_desc', 'quiz'),
70 array('value' => 'autoabandon', 'adv' => false), null));
72 // Grace period time.
73 $quizsettings->add(new admin_setting_configtext_with_advanced('quiz/graceperiod',
74 get_string('graceperiod', 'quiz'), get_string('graceperiod_desc', 'quiz'),
75 array('value' => '86400', 'adv' => false), PARAM_INT));
77 // Minimum grace period used behind the scenes.
78 $quizsettings->add(new admin_setting_configtext('quiz/graceperiodmin',
79 get_string('graceperiodmin', 'quiz'), get_string('graceperiodmin_desc', 'quiz'),
80 60, PARAM_INT));
82 // Number of attempts.
83 $options = array(get_string('unlimited'));
84 for ($i = 1; $i <= QUIZ_MAX_ATTEMPT_OPTION; $i++) {
85 $options[$i] = $i;
87 $quizsettings->add(new admin_setting_configselect_with_advanced('quiz/attempts',
88 get_string('attemptsallowed', 'quiz'), get_string('configattemptsallowed', 'quiz'),
89 array('value' => 0, 'adv' => false), $options));
91 // Grading method.
92 $quizsettings->add(new mod_quiz_admin_setting_grademethod('quiz/grademethod',
93 get_string('grademethod', 'quiz'), get_string('configgrademethod', 'quiz'),
94 array('value' => QUIZ_GRADEHIGHEST, 'adv' => false), null));
96 // Maximum grade.
97 $quizsettings->add(new admin_setting_configtext('quiz/maximumgrade',
98 get_string('maximumgrade'), get_string('configmaximumgrade', 'quiz'), 10, PARAM_INT));
100 // Shuffle questions.
101 $quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/shufflequestions',
102 get_string('shufflequestions', 'quiz'), get_string('configshufflequestions', 'quiz'),
103 array('value' => 0, 'adv' => false)));
105 // Questions per page.
106 $perpage = array();
107 $perpage[0] = get_string('never');
108 $perpage[1] = get_string('aftereachquestion', 'quiz');
109 for ($i = 2; $i <= QUIZ_MAX_QPP_OPTION; ++$i) {
110 $perpage[$i] = get_string('afternquestions', 'quiz', $i);
112 $quizsettings->add(new admin_setting_configselect_with_advanced('quiz/questionsperpage',
113 get_string('newpageevery', 'quiz'), get_string('confignewpageevery', 'quiz'),
114 array('value' => 1, 'adv' => false), $perpage));
116 // Navigation method.
117 $quizsettings->add(new admin_setting_configselect_with_advanced('quiz/navmethod',
118 get_string('navmethod', 'quiz'), get_string('confignavmethod', 'quiz'),
119 array('value' => QUIZ_NAVMETHOD_FREE, 'adv' => true), quiz_get_navigation_options()));
121 // Shuffle within questions.
122 $quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/shuffleanswers',
123 get_string('shufflewithin', 'quiz'), get_string('configshufflewithin', 'quiz'),
124 array('value' => 1, 'adv' => false)));
126 // Preferred behaviour.
127 $quizsettings->add(new admin_setting_question_behaviour('quiz/preferredbehaviour',
128 get_string('howquestionsbehave', 'question'), get_string('howquestionsbehave_desc', 'quiz'),
129 'deferredfeedback'));
131 // Each attempt builds on last.
132 $quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/attemptonlast',
133 get_string('eachattemptbuildsonthelast', 'quiz'),
134 get_string('configeachattemptbuildsonthelast', 'quiz'),
135 array('value' => 0, 'adv' => true)));
137 // Review options.
138 $quizsettings->add(new admin_setting_heading('reviewheading',
139 get_string('reviewoptionsheading', 'quiz'), ''));
140 foreach (mod_quiz_admin_review_setting::fields() as $field => $name) {
141 $default = mod_quiz_admin_review_setting::all_on();
142 $forceduring = null;
143 if ($field == 'attempt') {
144 $forceduring = true;
145 } else if ($field == 'overallfeedback') {
146 $default = $default ^ mod_quiz_admin_review_setting::DURING;
147 $forceduring = false;
149 $quizsettings->add(new mod_quiz_admin_review_setting('quiz/review' . $field,
150 $name, '', $default, $forceduring));
153 // Show the user's picture.
154 $quizsettings->add(new mod_quiz_admin_setting_user_image('quiz/showuserpicture',
155 get_string('showuserpicture', 'quiz'), get_string('configshowuserpicture', 'quiz'),
156 array('value' => 0, 'adv' => false), null));
158 // Decimal places for overall grades.
159 $options = array();
160 for ($i = 0; $i <= QUIZ_MAX_DECIMAL_OPTION; $i++) {
161 $options[$i] = $i;
163 $quizsettings->add(new admin_setting_configselect_with_advanced('quiz/decimalpoints',
164 get_string('decimalplaces', 'quiz'), get_string('configdecimalplaces', 'quiz'),
165 array('value' => 2, 'adv' => false), $options));
167 // Decimal places for question grades.
168 $options = array(-1 => get_string('sameasoverall', 'quiz'));
169 for ($i = 0; $i <= QUIZ_MAX_Q_DECIMAL_OPTION; $i++) {
170 $options[$i] = $i;
172 $quizsettings->add(new admin_setting_configselect_with_advanced('quiz/questiondecimalpoints',
173 get_string('decimalplacesquestion', 'quiz'),
174 get_string('configdecimalplacesquestion', 'quiz'),
175 array('value' => -1, 'adv' => true), $options));
177 // Show blocks during quiz attempts.
178 $quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/showblocks',
179 get_string('showblocks', 'quiz'), get_string('configshowblocks', 'quiz'),
180 array('value' => 0, 'adv' => true)));
182 // Password.
183 $quizsettings->add(new admin_setting_configtext_with_advanced('quiz/password',
184 get_string('requirepassword', 'quiz'), get_string('configrequirepassword', 'quiz'),
185 array('value' => '', 'adv' => true), PARAM_TEXT));
187 // IP restrictions.
188 $quizsettings->add(new admin_setting_configtext_with_advanced('quiz/subnet',
189 get_string('requiresubnet', 'quiz'), get_string('configrequiresubnet', 'quiz'),
190 array('value' => '', 'adv' => true), PARAM_TEXT));
192 // Enforced delay between attempts.
193 $quizsettings->add(new admin_setting_configtext_with_advanced('quiz/delay1',
194 get_string('delay1st2nd', 'quiz'), get_string('configdelay1st2nd', 'quiz'),
195 array('value' => 0, 'adv' => true), PARAM_INT));
196 $quizsettings->add(new admin_setting_configtext_with_advanced('quiz/delay2',
197 get_string('delaylater', 'quiz'), get_string('configdelaylater', 'quiz'),
198 array('value' => 0, 'adv' => true), PARAM_INT));
200 // Browser security.
201 $quizsettings->add(new mod_quiz_admin_setting_browsersecurity('quiz/browsersecurity',
202 get_string('showinsecurepopup', 'quiz'), get_string('configpopup', 'quiz'),
203 array('value' => '-', 'adv' => true), null));
205 // Allow user to specify if setting outcomes is an advanced setting.
206 if (!empty($CFG->enableoutcomes)) {
207 $quizsettings->add(new admin_setting_configcheckbox('quiz/outcomes_adv',
208 get_string('outcomesadvanced', 'quiz'), get_string('configoutcomesadvanced', 'quiz'),
209 '0'));
212 // Autosave frequency.
213 $options = array(
214 0 => get_string('donotuseautosave', 'quiz'),
215 60 => get_string('oneminute', 'quiz'),
216 120 => get_string('numminutes', 'moodle', 2),
217 300 => get_string('numminutes', 'moodle', 5),
219 $quizsettings->add(new admin_setting_configselect('quiz/autosaveperiod',
220 get_string('autosaveperiod', 'quiz'), get_string('autosaveperiod_desc', 'quiz'), 0, $options));
223 // Now, depending on whether any reports have their own settings page, add
224 // the quiz setting page to the appropriate place in the tree.
225 if (empty($reportsbyname) && empty($rulesbyname)) {
226 $ADMIN->add('modsettings', $quizsettings);
227 } else {
228 $ADMIN->add('modsettings', new admin_category('modsettingsquizcat',
229 get_string('modulename', 'quiz'), $module->is_enabled() === false));
230 $ADMIN->add('modsettingsquizcat', $quizsettings);
232 // Add settings pages for the quiz report subplugins.
233 foreach ($reportsbyname as $strreportname => $report) {
234 $reportname = $report;
236 $settings = new admin_settingpage('modsettingsquizcat'.$reportname,
237 $strreportname, 'moodle/site:config', $module->is_enabled() === false);
238 if ($ADMIN->fulltree) {
239 include($CFG->dirroot . "/mod/quiz/report/$reportname/settings.php");
241 if (!empty($settings)) {
242 $ADMIN->add('modsettingsquizcat', $settings);
246 // Add settings pages for the quiz access rule subplugins.
247 foreach ($rulesbyname as $strrulename => $rule) {
248 $settings = new admin_settingpage('modsettingsquizcat' . $rule,
249 $strrulename, 'moodle/site:config', $module->is_enabled() === false);
250 if ($ADMIN->fulltree) {
251 include($CFG->dirroot . "/mod/quiz/accessrule/$rule/settings.php");
253 if (!empty($settings)) {
254 $ADMIN->add('modsettingsquizcat', $settings);
259 $settings = null; // We do not want standard settings link.