ajaxlib: fix unit tests.
[moodle.git] / mod / quiz / settingstree.php
CommitLineData
e2249afe 1<?php // $Id$
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
10require_once($CFG->dirroot . '/mod/quiz/lib.php');
7fb0303d 11require_once($CFG->dirroot . '/mod/quiz/settingslib.php');
e2249afe 12
13// First get a list of quiz reports with there own settings pages. If there none,
14// we use a simpler overall menu structure.
15$reportsbyname = array();
16if ($reports = get_list_of_plugins('mod/quiz/report')) {
17 foreach ($reports as $report) {
18 if (file_exists($CFG->dirroot . "/mod/quiz/report/$report/settings.php")) {
19 $strreportname = get_string($report . 'report', 'quiz_'.$report);
20 // Deal with reports which are lacking the language string
21 if ($strreportname[0] == '[') {
22 $textlib = textlib_get_instance();
23 $strreportname = $textlib->strtotitle($report . ' report');
24 }
25 $reportsbyname[$strreportname] = $report;
26 }
27 }
28 ksort($reportsbyname);
29}
30
31// Create the quiz settings page.
32if (empty($reportsbyname)) {
33 $pagetitle = get_string('modulename', 'quiz');
34} else {
35 $pagetitle = get_string('generalsettings', 'admin');
36}
37$quizsettings = new admin_settingpage('modsettingquiz', $pagetitle, 'moodle/site:config');
38
39// Introductory explanation that all the settings are defaults for the add quiz form.
40$quizsettings->add(new admin_setting_heading('quizintro', '', get_string('configintro', 'quiz')));
41
42// timelimit
7fb0303d 43$quizsettings->add(new admin_setting_text_with_advanced('quiz/timelimit',
e2249afe 44 get_string('timelimit', 'quiz'), get_string('configtimelimit', 'quiz'),
45 array('value' => '0', 'fix' => false), PARAM_INT));
46
47// delay1 and delay2
48$timedelayoptions = array();
49$timedelayoptions[0] = get_string('none');
50$timedelayoptions[1800] = get_string('numminutes', '', 30);
51$timedelayoptions[3600] = get_string('numminutes', '', 60);
52for($i=2; $i<=23; $i++) {
53 $seconds = $i*3600;
54 $timedelayoptions[$seconds] = get_string('numhours', '', $i);
55}
56$timedelayoptions[86400] = get_string('numhours', '', 24);
57for($i=2; $i<=7; $i++) {
58 $seconds = $i*86400;
59 $timedelayoptions[$seconds] = get_string('numdays', '', $i);
60}
7fb0303d 61$quizsettings->add(new admin_setting_combo_with_advanced('quiz/delay1',
e2249afe 62 get_string('delay1', 'quiz'), get_string('configdelay1', 'quiz'),
63 array('value' => 0, 'fix' => false), $timedelayoptions));
7fb0303d 64$quizsettings->add(new admin_setting_combo_with_advanced('quiz/delay2',
e2249afe 65 get_string('delay2', 'quiz'), get_string('configdelay2', 'quiz'),
66 array('value' => 0, 'fix' => false), $timedelayoptions));
67
68// questionsperpage
69$perpage = array();
70$perpage[0] = get_string('never');
71$perpage[1] = get_string('aftereachquestion', 'quiz');
72for ($i = 2; $i <= 50; ++$i) {
73 $perpage[$i] = get_string('afternquestions', 'quiz', $i);
74}
7fb0303d 75$quizsettings->add(new admin_setting_combo_with_advanced('quiz/questionsperpage',
e2249afe 76 get_string('newpageevery', 'quiz'), get_string('confignewpageevery', 'quiz'),
77 array('value' => 1, 'fix' => false), $perpage));
78
79// shufflequestions
7fb0303d 80$quizsettings->add(new admin_setting_yesno_with_advanced('quiz/shufflequestions',
e2249afe 81 get_string('shufflequestions', 'quiz'), get_string('configshufflequestions', 'quiz'),
82 array('value' => 0, 'fix' => false)));
83
84// shuffleanswers
7fb0303d 85$quizsettings->add(new admin_setting_yesno_with_advanced('quiz/shuffleanswers',
e2249afe 86 get_string('shufflewithin', 'quiz'), get_string('configshufflewithin', 'quiz'),
87 array('value' => 1, 'fix' => false)));
88
a733c4b9 89// showuserpicture
90$quizsettings->add(new admin_setting_yesno_with_advanced('quiz/showuserpicture',
91 get_string('showuserpicture', 'quiz'), get_string('configshowuserpicture', 'quiz'),
92 array('value' => 0, 'fix' => false)));
93
e2249afe 94// attempts
95$options = array(get_string('unlimited'));
96for ($i = 1; $i <= 6; $i++) {
97 $options[$i] = $i;
98}
7fb0303d 99$quizsettings->add(new admin_setting_combo_with_advanced('quiz/attempts',
e2249afe 100 get_string('attemptsallowed', 'quiz'), get_string('configattemptsallowed', 'quiz'),
101 array('value' => 0, 'fix' => false), $options));
102
103// attemptonlast
7fb0303d 104$quizsettings->add(new admin_setting_yesno_with_advanced('quiz/attemptonlast',
e2249afe 105 get_string('eachattemptbuildsonthelast', 'quiz'), get_string('configeachattemptbuildsonthelast', 'quiz'),
106 array('value' => 0, 'fix' => false)));
107
108// optionflags
7fb0303d 109$quizsettings->add(new admin_setting_yesno_with_advanced('quiz/optionflags',
e2249afe 110 get_string('adaptive', 'quiz'), get_string('configadaptive', 'quiz'),
111 array('value' => 1, 'fix' => false)));
112
113// maximumgrade
7fb0303d 114$quizsettings->add(new admin_setting_configtext('quiz/maximumgrade',
115 get_string('maximumgrade'), get_string('configmaximumgrade', 'quiz'), 10, PARAM_INT));
e2249afe 116
117// grademethod
7fb0303d 118$quizsettings->add(new admin_setting_combo_with_advanced('quiz/grademethod',
e2249afe 119 get_string('grademethod', 'quiz'), get_string('configgrademethod', 'quiz'),
120 array('value' => QUIZ_GRADEHIGHEST, 'fix' => false), quiz_get_grading_options()));
121
122// penaltyscheme
7fb0303d 123$quizsettings->add(new admin_setting_yesno_with_advanced('quiz/penaltyscheme',
e2249afe 124 get_string('penaltyscheme', 'quiz'), get_string('configpenaltyscheme', 'quiz'),
125 array('value' => 1, 'fix' => false)));
126
127// decimalpoints
128$options = array();
129for ($i = 0; $i <= 5; $i++) {
130 $options[$i] = $i;
131}
7fb0303d 132$quizsettings->add(new admin_setting_combo_with_advanced('quiz/decimalpoints',
e2249afe 133 get_string('decimaldigits', 'quiz'), get_string('configdecimaldigits', 'quiz'),
134 array('value' => 2, 'fix' => false), $options));
135
136// review
7fb0303d 137$quizsettings->add(new admin_setting_quiz_reviewoptions('quiz/review',
e2249afe 138 get_string('reviewoptions', 'quiz'), get_string('configreviewoptions', 'quiz'),
139 array('value' => 0x3fffffff, 'fix' => false)));
140
141// popup
7fb0303d 142$quizsettings->add(new admin_setting_yesno_with_advanced('quiz/popup',
e2249afe 143 get_string('popup', 'quiz'), get_string('configpopup', 'quiz'),
144 array('value' => 0, 'fix' => false)));
145
146// quizpassword
7fb0303d 147$quizsettings->add(new admin_setting_text_with_advanced('quiz/password',
e2249afe 148 get_string('requirepassword', 'quiz'), get_string('configrequirepassword', 'quiz'),
149 array('value' => '', 'fix' => false), PARAM_TEXT));
150
151// subnet
7fb0303d 152$quizsettings->add(new admin_setting_text_with_advanced('quiz/subnet',
e2249afe 153 get_string('requiresubnet', 'quiz'), get_string('configrequiresubnet', 'quiz'),
154 array('value' => '', 'fix' => false), PARAM_TEXT));
155
156/// Now, depending on whether any reports have their own settings page, add
157/// the quiz setting page to the appropriate place in the tree.
158if (empty($reportsbyname)) {
159 $ADMIN->add('modsettings', $quizsettings);
160} else {
161 $ADMIN->add('modsettings', new admin_category('modsettingsquizcat', get_string('modulename', 'quiz'), !$module->visible));
162 $ADMIN->add('modsettingsquizcat', $quizsettings);
163
164/// Add the report pages for the settings.php files in sub directories of mod/quiz/report
165 foreach ($reportsbyname as $strreportname => $report) {
166 $reportname = $report;
167 $settings = new admin_settingpage('modsettingsquizcat'.$reportname, $strreportname, 'moodle/site:config', !$module->visible);
168 if ($ADMIN->fulltree) {
169 include($CFG->dirroot."/mod/quiz/report/$reportname/settings.php");
170 }
171 $ADMIN->add('modsettingsquizcat', $settings);
172 }
173}
174?>