2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * Administration settings definitions for the quiz module.
21 * @copyright 2010 Petr Skoda
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 use mod_quiz\admin\review_setting
;
27 defined('MOODLE_INTERNAL') ||
die();
29 require_once($CFG->dirroot
. '/mod/quiz/lib.php');
31 // First get a list of quiz reports with there own settings pages. If there none,
32 // we use a simpler overall menu structure.
33 $reports = core_component
::get_plugin_list_with_file('quiz', 'settings.php', false);
35 foreach ($reports as $report => $reportdir) {
36 $strreportname = get_string($report . 'report', 'quiz_'.$report);
37 $reportsbyname[$strreportname] = $report;
39 core_collator
::ksort($reportsbyname);
41 // First get a list of quiz reports with there own settings pages. If there none,
42 // we use a simpler overall menu structure.
43 $rules = core_component
::get_plugin_list_with_file('quizaccess', 'settings.php', false);
45 foreach ($rules as $rule => $ruledir) {
46 $strrulename = get_string('pluginname', 'quizaccess_' . $rule);
47 $rulesbyname[$strrulename] = $rule;
49 core_collator
::ksort($rulesbyname);
51 // Create the quiz settings page.
52 if (empty($reportsbyname) && empty($rulesbyname)) {
53 $pagetitle = get_string('modulename', 'quiz');
55 $pagetitle = get_string('generalsettings', 'admin');
57 $quizsettings = new admin_settingpage('modsettingquiz', $pagetitle, 'moodle/site:config');
59 if ($ADMIN->fulltree
) {
60 // Introductory explanation that all the settings are defaults for the add quiz form.
61 $quizsettings->add(new admin_setting_heading('quizintro', '', get_string('configintro', 'quiz')));
64 $setting = new admin_setting_configduration('quiz/timelimit',
65 get_string('timelimit', 'quiz'), get_string('configtimelimitsec', 'quiz'),
67 $setting->set_advanced_flag_options(admin_setting_flag
::ENABLED
, false);
68 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
69 $quizsettings->add($setting);
71 // Delay to notify graded attempts.
72 $quizsettings->add(new admin_setting_configduration('quiz/notifyattemptgradeddelay',
73 get_string('attemptgradeddelay', 'quiz'), get_string('attemptgradeddelay_desc', 'quiz'), 5 * HOURSECS
, HOURSECS
));
75 // What to do with overdue attempts.
76 $setting = new \mod_quiz\admin\
overdue_handling_setting('quiz/overduehandling',
77 get_string('overduehandling', 'quiz'), get_string('overduehandling_desc', 'quiz'),
78 ['value' => 'autosubmit', 'adv' => false], null);
79 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
80 $quizsettings->add($setting);
83 $setting = new admin_setting_configduration('quiz/graceperiod',
84 get_string('graceperiod', 'quiz'), get_string('graceperiod_desc', 'quiz'),
86 $setting->set_advanced_flag_options(admin_setting_flag
::ENABLED
, false);
87 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
88 $quizsettings->add($setting);
90 // Minimum grace period used behind the scenes.
91 $quizsettings->add(new admin_setting_configduration('quiz/graceperiodmin',
92 get_string('graceperiodmin', 'quiz'), get_string('graceperiodmin_desc', 'quiz'),
95 // Number of attempts.
96 $options = [get_string('unlimited')];
97 for ($i = 1; $i <= QUIZ_MAX_ATTEMPT_OPTION
; $i++
) {
100 $setting = new admin_setting_configselect('quiz/attempts',
101 get_string('attemptsallowed', 'quiz'), get_string('configattemptsallowed', 'quiz'),
103 $setting->set_advanced_flag_options(admin_setting_flag
::ENABLED
, false);
104 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
105 $quizsettings->add($setting);
108 $setting = new \mod_quiz\admin\
grade_method_setting('quiz/grademethod',
109 get_string('grademethod', 'quiz'), get_string('configgrademethod', 'quiz'),
110 ['value' => QUIZ_GRADEHIGHEST
, 'adv' => false], null);
111 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
112 $quizsettings->add($setting);
115 $setting = new admin_setting_configtext('quiz/maximumgrade',
116 get_string('maximumgrade'), get_string('configmaximumgrade', 'quiz'), 10, PARAM_INT
);
117 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
118 $quizsettings->add($setting);
120 // Questions per page.
122 $perpage[0] = get_string('never');
123 $perpage[1] = get_string('aftereachquestion', 'quiz');
124 for ($i = 2; $i <= QUIZ_MAX_QPP_OPTION
; ++
$i) {
125 $perpage[$i] = get_string('afternquestions', 'quiz', $i);
127 $setting = new admin_setting_configselect('quiz/questionsperpage',
128 get_string('newpageevery', 'quiz'), get_string('confignewpageevery', 'quiz'),
130 $setting->set_advanced_flag_options(admin_setting_flag
::ENABLED
, false);
131 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
132 $quizsettings->add($setting);
134 // Navigation method.
135 $setting = new admin_setting_configselect('quiz/navmethod',
136 get_string('navmethod', 'quiz'), get_string('confignavmethod', 'quiz'),
137 QUIZ_NAVMETHOD_FREE
, quiz_get_navigation_options());
138 $setting->set_advanced_flag_options(admin_setting_flag
::ENABLED
, true);
139 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
140 $quizsettings->add($setting);
142 // Shuffle within questions.
143 $setting = new admin_setting_configcheckbox('quiz/shuffleanswers',
144 get_string('shufflewithin', 'quiz'), get_string('configshufflewithin', 'quiz'),
146 $setting->set_advanced_flag_options(admin_setting_flag
::ENABLED
, false);
147 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
148 $quizsettings->add($setting);
150 // Preferred behaviour.
151 $setting = new admin_setting_question_behaviour('quiz/preferredbehaviour',
152 get_string('howquestionsbehave', 'question'), get_string('howquestionsbehave_desc', 'quiz'),
154 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
155 $quizsettings->add($setting);
157 // Can redo completed questions.
158 $setting = new admin_setting_configselect('quiz/canredoquestions',
159 get_string('canredoquestions', 'quiz'), get_string('canredoquestions_desc', 'quiz'),
161 [0 => get_string('no'), 1 => get_string('canredoquestionsyes', 'quiz')]);
162 $setting->set_advanced_flag_options(admin_setting_flag
::ENABLED
, true);
163 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
164 $quizsettings->add($setting);
166 // Each attempt builds on last.
167 $setting = new admin_setting_configcheckbox('quiz/attemptonlast',
168 get_string('eachattemptbuildsonthelast', 'quiz'),
169 get_string('configeachattemptbuildsonthelast', 'quiz'),
171 $setting->set_advanced_flag_options(admin_setting_flag
::ENABLED
, true);
172 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
173 $quizsettings->add($setting);
176 $quizsettings->add(new admin_setting_heading('reviewheading',
177 get_string('reviewoptionsheading', 'quiz'), ''));
178 foreach (review_setting
::fields() as $field => $name) {
179 $default = review_setting
::all_on();
181 if ($field == 'attempt') {
183 } else if ($field == 'overallfeedback') {
184 $default = $default ^ review_setting
::DURING
;
185 $forceduring = false;
187 $quizsettings->add(new review_setting('quiz/review' . $field,
188 $name, '', $default, $forceduring));
191 // Show the user's picture.
192 $setting = new \mod_quiz\admin\
user_image_setting('quiz/showuserpicture',
193 get_string('showuserpicture', 'quiz'), get_string('configshowuserpicture', 'quiz'),
194 ['value' => 0, 'adv' => false], null);
195 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
196 $quizsettings->add($setting);
198 // Decimal places for overall grades.
200 for ($i = 0; $i <= QUIZ_MAX_DECIMAL_OPTION
; $i++
) {
203 $setting = new admin_setting_configselect('quiz/decimalpoints',
204 get_string('decimalplaces', 'quiz'), get_string('configdecimalplaces', 'quiz'),
206 $setting->set_advanced_flag_options(admin_setting_flag
::ENABLED
, false);
207 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
208 $quizsettings->add($setting);
210 // Decimal places for question grades.
211 $options = [-1 => get_string('sameasoverall', 'quiz')];
212 for ($i = 0; $i <= QUIZ_MAX_Q_DECIMAL_OPTION
; $i++
) {
215 $setting = new admin_setting_configselect('quiz/questiondecimalpoints',
216 get_string('decimalplacesquestion', 'quiz'),
217 get_string('configdecimalplacesquestion', 'quiz'),
219 $setting->set_advanced_flag_options(admin_setting_flag
::ENABLED
, false);
220 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
221 $quizsettings->add($setting);
223 // Show blocks during quiz attempts.
224 $setting = new admin_setting_configcheckbox('quiz/showblocks',
225 get_string('showblocks', 'quiz'), get_string('configshowblocks', 'quiz'),
227 $setting->set_advanced_flag_options(admin_setting_flag
::ENABLED
, true);
228 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
229 $quizsettings->add($setting);
232 $setting = new admin_setting_configpasswordunmask('quiz/quizpassword',
233 get_string('requirepassword', 'quiz'), get_string('configrequirepassword', 'quiz'),
235 $setting->set_advanced_flag_options(admin_setting_flag
::ENABLED
, false);
236 $setting->set_required_flag_options(admin_setting_flag
::ENABLED
, false);
237 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
238 $quizsettings->add($setting);
241 $setting = new admin_setting_configtext('quiz/subnet',
242 get_string('requiresubnet', 'quiz'), get_string('configrequiresubnet', 'quiz'),
244 $setting->set_advanced_flag_options(admin_setting_flag
::ENABLED
, true);
245 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
246 $quizsettings->add($setting);
248 // Enforced delay between attempts.
249 $setting = new admin_setting_configduration('quiz/delay1',
250 get_string('delay1st2nd', 'quiz'), get_string('configdelay1st2nd', 'quiz'),
252 $setting->set_advanced_flag_options(admin_setting_flag
::ENABLED
, true);
253 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
254 $quizsettings->add($setting);
255 $setting = new admin_setting_configduration('quiz/delay2',
256 get_string('delaylater', 'quiz'), get_string('configdelaylater', 'quiz'),
258 $setting->set_advanced_flag_options(admin_setting_flag
::ENABLED
, true);
259 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
260 $quizsettings->add($setting);
263 $setting = new \mod_quiz\admin\browser_security_setting
('quiz/browsersecurity',
264 get_string('showinsecurepopup', 'quiz'), get_string('configpopup', 'quiz'),
265 ['value' => '-', 'adv' => true], null);
266 $setting->set_locked_flag_options(admin_setting_flag
::ENABLED
, false);
267 $quizsettings->add($setting);
269 $quizsettings->add(new admin_setting_configtext('quiz/initialnumfeedbacks',
270 get_string('initialnumfeedbacks', 'quiz'), get_string('initialnumfeedbacks_desc', 'quiz'),
273 // Allow user to specify if setting outcomes is an advanced setting.
274 if (!empty($CFG->enableoutcomes
)) {
275 $quizsettings->add(new admin_setting_configcheckbox('quiz/outcomes_adv',
276 get_string('outcomesadvanced', 'quiz'), get_string('configoutcomesadvanced', 'quiz'),
280 // Autosave frequency.
281 $quizsettings->add(new admin_setting_configduration('quiz/autosaveperiod',
282 get_string('autosaveperiod', 'quiz'), get_string('autosaveperiod_desc', 'quiz'), 60, 1));
285 // Now, depending on whether any reports have their own settings page, add
286 // the quiz setting page to the appropriate place in the tree.
287 if (empty($reportsbyname) && empty($rulesbyname)) {
288 $ADMIN->add('modsettings', $quizsettings);
290 $ADMIN->add('modsettings', new admin_category('modsettingsquizcat',
291 get_string('modulename', 'quiz'), $module->is_enabled() === false));
292 $ADMIN->add('modsettingsquizcat', $quizsettings);
294 // Add settings pages for the quiz report subplugins.
295 foreach ($reportsbyname as $strreportname => $report) {
296 $reportname = $report;
298 $settings = new admin_settingpage('modsettingsquizcat'.$reportname,
299 $strreportname, 'moodle/site:config', $module->is_enabled() === false);
300 include($CFG->dirroot
. "/mod/quiz/report/$reportname/settings.php");
301 if (!empty($settings)) {
302 $ADMIN->add('modsettingsquizcat', $settings);
306 // Add settings pages for the quiz access rule subplugins.
307 foreach ($rulesbyname as $strrulename => $rule) {
308 $settings = new admin_settingpage('modsettingsquizcat' . $rule,
309 $strrulename, 'moodle/site:config', $module->is_enabled() === false);
310 include($CFG->dirroot
. "/mod/quiz/accessrule/$rule/settings.php");
311 if (!empty($settings)) {
312 $ADMIN->add('modsettingsquizcat', $settings);
317 $settings = null; // We do not want standard settings link.