MDL-21695 Removing legacy help file, has been replaced by string
[moodle.git] / mod / quiz / mod_form.php
CommitLineData
83192608 1<?php
a23f0aaf 2
84e628a0 3///////////////////////////////////////////////////////////////////////////
4// //
5// NOTICE OF COPYRIGHT //
6// //
7// Moodle - Modular Object-Oriented Dynamic Learning Environment //
8// http://moodle.org //
9// //
10// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
11// //
12// This program is free software; you can redistribute it and/or modify //
13// it under the terms of the GNU General Public License as published by //
14// the Free Software Foundation; either version 2 of the License, or //
15// (at your option) any later version. //
16// //
17// This program is distributed in the hope that it will be useful, //
18// but WITHOUT ANY WARRANTY; without even the implied warranty of //
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20// GNU General Public License for more details: //
21// //
22// http://www.gnu.org/copyleft/gpl.html //
23// //
24///////////////////////////////////////////////////////////////////////////
25
bfebaf64
MD
26if (!defined('MOODLE_INTERNAL')) {
27 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
28}
29
84e628a0 30require_once($CFG->dirroot . '/course/moodleform_mod.php');
31require_once($CFG->dirroot . '/mod/quiz/locallib.php');
32
33/**
34 * Settings form for the quiz module.
3268cf99 35 *
84e628a0 36 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
37 * @package quiz
38 */
f07b9627 39class mod_quiz_mod_form extends moodleform_mod {
a23f0aaf 40 var $_feedbacks;
41
2ee60b49 42 function definition() {
a23f0aaf 43
25ddb7ef 44 global $COURSE, $CFG, $DB, $PAGE;
e2249afe 45 $quizconfig = get_config('quiz');
2ee60b49 46 $mform =& $this->_form;
a23f0aaf 47
a23f0aaf 48//-------------------------------------------------------------------------------
49 $mform->addElement('header', 'general', get_string('general', 'form'));
50
84e628a0 51 /// Name.
26de8d35 52 $mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
8eb1d25f 53 if (!empty($CFG->formatstringstriptags)) {
54 $mform->setType('name', PARAM_TEXT);
55 } else {
56 $mform->setType('name', PARAM_CLEAN);
57 }
99ebfea2 58 $mform->addRule('name', null, 'required', null, 'client');
a23f0aaf 59
84e628a0 60 /// Introduction.
0cd1affc 61 $this->add_intro_editor(false, get_string('introduction', 'quiz'));
a23f0aaf 62
84e628a0 63 /// Open and close dates.
64 $mform->addElement('date_time_selector', 'timeopen', get_string('quizopen', 'quiz'), array('optional' => true));
8289cdf3 65 $mform->setHelpButton('timeopen', array('timeopen', get_string('quizopen', 'quiz'), 'quiz'));
a23f0aaf 66
84e628a0 67 $mform->addElement('date_time_selector', 'timeclose', get_string('quizclose', 'quiz'), array('optional' => true));
8289cdf3 68 $mform->setHelpButton('timeclose', array('timeopen', get_string('quizclose', 'quiz'), 'quiz'));
a23f0aaf 69
84e628a0 70 /// Time limit.
71 $mform->addElement('duration', 'timelimit', get_string('timelimit', 'quiz'), array('optional' => true));
72 $mform->setHelpButton('timelimit', array('timelimit', get_string('quiztimer','quiz'), 'quiz'));
adf8f3f9 73 $mform->setAdvanced('timelimit', $quizconfig->timelimit_adv);
e2249afe 74 $mform->setDefault('timelimit', $quizconfig->timelimit);
a23f0aaf 75
84e628a0 76 /// Number of attempts.
77 $attemptoptions = array('0' => get_string('unlimited'));
78 for ($i = 1; $i <= QUIZ_MAX_ATTEMPT_OPTION; $i++) {
79 $attemptoptions[$i] = $i;
a23f0aaf 80 }
84e628a0 81 $mform->addElement('select', 'attempts', get_string('attemptsallowed', 'quiz'), $attemptoptions);
82 $mform->setHelpButton('attempts', array('attempts', get_string('attemptsallowed','quiz'), 'quiz'));
adf8f3f9 83 $mform->setAdvanced('attempts', $quizconfig->attempts_adv);
84e628a0 84 $mform->setDefault('attempts', $quizconfig->attempts);
a23f0aaf 85
84e628a0 86 /// Grading method.
87 $mform->addElement('select', 'grademethod', get_string('grademethod', 'quiz'), quiz_get_grading_options());
88 $mform->setHelpButton('grademethod', array('grademethod', get_string('grademethod','quiz'), 'quiz'));
adf8f3f9 89 $mform->setAdvanced('grademethod', $quizconfig->grademethod_adv);
84e628a0 90 $mform->setDefault('grademethod', $quizconfig->grademethod);
91 $mform->disabledIf('grademethod', 'attempts', 'eq', 1);
92
a23f0aaf 93//-------------------------------------------------------------------------------
84e628a0 94 $mform->addElement('header', 'layouthdr', get_string('layout', 'quiz'));
95
96 /// Shuffle questions.
eeab18f0 97 $shuffleoptions = array(0 => get_string('asshownoneditscreen', 'quiz'), 1 => get_string('shuffledrandomly', 'quiz'));
98 $mform->addElement('select', 'shufflequestions', get_string('questionorder', 'quiz'), $shuffleoptions, array('id' => 'id_shufflequestions'));
84e628a0 99 $mform->setHelpButton('shufflequestions', array('shufflequestions', get_string('shufflequestions','quiz'), 'quiz'));
adf8f3f9 100 $mform->setAdvanced('shufflequestions', $quizconfig->shufflequestions_adv);
84e628a0 101 $mform->setDefault('shufflequestions', $quizconfig->shufflequestions);
102
103 /// Questions per page.
eeab18f0 104 $pageoptions = array();
105 $pageoptions[0] = get_string('neverallononepage', 'quiz');
106 $pageoptions[1] = get_string('everyquestion', 'quiz');
84e628a0 107 for ($i = 2; $i <= QUIZ_MAX_QPP_OPTION; ++$i) {
eeab18f0 108 $pageoptions[$i] = get_string('everynquestions', 'quiz', $i);
a23f0aaf 109 }
eeab18f0 110
111 $pagegroup = array();
112 $pagegroup[] = &$mform->createElement('select', 'questionsperpage', get_string('newpage', 'quiz'), $pageoptions, array('id' => 'id_questionsperpage'));
e2249afe 113 $mform->setDefault('questionsperpage', $quizconfig->questionsperpage);
a23f0aaf 114
eeab18f0 115 if (!empty($this->_cm)) {
116 $pagegroup[] = &$mform->createElement('checkbox', 'repaginatenow', '', get_string('repaginatenow', 'quiz'), array('id' => 'id_repaginatenow'));
117 $mform->disabledIf('repaginatenow', 'shufflequestions', 'eq', 1);
f44b10ed 118 $PAGE->requires->yui2_lib('event');
9dec75db 119 $PAGE->requires->js('/mod/quiz/edit.js');
eeab18f0 120 }
121
122 $mform->addGroup($pagegroup, 'questionsperpagegrp', get_string('newpage', 'quiz'), null, false);
123 $mform->setHelpButton('questionsperpagegrp', array('questionsperpage', get_string('newpageevery', 'quiz'), 'quiz'));
adf8f3f9 124 $mform->setAdvanced('questionsperpagegrp', $quizconfig->questionsperpage_adv);
eeab18f0 125
84e628a0 126//-------------------------------------------------------------------------------
127 $mform->addElement('header', 'interactionhdr', get_string('questionbehaviour', 'quiz'));
a23f0aaf 128
84e628a0 129 /// Shuffle within questions.
130 $mform->addElement('selectyesno', 'shuffleanswers', get_string('shufflewithin', 'quiz'));
131 $mform->setHelpButton('shuffleanswers', array('shufflewithin', get_string('shufflewithin','quiz'), 'quiz'));
adf8f3f9 132 $mform->setAdvanced('shuffleanswers', $quizconfig->shuffleanswers_adv);
e2249afe 133 $mform->setDefault('shuffleanswers', $quizconfig->shuffleanswers);
a23f0aaf 134
84e628a0 135 /// Adaptive mode.
136 $mform->addElement('selectyesno', 'adaptive', get_string('adaptive', 'quiz'));
137 $mform->setHelpButton('adaptive', array('adaptive', get_string('adaptive','quiz'), 'quiz'));
adf8f3f9 138 $mform->setAdvanced('adaptive', $quizconfig->optionflags_adv);
e2249afe 139 $mform->setDefault('adaptive', $quizconfig->optionflags & QUESTION_ADAPTIVE);
a23f0aaf 140
84e628a0 141 /// Apply penalties.
142 $mform->addElement('selectyesno', 'penaltyscheme', get_string('penaltyscheme', 'quiz'));
143 $mform->setHelpButton('penaltyscheme', array('penaltyscheme', get_string('penaltyscheme','quiz'), 'quiz'));
adf8f3f9 144 $mform->setAdvanced('penaltyscheme', $quizconfig->penaltyscheme_adv);
e2249afe 145 $mform->setDefault('penaltyscheme', $quizconfig->penaltyscheme);
84e628a0 146 $mform->disabledIf('penaltyscheme', 'adaptive', 'neq', 1);
a23f0aaf 147
84e628a0 148 /// Each attempt builds on last.
149 $mform->addElement('selectyesno', 'attemptonlast', get_string('eachattemptbuildsonthelast', 'quiz'));
150 $mform->setHelpButton('attemptonlast', array('repeatattempts', get_string('eachattemptbuildsonthelast', 'quiz'), 'quiz'));
adf8f3f9 151 $mform->setAdvanced('attemptonlast', $quizconfig->attemptonlast_adv);
84e628a0 152 $mform->setDefault('attemptonlast', $quizconfig->attemptonlast);
153 $mform->disabledIf('attemptonlast', 'attempts', 'eq', 1);
a23f0aaf 154
155//-------------------------------------------------------------------------------
e2833e87 156 $mform->addElement('header', 'reviewoptionshdr', get_string('reviewoptionsheading', 'quiz'));
157 $mform->setHelpButton('reviewoptionshdr', array('reviewoptions', get_string('reviewoptionsheading','quiz'), 'quiz'));
adf8f3f9 158 $mform->setAdvanced('reviewoptionshdr', $quizconfig->review_adv);
a23f0aaf 159
84e628a0 160 /// Review options.
2ee60b49 161 $immediatelyoptionsgrp=array();
a23f0aaf 162 $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'responsesimmediately', '', get_string('responses', 'quiz'));
a23f0aaf 163 $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'answersimmediately', '', get_string('answers', 'quiz'));
00719c02 164 $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackimmediately', '', get_string('feedback', 'quiz'));
a23f0aaf 165 $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackimmediately', '', get_string('generalfeedback', 'quiz'));
00719c02 166 $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'scoreimmediately', '', get_string('scores', 'quiz'));
167 $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'overallfeedbackimmediately', '', get_string('overallfeedback', 'quiz'));
84e628a0 168 $mform->addGroup($immediatelyoptionsgrp, 'immediatelyoptionsgrp', get_string('reviewimmediately', 'quiz'), null, false);
e2249afe 169 $mform->setDefault('responsesimmediately', $quizconfig->review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_IMMEDIATELY);
170 $mform->setDefault('answersimmediately', $quizconfig->review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_IMMEDIATELY);
171 $mform->setDefault('feedbackimmediately', $quizconfig->review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_IMMEDIATELY);
172 $mform->setDefault('generalfeedbackimmediately', $quizconfig->review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_IMMEDIATELY);
173 $mform->setDefault('scoreimmediately', $quizconfig->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_IMMEDIATELY);
174 $mform->setDefault('overallfeedbackimmediately', $quizconfig->review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_IMMEDIATELY);
a23f0aaf 175
2ee60b49 176 $openoptionsgrp=array();
a23f0aaf 177 $openoptionsgrp[] = &$mform->createElement('checkbox', 'responsesopen', '', get_string('responses', 'quiz'));
a23f0aaf 178 $openoptionsgrp[] = &$mform->createElement('checkbox', 'answersopen', '', get_string('answers', 'quiz'));
00719c02 179 $openoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackopen', '', get_string('feedback', 'quiz'));
a23f0aaf 180 $openoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackopen', '', get_string('generalfeedback', 'quiz'));
00719c02 181 $openoptionsgrp[] = &$mform->createElement('checkbox', 'scoreopen', '', get_string('scores', 'quiz'));
182 $openoptionsgrp[] = &$mform->createElement('checkbox', 'overallfeedbackopen', '', get_string('overallfeedback', 'quiz'));
84e628a0 183 $mform->addGroup($openoptionsgrp, 'openoptionsgrp', get_string('reviewopen', 'quiz'), array(' '), false);
e2249afe 184 $mform->setDefault('responsesopen', $quizconfig->review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_OPEN);
185 $mform->setDefault('answersopen', $quizconfig->review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_OPEN);
186 $mform->setDefault('feedbackopen', $quizconfig->review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_OPEN);
187 $mform->setDefault('generalfeedbackopen', $quizconfig->review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_OPEN);
188 $mform->setDefault('scoreopen', $quizconfig->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_OPEN);
189 $mform->setDefault('overallfeedbackopen', $quizconfig->review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_OPEN);
a23f0aaf 190
2ee60b49 191 $closedoptionsgrp=array();
a23f0aaf 192 $closedoptionsgrp[] = &$mform->createElement('checkbox', 'responsesclosed', '', get_string('responses', 'quiz'));
a23f0aaf 193 $closedoptionsgrp[] = &$mform->createElement('checkbox', 'answersclosed', '', get_string('answers', 'quiz'));
00719c02 194 $closedoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackclosed', '', get_string('feedback', 'quiz'));
a23f0aaf 195 $closedoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackclosed', '', get_string('generalfeedback', 'quiz'));
00719c02 196 $closedoptionsgrp[] = &$mform->createElement('checkbox', 'scoreclosed', '', get_string('scores', 'quiz'));
197 $closedoptionsgrp[] = &$mform->createElement('checkbox', 'overallfeedbackclosed', '', get_string('overallfeedback', 'quiz'));
84e628a0 198 $mform->addGroup($closedoptionsgrp, 'closedoptionsgrp', get_string('reviewclosed', 'quiz'), array(' '), false);
e2249afe 199 $mform->setDefault('responsesclosed', $quizconfig->review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_CLOSED);
200 $mform->setDefault('answersclosed', $quizconfig->review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_CLOSED);
201 $mform->setDefault('feedbackclosed', $quizconfig->review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_CLOSED);
202 $mform->setDefault('generalfeedbackclosed', $quizconfig->review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_CLOSED);
203 $mform->setDefault('scoreclosed', $quizconfig->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_CLOSED);
204 $mform->setDefault('overallfeedbackclosed', $quizconfig->review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_CLOSED);
84e628a0 205 $mform->disabledIf('closedoptionsgrp', 'timeclose[enabled]');
a23f0aaf 206
207//-------------------------------------------------------------------------------
84e628a0 208 $mform->addElement('header', 'display', get_string('display', 'form'));
a23f0aaf 209
84e628a0 210 /// Show user picture.
211 $mform->addElement('selectyesno', 'showuserpicture', get_string('showuserpicture', 'quiz'));
212 $mform->setHelpButton('showuserpicture', array('showuserpicture', get_string('showuserpicture', 'quiz'), 'quiz'));
adf8f3f9 213 $mform->setAdvanced('showuserpicture', $quizconfig->showuserpicture_adv);
84e628a0 214 $mform->setDefault('showuserpicture', $quizconfig->showuserpicture);
215
216 /// Overall decimal points.
217 $options = array();
218 for ($i = 0; $i <= QUIZ_MAX_DECIMAL_OPTION; $i++) {
219 $options[$i] = $i;
220 }
221 $mform->addElement('select', 'decimalpoints', get_string('decimalplaces', 'quiz'), $options);
222 $mform->setHelpButton('decimalpoints', array('decimalpoints', get_string('decimalplaces','quiz'), 'quiz'));
adf8f3f9 223 $mform->setAdvanced('decimalpoints', $quizconfig->decimalpoints_adv);
84e628a0 224 $mform->setDefault('decimalpoints', $quizconfig->decimalpoints);
a23f0aaf 225
84e628a0 226 /// Question decimal points.
227 $options = array(-1 => get_string('sameasoverall', 'quiz'));
228 for ($i = 0; $i <= QUIZ_MAX_Q_DECIMAL_OPTION; $i++) {
229 $options[$i] = $i;
230 }
231 $mform->addElement('select', 'questiondecimalpoints', get_string('decimalplacesquestion', 'quiz'), $options);
232 $mform->setHelpButton('questiondecimalpoints', array('decimalplacesquestion', get_string('decimalplacesquestion','quiz'), 'quiz'));
adf8f3f9 233 $mform->setAdvanced('questiondecimalpoints', $quizconfig->questiondecimalpoints_adv);
84e628a0 234 $mform->setDefault('questiondecimalpoints', $quizconfig->questiondecimalpoints);
235
56ed242b
SH
236 // Show blocks during quiz attempt
237 $mform->addElement('selectyesno', 'showblocks', get_string('showblocks', 'quiz'));
238 $mform->setHelpButton('showblocks', array('showblocks', get_string('showblocks', 'quiz'), 'quiz'));
239 $mform->setAdvanced('showblocks', $quizconfig->showblocks_adv);
240 $mform->setDefault('showblocks', $quizconfig->showblocks);
241
84e628a0 242//-------------------------------------------------------------------------------
243 $mform->addElement('header', 'security', get_string('extraattemptrestrictions', 'quiz'));
244
245 /// Enforced time delay between quiz attempts.
246 $mform->addElement('passwordunmask', 'quizpassword', get_string('requirepassword', 'quiz'));
2ee60b49 247 $mform->setType('quizpassword', PARAM_TEXT);
84e628a0 248 $mform->setHelpButton('quizpassword', array('requirepassword', get_string('requirepassword', 'quiz'), 'quiz'));
adf8f3f9 249 $mform->setAdvanced('quizpassword', $quizconfig->password_adv);
e2249afe 250 $mform->setDefault('quizpassword', $quizconfig->password);
a23f0aaf 251
84e628a0 252 /// IP address.
253 $mform->addElement('text', 'subnet', get_string('requiresubnet', 'quiz'));
2ee60b49 254 $mform->setType('subnet', PARAM_TEXT);
84e628a0 255 $mform->setHelpButton('subnet', array('requiresubnet', get_string('requiresubnet', 'quiz'), 'quiz'));
adf8f3f9 256 $mform->setAdvanced('subnet', $quizconfig->subnet_adv);
e2249afe 257 $mform->setDefault('subnet', $quizconfig->subnet);
a23f0aaf 258
84e628a0 259 /// Enforced time delay between quiz attempts.
260 $mform->addElement('duration', 'delay1', get_string('delay1st2nd', 'quiz'), array('optional' => true));
261 $mform->setHelpButton('delay1', array('timedelay1', get_string('delay1st2nd', 'quiz'), 'quiz'));
adf8f3f9 262 $mform->setAdvanced('delay1', $quizconfig->delay1_adv);
84e628a0 263 $mform->setDefault('delay1', $quizconfig->delay1);
264 $mform->disabledIf('delay1', 'attempts', 'eq', 1);
265
266 $mform->addElement('duration', 'delay2', get_string('delaylater', 'quiz'), array('optional' => true));
267 $mform->setHelpButton('delay2', array('timedelay2', get_string('delaylater', 'quiz'), 'quiz'));
adf8f3f9 268 $mform->setAdvanced('delay2', $quizconfig->delay2_adv);
84e628a0 269 $mform->setDefault('delay2', $quizconfig->delay2);
270 $mform->disabledIf('delay2', 'attempts', 'eq', 1);
271 $mform->disabledIf('delay2', 'attempts', 'eq', 2);
272
273 /// 'Secure' window.
7d4dfc48 274 $options = array(
275 0 => get_string('none', 'quiz'),
276 1 => get_string('popupwithjavascriptsupport', 'quiz'));
05d5801a 277 if (!empty($CFG->enablesafebrowserintegration)) {
7d4dfc48 278 $options[2] = get_string('requiresafeexambrowser', 'quiz');
279 }
280 $mform->addElement('select', 'popup', get_string('browsersecurity', 'quiz'), $options);
281 $mform->setHelpButton('popup', array('browsersecurity', get_string('browsersecurity', 'quiz'), 'quiz'));
adf8f3f9 282 $mform->setAdvanced('popup', $quizconfig->popup_adv);
84e628a0 283 $mform->setDefault('popup', $quizconfig->popup);
284
a23f0aaf 285//-------------------------------------------------------------------------------
08224df1 286 $mform->addElement('header', 'overallfeedbackhdr', get_string('overallfeedback', 'quiz'));
2ee60b49 287 $mform->setHelpButton('overallfeedbackhdr', array('overallfeedback', get_string('overallfeedback', 'quiz'), 'quiz'));
a23f0aaf 288
e0b7cfcb 289 $mform->addElement('hidden', 'grade', $quizconfig->maximumgrade);
d18e0fe6 290 $mform->setType('grade', PARAM_RAW);
e0b7cfcb 291 if (empty($this->_cm)) {
292 $needwarning = $quizconfig->maximumgrade == 0;
293 } else {
2f5f73d0 294 $quizgrade = $DB->get_field('quiz', 'grade', array('id' => $this->_instance));
295 $needwarning = $quizgrade == 0;
e0b7cfcb 296 }
297 if ($needwarning) {
298 $mform->addElement('static', 'nogradewarning', '', get_string('nogradewarning', 'quiz'));
299 }
300
2ee60b49 301 $mform->addElement('static', 'gradeboundarystatic1', get_string('gradeboundary', 'quiz'), '100%');
a23f0aaf 302
e0b7cfcb 303 $repeatarray = array();
a462602a 304 $repeatarray[] = &MoodleQuickForm::createElement('text', 'feedbacktext', get_string('feedback', 'quiz'), array('size' => 50));
e0b7cfcb 305 $mform->setType('feedbacktext', PARAM_RAW);
a462602a 306 $repeatarray[] = &MoodleQuickForm::createElement('text', 'feedbackboundaries', get_string('gradeboundary', 'quiz'), array('size' => 10));
e0b7cfcb 307 $mform->setType('feedbackboundaries', PARAM_NOTAGS);
a23f0aaf 308
309 if (!empty($this->_instance)) {
c18269c7 310 $this->_feedbacks = $DB->get_records('quiz_feedback', array('quizid'=>$this->_instance), 'mingrade DESC');
a23f0aaf 311 } else {
312 $this->_feedbacks = array();
313 }
314 $numfeedbacks = max(count($this->_feedbacks) * 1.5, 5);
ebff6e2c 315
84e628a0 316 $nextel=$this->repeat_elements($repeatarray, $numfeedbacks - 1,
6f3b54c8 317 array(), 'boundary_repeats', 'boundary_add_fields', 3,
318 get_string('addmoreoverallfeedbacks', 'quiz'), true);
a23f0aaf 319
e0b7cfcb 320 // Put some extra elements in before the button
a462602a 321 $insertEl = &MoodleQuickForm::createElement('text', "feedbacktext[$nextel]", get_string('feedback', 'quiz'), array('size' => 50));
a23f0aaf 322 $mform->insertElementBefore($insertEl, 'boundary_add_fields');
a23f0aaf 323
324 $insertEl = &MoodleQuickForm::createElement('static', 'gradeboundarystatic2', get_string('gradeboundary', 'quiz'), '0%');
325 $mform->insertElementBefore($insertEl, 'boundary_add_fields');
326
e0b7cfcb 327 // Add the disabledif rules. We cannot do this using the $repeatoptions parameter to
328 // repeat_elements becuase we don't want to dissable the first feedbacktext.
329 for ($i = 0; $i < $nextel; $i++) {
330 $mform->disabledIf('feedbackboundaries[' . $i . ']', 'grade', 'eq', 0);
331 $mform->disabledIf('feedbacktext[' . ($i + 1) . ']', 'grade', 'eq', 0);
332 }
333
84e628a0 334//-------------------------------------------------------------------------------
42f103be 335 $this->standard_coursemodule_elements();
84e628a0 336
a23f0aaf 337//-------------------------------------------------------------------------------
338 // buttons
339 $this->add_action_buttons();
2ee60b49 340 }
a23f0aaf 341
2ee60b49 342 function data_preprocessing(&$default_values){
e0b7cfcb 343 if (isset($default_values['grade'])) {
344 $default_values['grade'] = $default_values['grade'] + 0; // Convert to a real number, so we don't get 0.0000.
345 }
346
a23f0aaf 347 if (count($this->_feedbacks)) {
348 $key = 0;
349 foreach ($this->_feedbacks as $feedback){
350 $default_values['feedbacktext['.$key.']'] = $feedback->feedbacktext;
351 if ($feedback->mingrade > 0) {
352 $default_values['feedbackboundaries['.$key.']'] = (100.0 * $feedback->mingrade / $default_values['grade']) . '%';
353 }
354 $key++;
355 }
a23f0aaf 356 }
298daa21 357
358 if (isset($default_values['timelimit'])) {
359 $default_values['timelimitenable'] = $default_values['timelimit'] > 0;
a23f0aaf 360 }
361
362 if (isset($default_values['review'])){
363 $review = (int)$default_values['review'];
364 unset($default_values['review']);
365
366 $default_values['responsesimmediately'] = $review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_IMMEDIATELY;
a23f0aaf 367 $default_values['answersimmediately'] = $review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_IMMEDIATELY;
00719c02 368 $default_values['feedbackimmediately'] = $review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_IMMEDIATELY;
a23f0aaf 369 $default_values['generalfeedbackimmediately'] = $review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_IMMEDIATELY;
00719c02 370 $default_values['scoreimmediately'] = $review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_IMMEDIATELY;
371 $default_values['overallfeedbackimmediately'] = $review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_IMMEDIATELY;
a23f0aaf 372
373 $default_values['responsesopen'] = $review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_OPEN;
a23f0aaf 374 $default_values['answersopen'] = $review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_OPEN;
00719c02 375 $default_values['feedbackopen'] = $review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_OPEN;
a23f0aaf 376 $default_values['generalfeedbackopen'] = $review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_OPEN;
00719c02 377 $default_values['scoreopen'] = $review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_OPEN;
378 $default_values['overallfeedbackopen'] = $review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_OPEN;
a23f0aaf 379
380 $default_values['responsesclosed'] = $review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_CLOSED;
a23f0aaf 381 $default_values['answersclosed'] = $review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_CLOSED;
00719c02 382 $default_values['feedbackclosed'] = $review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_CLOSED;
a23f0aaf 383 $default_values['generalfeedbackclosed'] = $review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_CLOSED;
00719c02 384 $default_values['scoreclosed'] = $review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_CLOSED;
385 $default_values['overallfeedbackclosed'] = $review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_CLOSED;
a23f0aaf 386 }
387
388 if (isset($default_values['optionflags'])){
389 $default_values['adaptive'] = $default_values['optionflags'] & QUESTION_ADAPTIVE;
390 unset($default_values['optionflags']);
391 }
ab0a8ff2 392
393 // Password field - different in form to stop browsers that remember passwords
394 // getting confused.
2ee60b49 395 if (isset($default_values['password'])) {
ab0a8ff2 396 $default_values['quizpassword'] = $default_values['password'];
397 unset($default_values['password']);
398 }
2ee60b49 399 }
a23f0aaf 400
a78890d5 401 function validation($data, $files) {
402 $errors = parent::validation($data, $files);
60243313 403
a23f0aaf 404 // Check open and close times are consistent.
405 if ($data['timeopen'] != 0 && $data['timeclose'] != 0 && $data['timeclose'] < $data['timeopen']) {
406 $errors['timeclose'] = get_string('closebeforeopen', 'quiz');
407 }
408
409 // Check the boundary value is a number or a percentage, and in range.
410 $i = 0;
411 while (!empty($data['feedbackboundaries'][$i] )) {
412 $boundary = trim($data['feedbackboundaries'][$i]);
413 if (strlen($boundary) > 0 && $boundary[strlen($boundary) - 1] == '%') {
414 $boundary = trim(substr($boundary, 0, -1));
415 if (is_numeric($boundary)) {
416 $boundary = $boundary * $data['grade'] / 100.0;
417 } else {
418 $errors["feedbackboundaries[$i]"] = get_string('feedbackerrorboundaryformat', 'quiz', $i + 1);
419 }
420 }
421 if (is_numeric($boundary) && $boundary <= 0 || $boundary >= $data['grade'] ) {
422 $errors["feedbackboundaries[$i]"] = get_string('feedbackerrorboundaryoutofrange', 'quiz', $i + 1);
423 }
424 if (is_numeric($boundary) && $i > 0 && $boundary >= $data['feedbackboundaries'][$i - 1]) {
425 $errors["feedbackboundaries[$i]"] = get_string('feedbackerrororder', 'quiz', $i + 1);
426 }
427 $data['feedbackboundaries'][$i] = $boundary;
428 $i += 1;
429 }
430 $numboundaries = $i;
431
432 // Check there is nothing in the remaining unused fields.
e0b7cfcb 433 if (!empty($data['feedbackboundaries'])) {
434 for ($i = $numboundaries; $i < count($data['feedbackboundaries']); $i += 1) {
435 if (!empty($data['feedbackboundaries'][$i] ) && trim($data['feedbackboundaries'][$i] ) != '') {
436 $errors["feedbackboundaries[$i]"] = get_string('feedbackerrorjunkinboundary', 'quiz', $i + 1);
437 }
a23f0aaf 438 }
439 }
e0b7cfcb 440 for ($i = $numboundaries + 1; $i < count($data['feedbacktext']); $i += 1) {
a23f0aaf 441 if (!empty($data['feedbacktext'][$i] ) && trim($data['feedbacktext'][$i] ) != '') {
442 $errors["feedbacktext[$i]"] = get_string('feedbackerrorjunkinfeedback', 'quiz', $i + 1);
443 }
444 }
60243313 445
32648682 446 return $errors;
2ee60b49 447 }
a23f0aaf 448
449}
83192608 450