MDL-20636 Remove © from all PHPdoc comments, and tidy them up a bit.
[moodle.git] / mod / quiz / settings.php
CommitLineData
83192608 1<?php
e2249afe 2/**
3 * settingstree.php - Tells the admin menu that there are sub menu pages to
4 * include for this activity.
5 *
6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
7 * @package quiz
8 */
9
dbf9e4ba
PS
10defined('MOODLE_INTERNAL') || die;
11
e2249afe 12require_once($CFG->dirroot . '/mod/quiz/lib.php');
25302dee 13require_once($CFG->dirroot . '/mod/quiz/locallib.php');
7fb0303d 14require_once($CFG->dirroot . '/mod/quiz/settingslib.php');
e2249afe 15
16// First get a list of quiz reports with there own settings pages. If there none,
17// we use a simpler overall menu structure.
18$reportsbyname = array();
17da2e6f 19if ($reports = get_plugin_list('quiz')) {
20 foreach ($reports as $report => $reportdir) {
21 if (file_exists("$reportdir/settings.php")) {
e2249afe 22 $strreportname = get_string($report . 'report', 'quiz_'.$report);
23 // Deal with reports which are lacking the language string
24 if ($strreportname[0] == '[') {
25 $textlib = textlib_get_instance();
26 $strreportname = $textlib->strtotitle($report . ' report');
27 }
28 $reportsbyname[$strreportname] = $report;
29 }
30 }
31 ksort($reportsbyname);
32}
33
34// Create the quiz settings page.
35if (empty($reportsbyname)) {
36 $pagetitle = get_string('modulename', 'quiz');
37} else {
38 $pagetitle = get_string('generalsettings', 'admin');
39}
40$quizsettings = new admin_settingpage('modsettingquiz', $pagetitle, 'moodle/site:config');
41
42// Introductory explanation that all the settings are defaults for the add quiz form.
43$quizsettings->add(new admin_setting_heading('quizintro', '', get_string('configintro', 'quiz')));
44
84e628a0 45// Time limit
c304d581 46$quizsettings->add(new admin_setting_configtext_with_advanced('quiz/timelimit',
84e628a0 47 get_string('timelimitsec', 'quiz'), get_string('configtimelimitsec', 'quiz'),
e2249afe 48 array('value' => '0', 'fix' => false), PARAM_INT));
49
84e628a0 50// Number of attempts
51$options = array(get_string('unlimited'));
52for ($i = 1; $i <= QUIZ_MAX_ATTEMPT_OPTION; $i++) {
53 $options[$i] = $i;
e2249afe 54}
c304d581 55$quizsettings->add(new admin_setting_configselect_with_advanced('quiz/attempts',
84e628a0 56 get_string('attemptsallowed', 'quiz'), get_string('configattemptsallowed', 'quiz'),
57 array('value' => 0, 'fix' => false), $options));
58
59// Grading method.
c304d581 60$quizsettings->add(new admin_setting_configselect_with_advanced('quiz/grademethod',
84e628a0 61 get_string('grademethod', 'quiz'), get_string('configgrademethod', 'quiz'),
62 array('value' => QUIZ_GRADEHIGHEST, 'fix' => false), quiz_get_grading_options()));
63
64// Maximum grade
65$quizsettings->add(new admin_setting_configtext('quiz/maximumgrade',
66 get_string('maximumgrade'), get_string('configmaximumgrade', 'quiz'), 10, PARAM_INT));
67
68// Shuffle questions
adf8f3f9 69$quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/shufflequestions',
84e628a0 70 get_string('shufflequestions', 'quiz'), get_string('configshufflequestions', 'quiz'),
adf8f3f9 71 array('value' => 0, 'adv' => false)));
84e628a0 72
73// Questions per page
e2249afe 74$perpage = array();
75$perpage[0] = get_string('never');
76$perpage[1] = get_string('aftereachquestion', 'quiz');
84e628a0 77for ($i = 2; $i <= QUIZ_MAX_QPP_OPTION; ++$i) {
e2249afe 78 $perpage[$i] = get_string('afternquestions', 'quiz', $i);
79}
c304d581 80$quizsettings->add(new admin_setting_configselect_with_advanced('quiz/questionsperpage',
e2249afe 81 get_string('newpageevery', 'quiz'), get_string('confignewpageevery', 'quiz'),
82 array('value' => 1, 'fix' => false), $perpage));
83
84e628a0 84// Shuffle within questions
adf8f3f9 85$quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/shuffleanswers',
e2249afe 86 get_string('shufflewithin', 'quiz'), get_string('configshufflewithin', 'quiz'),
adf8f3f9 87 array('value' => 1, 'adv' => false)));
e2249afe 88
84e628a0 89// Adaptive mode.
adf8f3f9 90$quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/optionflags',
e2249afe 91 get_string('adaptive', 'quiz'), get_string('configadaptive', 'quiz'),
adf8f3f9 92 array('value' => 1, 'adv' => false)));
e2249afe 93
84e628a0 94// Apply penalties.
adf8f3f9 95$quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/penaltyscheme',
e2249afe 96 get_string('penaltyscheme', 'quiz'), get_string('configpenaltyscheme', 'quiz'),
adf8f3f9 97 array('value' => 1, 'adv' => true)));
84e628a0 98
99// Each attempt builds on last.
adf8f3f9 100$quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/attemptonlast',
84e628a0 101 get_string('eachattemptbuildsonthelast', 'quiz'), get_string('configeachattemptbuildsonthelast', 'quiz'),
adf8f3f9 102 array('value' => 0, 'adv' => true)));
84e628a0 103
14936199
TH
104// Review options.
105$quizsettings->add(new admin_setting_heading('reviewheading', get_string('reviewoptionsheading', 'quiz'), ''));
106foreach (mod_quiz_admin_review_setting::fields() as $field => $name) {
107 $default = mod_quiz_admin_review_setting::all_on();
108 $forceduring = null;
109 if ($field == 'attempt') {
110 $forceduring = true;
111 } else if ($field == 'overallfeedback') {
112 $default = $default ^ mod_quiz_admin_review_setting::DURING;
113 $forceduring = false;
114 }
115 $quizsettings->add(new mod_quiz_admin_review_setting('quiz/review' . $field,
116 $name, '', $default, $forceduring));
117}
84e628a0 118
119// Show the user's picture
adf8f3f9 120$quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/showuserpicture',
84e628a0 121 get_string('showuserpicture', 'quiz'), get_string('configshowuserpicture', 'quiz'),
adf8f3f9 122 array('value' => 0, 'adv' => false)));
e2249afe 123
84e628a0 124// Decimal places for overall grades.
e2249afe 125$options = array();
84e628a0 126for ($i = 0; $i <= QUIZ_MAX_DECIMAL_OPTION; $i++) {
e2249afe 127 $options[$i] = $i;
128}
c304d581 129$quizsettings->add(new admin_setting_configselect_with_advanced('quiz/decimalpoints',
84e628a0 130 get_string('decimalplaces', 'quiz'), get_string('configdecimalplaces', 'quiz'),
e2249afe 131 array('value' => 2, 'fix' => false), $options));
132
84e628a0 133// Decimal places for question grades.
134$options = array(-1 => get_string('sameasoverall', 'quiz'));
135for ($i = 0; $i <= QUIZ_MAX_Q_DECIMAL_OPTION; $i++) {
136 $options[$i] = $i;
137}
c304d581 138$quizsettings->add(new admin_setting_configselect_with_advanced('quiz/questiondecimalpoints',
84e628a0 139 get_string('decimalplacesquestion', 'quiz'), get_string('configdecimalplacesquestion', 'quiz'),
140 array('value' => -1, 'fix' => true), $options));
e2249afe 141
56ed242b
SH
142// Show blocks during quiz attempts
143$quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/showblocks',
144 get_string('showblocks', 'quiz'), get_string('configshowblocks', 'quiz'),
145 array('value' => 0, 'adv' => true)));
146
84e628a0 147// Password.
c304d581 148$quizsettings->add(new admin_setting_configtext_with_advanced('quiz/password',
e2249afe 149 get_string('requirepassword', 'quiz'), get_string('configrequirepassword', 'quiz'),
84e628a0 150 array('value' => '', 'fix' => true), PARAM_TEXT));
e2249afe 151
84e628a0 152// IP restrictions.
c304d581 153$quizsettings->add(new admin_setting_configtext_with_advanced('quiz/subnet',
e2249afe 154 get_string('requiresubnet', 'quiz'), get_string('configrequiresubnet', 'quiz'),
84e628a0 155 array('value' => '', 'fix' => true), PARAM_TEXT));
156
157// Enforced delay between attempts.
c304d581 158$quizsettings->add(new admin_setting_configtext_with_advanced('quiz/delay1',
84e628a0 159 get_string('delay1st2nd', 'quiz'), get_string('configdelay1st2nd', 'quiz'),
160 array('value' => 0, 'fix' => true), PARAM_INTEGER));
c304d581 161$quizsettings->add(new admin_setting_configtext_with_advanced('quiz/delay2',
84e628a0 162 get_string('delaylater', 'quiz'), get_string('configdelaylater', 'quiz'),
163 array('value' => 0, 'fix' => true), PARAM_INTEGER));
164
165// 'Secure' window.
adf8f3f9 166$quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/popup',
84e628a0 167 get_string('showinsecurepopup', 'quiz'), get_string('configpopup', 'quiz'),
adf8f3f9 168 array('value' => 0, 'adv' => true)));
e2249afe 169
170/// Now, depending on whether any reports have their own settings page, add
171/// the quiz setting page to the appropriate place in the tree.
172if (empty($reportsbyname)) {
173 $ADMIN->add('modsettings', $quizsettings);
174} else {
175 $ADMIN->add('modsettings', new admin_category('modsettingsquizcat', get_string('modulename', 'quiz'), !$module->visible));
176 $ADMIN->add('modsettingsquizcat', $quizsettings);
177
178/// Add the report pages for the settings.php files in sub directories of mod/quiz/report
179 foreach ($reportsbyname as $strreportname => $report) {
180 $reportname = $report;
dbf9e4ba 181
e2249afe 182 $settings = new admin_settingpage('modsettingsquizcat'.$reportname, $strreportname, 'moodle/site:config', !$module->visible);
183 if ($ADMIN->fulltree) {
184 include($CFG->dirroot."/mod/quiz/report/$reportname/settings.php");
185 }
186 $ADMIN->add('modsettingsquizcat', $settings);
187 }
188}
dbf9e4ba
PS
189
190$settings = NULL; // we do not want standard settings link