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