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