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