MDL-47276 quiz: change default for When time expires for new installs
[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
8a347d80
TH
58if ($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')));
61
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));
66
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'),
129a4568 70 array('value' => 'autosubmit', 'adv' => false), null));
8a347d80
TH
71
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));
76
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));
81
82 // Number of attempts.
83 $options = array(get_string('unlimited'));
84 for ($i = 1; $i <= QUIZ_MAX_ATTEMPT_OPTION; $i++) {
85 $options[$i] = $i;
86 }
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));
90
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));
95
96 // Maximum grade.
97 $quizsettings->add(new admin_setting_configtext('quiz/maximumgrade',
98 get_string('maximumgrade'), get_string('configmaximumgrade', 'quiz'), 10, PARAM_INT));
99
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)));
104
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);
111 }
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));
115
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()));
120
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)));
125
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'));
130
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)));
136
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;
148 }
149 $quizsettings->add(new mod_quiz_admin_review_setting('quiz/review' . $field,
150 $name, '', $default, $forceduring));
14936199 151 }
84e628a0 152
8a347d80
TH
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'),
0e8fe7de 156 array('value' => 0, 'adv' => false), null));
e2249afe 157
8a347d80
TH
158 // Decimal places for overall grades.
159 $options = array();
160 for ($i = 0; $i <= QUIZ_MAX_DECIMAL_OPTION; $i++) {
161 $options[$i] = $i;
162 }
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));
166
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;
171 }
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));
176
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)));
181
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));
186
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));
191
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));
199
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));
204
31805089 205 // Allow user to specify if setting outcomes is an advanced setting.
8a347d80
TH
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'));
210 }
d18f78b0 211
8a347d80
TH
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),
218 );
219 $quizsettings->add(new admin_setting_configselect('quiz/autosaveperiod',
220 get_string('autosaveperiod', 'quiz'), get_string('autosaveperiod_desc', 'quiz'), 0, $options));
221}
59570888 222
55ca80ed
TH
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.
53f89488 225if (empty($reportsbyname) && empty($rulesbyname)) {
e2249afe 226 $ADMIN->add('modsettings', $quizsettings);
227} else {
55ca80ed 228 $ADMIN->add('modsettings', new admin_category('modsettingsquizcat',
fde6f79f 229 get_string('modulename', 'quiz'), $module->is_enabled() === false));
e2249afe 230 $ADMIN->add('modsettingsquizcat', $quizsettings);
231
53f89488 232 // Add settings pages for the quiz report subplugins.
e2249afe 233 foreach ($reportsbyname as $strreportname => $report) {
234 $reportname = $report;
dbf9e4ba 235
55ca80ed 236 $settings = new admin_settingpage('modsettingsquizcat'.$reportname,
fde6f79f 237 $strreportname, 'moodle/site:config', $module->is_enabled() === false);
e2249afe 238 if ($ADMIN->fulltree) {
4344c5d5 239 include($CFG->dirroot . "/mod/quiz/report/$reportname/settings.php");
e2249afe 240 }
53f89488
TH
241 if (!empty($settings)) {
242 $ADMIN->add('modsettingsquizcat', $settings);
243 }
244 }
245
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");
252 }
253 if (!empty($settings)) {
254 $ADMIN->add('modsettingsquizcat', $settings);
255 }
e2249afe 256 }
257}
dbf9e4ba 258
9e83f3d1 259$settings = null; // We do not want standard settings link.