44888f69 |
1 | <?php // $Id$ |
23a7718b |
2 | require_once ($CFG->dirroot.'/course/moodleform_mod.php'); |
a23f0aaf |
3 | |
4 | require_once("$CFG->dirroot/mod/quiz/locallib.php"); |
5 | |
f07b9627 |
6 | class mod_quiz_mod_form extends moodleform_mod { |
a23f0aaf |
7 | var $_feedbacks; |
8 | |
2ee60b49 |
9 | function definition() { |
a23f0aaf |
10 | |
c18269c7 |
11 | global $COURSE, $CFG, $DB; |
e2249afe |
12 | $quizconfig = get_config('quiz'); |
2ee60b49 |
13 | $mform =& $this->_form; |
a23f0aaf |
14 | |
a23f0aaf |
15 | //------------------------------------------------------------------------------- |
16 | $mform->addElement('header', 'general', get_string('general', 'form')); |
17 | |
26de8d35 |
18 | $mform->addElement('text', 'name', get_string('name'), array('size'=>'64')); |
8eb1d25f |
19 | if (!empty($CFG->formatstringstriptags)) { |
20 | $mform->setType('name', PARAM_TEXT); |
21 | } else { |
22 | $mform->setType('name', PARAM_CLEAN); |
23 | } |
99ebfea2 |
24 | $mform->addRule('name', null, 'required', null, 'client'); |
a23f0aaf |
25 | |
2ee60b49 |
26 | $mform->addElement('htmleditor', 'intro', get_string("introduction", "quiz")); |
27 | $mform->setType('intro', PARAM_RAW); |
16851b22 |
28 | $mform->setHelpButton('intro', array('richtext2', get_string('helprichtext'))); |
a23f0aaf |
29 | |
30 | //------------------------------------------------------------------------------- |
31 | $mform->addElement('header', 'timinghdr', get_string('timing', 'form')); |
8289cdf3 |
32 | $mform->addElement('date_time_selector', 'timeopen', get_string('quizopen', 'quiz'), array('optional'=>true)); |
33 | $mform->setHelpButton('timeopen', array('timeopen', get_string('quizopen', 'quiz'), 'quiz')); |
a23f0aaf |
34 | |
8289cdf3 |
35 | $mform->addElement('date_time_selector', 'timeclose', get_string('quizclose', 'quiz'), array('optional'=>true)); |
36 | $mform->setHelpButton('timeclose', array('timeopen', get_string('quizclose', 'quiz'), 'quiz')); |
a23f0aaf |
37 | |
38 | |
39 | $timelimitgrp=array(); |
40 | $timelimitgrp[] = &$mform->createElement('text', 'timelimit'); |
41 | $timelimitgrp[] = &$mform->createElement('checkbox', 'timelimitenable', '', get_string('enable')); |
bb4598fc |
42 | $mform->addGroup($timelimitgrp, 'timelimitgrp', get_string('timelimitmin', 'quiz'), array(' '), false); |
2ee60b49 |
43 | $mform->setType('timelimit', PARAM_TEXT); |
44 | $timelimitgrprules = array(); |
45 | $timelimitgrprules['timelimit'][] = array(null, 'numeric', null, 'client'); |
46 | $mform->addGroupRule('timelimitgrp', $timelimitgrprules); |
a23f0aaf |
47 | $mform->disabledIf('timelimitgrp', 'timelimitenable'); |
e2249afe |
48 | $mform->setAdvanced('timelimitgrp', $quizconfig->fix_timelimit); |
2ee60b49 |
49 | $mform->setHelpButton('timelimitgrp', array("timelimit", get_string("quiztimer","quiz"), "quiz")); |
e2249afe |
50 | $mform->setDefault('timelimit', $quizconfig->timelimit); |
51 | $mform->setDefault('timelimitenable', !empty($quizconfig->timelimit)); |
a23f0aaf |
52 | |
53 | |
54 | //enforced time delay between quiz attempts add-on |
55 | $timedelayoptions = array(); |
56 | $timedelayoptions[0] = get_string('none'); |
57 | $timedelayoptions[1800] = get_string('numminutes', '', 30); |
58 | $timedelayoptions[3600] = get_string('numminutes', '', 60); |
59 | for($i=2; $i<=23; $i++) { |
60 | $seconds = $i*3600; |
61 | $timedelayoptions[$seconds] = get_string('numhours', '', $i); |
62 | } |
63 | $timedelayoptions[86400] = get_string('numhours', '', 24); |
64 | for($i=2; $i<=7; $i++) { |
65 | $seconds = $i*86400; |
66 | $timedelayoptions[$seconds] = get_string('numdays', '', $i); |
67 | } |
68 | $mform->addElement('select', 'delay1', get_string("delay1", "quiz"), $timedelayoptions); |
2ee60b49 |
69 | $mform->setHelpButton('delay1', array("timedelay1", get_string("delay1", "quiz"), "quiz")); |
e2249afe |
70 | $mform->setAdvanced('delay1', $quizconfig->fix_delay1); |
71 | $mform->setDefault('delay1', $quizconfig->delay1); |
a23f0aaf |
72 | |
73 | $mform->addElement('select', 'delay2', get_string("delay2", "quiz"), $timedelayoptions); |
2ee60b49 |
74 | $mform->setHelpButton('delay2', array("timedelay2", get_string("delay2", "quiz"), "quiz")); |
e2249afe |
75 | $mform->setAdvanced('delay2', $quizconfig->fix_delay2); |
76 | $mform->setDefault('delay2', $quizconfig->delay2); |
a23f0aaf |
77 | |
78 | //------------------------------------------------------------------------------- |
79 | $mform->addElement('header', 'displayhdr', get_string('display', 'form')); |
2ee60b49 |
80 | $perpage = array(); |
4c07690e |
81 | $perpage[0] = get_string('never'); |
82 | $perpage[1] = get_string('aftereachquestion', 'quiz'); |
83 | for ($i = 2; $i <= 50; ++$i) { |
84 | $perpage[$i] = get_string('afternquestions', 'quiz', $i); |
a23f0aaf |
85 | } |
4c07690e |
86 | $mform->addElement('select', 'questionsperpage', get_string('newpageevery', 'quiz'), $perpage); |
87 | $mform->setHelpButton('questionsperpage', array('questionsperpage', get_string('newpageevery', 'quiz'), 'quiz')); |
e2249afe |
88 | $mform->setAdvanced('questionsperpage', $quizconfig->fix_questionsperpage); |
89 | $mform->setDefault('questionsperpage', $quizconfig->questionsperpage); |
a23f0aaf |
90 | |
2ee60b49 |
91 | $mform->addElement('selectyesno', 'shufflequestions', get_string("shufflequestions", "quiz")); |
92 | $mform->setHelpButton('shufflequestions', array("shufflequestions", get_string("shufflequestions","quiz"), "quiz")); |
e2249afe |
93 | $mform->setAdvanced('shufflequestions', $quizconfig->fix_shufflequestions); |
94 | $mform->setDefault('shufflequestions', $quizconfig->shufflequestions); |
a23f0aaf |
95 | |
2ee60b49 |
96 | $mform->addElement('selectyesno', 'shuffleanswers', get_string("shufflewithin", "quiz")); |
97 | $mform->setHelpButton('shuffleanswers', array("shufflewithin", get_string("shufflewithin","quiz"), "quiz")); |
e2249afe |
98 | $mform->setAdvanced('shuffleanswers', $quizconfig->fix_shuffleanswers); |
99 | $mform->setDefault('shuffleanswers', $quizconfig->shuffleanswers); |
a23f0aaf |
100 | |
a733c4b9 |
101 | $mform->addElement('selectyesno', 'showuserpicture', get_string('showuserpicture', 'quiz')); |
102 | $mform->setHelpButton('showuserpicture', array('showuserpicture', get_string('showuserpicture', 'quiz'), 'quiz')); |
103 | $mform->setAdvanced('showuserpicture', $quizconfig->fix_showuserpicture); |
104 | $mform->setDefault('showuserpicture', $quizconfig->showuserpicture); |
105 | |
a23f0aaf |
106 | //------------------------------------------------------------------------------- |
107 | $mform->addElement('header', 'attemptshdr', get_string('attempts', 'quiz')); |
ab652c35 |
108 | $attemptoptions = array('0' => get_string('unlimited')); |
109 | for ($i = 1; $i <= 10; $i++) { |
110 | $attemptoptions[$i] = $i; |
a23f0aaf |
111 | } |
2ee60b49 |
112 | $mform->addElement('select', 'attempts', get_string("attemptsallowed", "quiz"), $attemptoptions); |
113 | $mform->setHelpButton('attempts', array("attempts", get_string("attemptsallowed","quiz"), "quiz")); |
e2249afe |
114 | $mform->setAdvanced('attempts', $quizconfig->fix_attempts); |
115 | $mform->setDefault('attempts', $quizconfig->attempts); |
a23f0aaf |
116 | |
2ee60b49 |
117 | $mform->addElement('selectyesno', 'attemptonlast', get_string("eachattemptbuildsonthelast", "quiz")); |
118 | $mform->setHelpButton('attemptonlast', array("repeatattempts", get_string("eachattemptbuildsonthelast", "quiz"), "quiz")); |
e2249afe |
119 | $mform->setAdvanced('attemptonlast', $quizconfig->fix_attemptonlast); |
120 | $mform->setDefault('attemptonlast', $quizconfig->attemptonlast); |
a23f0aaf |
121 | |
2ee60b49 |
122 | $mform->addElement('selectyesno', 'adaptive', get_string("adaptive", "quiz")); |
123 | $mform->setHelpButton('adaptive', array("adaptive", get_string("adaptive","quiz"), "quiz")); |
e2249afe |
124 | $mform->setAdvanced('adaptive', $quizconfig->fix_optionflags); |
125 | $mform->setDefault('adaptive', $quizconfig->optionflags & QUESTION_ADAPTIVE); |
a23f0aaf |
126 | |
127 | |
128 | //------------------------------------------------------------------------------- |
129 | $mform->addElement('header', 'gradeshdr', get_string('grades', 'grades')); |
0675e5eb |
130 | $mform->addElement('select', 'grademethod', get_string("grademethod", "quiz"), quiz_get_grading_options()); |
2ee60b49 |
131 | $mform->setHelpButton('grademethod', array("grademethod", get_string("grademethod","quiz"), "quiz")); |
e2249afe |
132 | $mform->setAdvanced('grademethod', $quizconfig->fix_grademethod); |
133 | $mform->setDefault('grademethod', $quizconfig->grademethod); |
a23f0aaf |
134 | |
2ee60b49 |
135 | $mform->addElement('selectyesno', 'penaltyscheme', get_string("penaltyscheme", "quiz")); |
136 | $mform->setHelpButton('penaltyscheme', array("penaltyscheme", get_string("penaltyscheme","quiz"), "quiz")); |
e2249afe |
137 | $mform->setAdvanced('penaltyscheme', $quizconfig->fix_penaltyscheme); |
138 | $mform->setDefault('penaltyscheme', $quizconfig->penaltyscheme); |
a23f0aaf |
139 | |
2ee60b49 |
140 | $options = array( |
a23f0aaf |
141 | 0 => '0', |
142 | 1 => '1', |
143 | 2 => '2', |
144 | 3 => '3'); |
2ee60b49 |
145 | $mform->addElement('select', 'decimalpoints', get_string("decimaldigits", "quiz"), $options); |
146 | $mform->setHelpButton('decimalpoints', array("decimalpoints", get_string("decimaldigits","quiz"), "quiz")); |
e2249afe |
147 | $mform->setAdvanced('decimalpoints', $quizconfig->fix_decimalpoints); |
148 | $mform->setDefault('decimalpoints', $quizconfig->decimalpoints); |
a23f0aaf |
149 | |
e2249afe |
150 | $mform->addElement('hidden', 'grade', $quizconfig->maximumgrade); |
a23f0aaf |
151 | |
152 | //------------------------------------------------------------------------------- |
e2833e87 |
153 | $mform->addElement('header', 'reviewoptionshdr', get_string('reviewoptionsheading', 'quiz')); |
154 | $mform->setHelpButton('reviewoptionshdr', array('reviewoptions', get_string('reviewoptionsheading','quiz'), 'quiz')); |
e2249afe |
155 | $mform->setAdvanced('reviewoptionshdr', $quizconfig->fix_review); |
a23f0aaf |
156 | |
2ee60b49 |
157 | $immediatelyoptionsgrp=array(); |
a23f0aaf |
158 | $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'responsesimmediately', '', get_string('responses', 'quiz')); |
a23f0aaf |
159 | $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'answersimmediately', '', get_string('answers', 'quiz')); |
00719c02 |
160 | $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackimmediately', '', get_string('feedback', 'quiz')); |
a23f0aaf |
161 | $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackimmediately', '', get_string('generalfeedback', 'quiz')); |
00719c02 |
162 | $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'scoreimmediately', '', get_string('scores', 'quiz')); |
163 | $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'overallfeedbackimmediately', '', get_string('overallfeedback', 'quiz')); |
a23f0aaf |
164 | $mform->addGroup($immediatelyoptionsgrp, 'immediatelyoptionsgrp', get_string("reviewimmediately", "quiz"), null, false); |
e2249afe |
165 | $mform->setDefault('responsesimmediately', $quizconfig->review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_IMMEDIATELY); |
166 | $mform->setDefault('answersimmediately', $quizconfig->review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_IMMEDIATELY); |
167 | $mform->setDefault('feedbackimmediately', $quizconfig->review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_IMMEDIATELY); |
168 | $mform->setDefault('generalfeedbackimmediately', $quizconfig->review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_IMMEDIATELY); |
169 | $mform->setDefault('scoreimmediately', $quizconfig->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_IMMEDIATELY); |
170 | $mform->setDefault('overallfeedbackimmediately', $quizconfig->review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_IMMEDIATELY); |
a23f0aaf |
171 | |
2ee60b49 |
172 | $openoptionsgrp=array(); |
a23f0aaf |
173 | $openoptionsgrp[] = &$mform->createElement('checkbox', 'responsesopen', '', get_string('responses', 'quiz')); |
a23f0aaf |
174 | $openoptionsgrp[] = &$mform->createElement('checkbox', 'answersopen', '', get_string('answers', 'quiz')); |
00719c02 |
175 | $openoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackopen', '', get_string('feedback', 'quiz')); |
a23f0aaf |
176 | $openoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackopen', '', get_string('generalfeedback', 'quiz')); |
00719c02 |
177 | $openoptionsgrp[] = &$mform->createElement('checkbox', 'scoreopen', '', get_string('scores', 'quiz')); |
178 | $openoptionsgrp[] = &$mform->createElement('checkbox', 'overallfeedbackopen', '', get_string('overallfeedback', 'quiz')); |
a23f0aaf |
179 | $mform->addGroup($openoptionsgrp, 'openoptionsgrp', get_string("reviewopen", "quiz"), array(' '), false); |
e2249afe |
180 | $mform->setDefault('responsesopen', $quizconfig->review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_OPEN); |
181 | $mform->setDefault('answersopen', $quizconfig->review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_OPEN); |
182 | $mform->setDefault('feedbackopen', $quizconfig->review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_OPEN); |
183 | $mform->setDefault('generalfeedbackopen', $quizconfig->review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_OPEN); |
184 | $mform->setDefault('scoreopen', $quizconfig->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_OPEN); |
185 | $mform->setDefault('overallfeedbackopen', $quizconfig->review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_OPEN); |
a23f0aaf |
186 | |
187 | |
2ee60b49 |
188 | $closedoptionsgrp=array(); |
a23f0aaf |
189 | $closedoptionsgrp[] = &$mform->createElement('checkbox', 'responsesclosed', '', get_string('responses', 'quiz')); |
a23f0aaf |
190 | $closedoptionsgrp[] = &$mform->createElement('checkbox', 'answersclosed', '', get_string('answers', 'quiz')); |
00719c02 |
191 | $closedoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackclosed', '', get_string('feedback', 'quiz')); |
a23f0aaf |
192 | $closedoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackclosed', '', get_string('generalfeedback', 'quiz')); |
00719c02 |
193 | $closedoptionsgrp[] = &$mform->createElement('checkbox', 'scoreclosed', '', get_string('scores', 'quiz')); |
194 | $closedoptionsgrp[] = &$mform->createElement('checkbox', 'overallfeedbackclosed', '', get_string('overallfeedback', 'quiz')); |
a23f0aaf |
195 | $mform->addGroup($closedoptionsgrp, 'closedoptionsgrp', get_string("reviewclosed", "quiz"), array(' '), false); |
e2249afe |
196 | $mform->setDefault('responsesclosed', $quizconfig->review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_CLOSED); |
197 | $mform->setDefault('answersclosed', $quizconfig->review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_CLOSED); |
198 | $mform->setDefault('feedbackclosed', $quizconfig->review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_CLOSED); |
199 | $mform->setDefault('generalfeedbackclosed', $quizconfig->review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_CLOSED); |
200 | $mform->setDefault('scoreclosed', $quizconfig->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_CLOSED); |
201 | $mform->setDefault('overallfeedbackclosed', $quizconfig->review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_CLOSED); |
a23f0aaf |
202 | |
203 | //------------------------------------------------------------------------------- |
204 | $mform->addElement('header', 'security', get_string('security', 'form')); |
205 | |
206 | $mform->addElement('selectyesno', 'popup', get_string("popup", "quiz")); |
2ee60b49 |
207 | $mform->setHelpButton('popup', array("popup", get_string("popup", "quiz"), "quiz")); |
e2249afe |
208 | $mform->setAdvanced('popup', $quizconfig->fix_popup); |
209 | $mform->setDefault('popup', $quizconfig->popup); |
a23f0aaf |
210 | |
54bb33eb |
211 | $mform->addElement('passwordunmask', 'quizpassword', get_string("requirepassword", "quiz")); |
2ee60b49 |
212 | $mform->setType('quizpassword', PARAM_TEXT); |
213 | $mform->setHelpButton('quizpassword', array("requirepassword", get_string("requirepassword", "quiz"), "quiz")); |
e2249afe |
214 | $mform->setAdvanced('quizpassword', $quizconfig->fix_password); |
215 | $mform->setDefault('quizpassword', $quizconfig->password); |
a23f0aaf |
216 | |
2ee60b49 |
217 | $mform->addElement('text', 'subnet', get_string("requiresubnet", "quiz")); |
218 | $mform->setType('subnet', PARAM_TEXT); |
219 | $mform->setHelpButton('subnet', array("requiresubnet", get_string("requiresubnet", "quiz"), "quiz")); |
e2249afe |
220 | $mform->setAdvanced('subnet', $quizconfig->fix_subnet); |
221 | $mform->setDefault('subnet', $quizconfig->subnet); |
a23f0aaf |
222 | |
223 | //------------------------------------------------------------------------------- |
5ada3c8e |
224 | $features = new stdClass; |
225 | $features->groups = true; |
226 | $features->groupings = true; |
227 | $features->groupmembersonly = true; |
228 | $this->standard_coursemodule_elements($features); |
a23f0aaf |
229 | //------------------------------------------------------------------------------- |
08224df1 |
230 | $mform->addElement('header', 'overallfeedbackhdr', get_string('overallfeedback', 'quiz')); |
2ee60b49 |
231 | $mform->setHelpButton('overallfeedbackhdr', array('overallfeedback', get_string('overallfeedback', 'quiz'), 'quiz')); |
a23f0aaf |
232 | |
2ee60b49 |
233 | $mform->addElement('static', 'gradeboundarystatic1', get_string('gradeboundary', 'quiz'), '100%'); |
a23f0aaf |
234 | |
235 | $repeatarray=array(); |
a462602a |
236 | $repeatarray[] = &MoodleQuickForm::createElement('text', 'feedbacktext', get_string('feedback', 'quiz'), array('size' => 50)); |
237 | $repeatarray[] = &MoodleQuickForm::createElement('text', 'feedbackboundaries', get_string('gradeboundary', 'quiz'), array('size' => 10)); |
a23f0aaf |
238 | |
239 | if (!empty($this->_instance)) { |
c18269c7 |
240 | $this->_feedbacks = $DB->get_records('quiz_feedback', array('quizid'=>$this->_instance), 'mingrade DESC'); |
a23f0aaf |
241 | } else { |
242 | $this->_feedbacks = array(); |
243 | } |
244 | $numfeedbacks = max(count($this->_feedbacks) * 1.5, 5); |
ebff6e2c |
245 | |
de266537 |
246 | $mform->setType('feedbacktext', PARAM_RAW); |
3a298174 |
247 | $mform->setType('feedbackboundaries', PARAM_NOTAGS); |
ebff6e2c |
248 | |
a23f0aaf |
249 | $nextel=$this->repeat_elements($repeatarray, $numfeedbacks-1, |
6f3b54c8 |
250 | array(), 'boundary_repeats', 'boundary_add_fields', 3, |
251 | get_string('addmoreoverallfeedbacks', 'quiz'), true); |
a23f0aaf |
252 | |
253 | //put some extra elements in before the button |
a462602a |
254 | $insertEl = &MoodleQuickForm::createElement('text', "feedbacktext[$nextel]", get_string('feedback', 'quiz'), array('size' => 50)); |
a23f0aaf |
255 | $mform->insertElementBefore($insertEl, 'boundary_add_fields'); |
a23f0aaf |
256 | |
257 | $insertEl = &MoodleQuickForm::createElement('static', 'gradeboundarystatic2', get_string('gradeboundary', 'quiz'), '0%'); |
258 | $mform->insertElementBefore($insertEl, 'boundary_add_fields'); |
259 | |
260 | //------------------------------------------------------------------------------- |
261 | // buttons |
262 | $this->add_action_buttons(); |
2ee60b49 |
263 | } |
a23f0aaf |
264 | |
2ee60b49 |
265 | function data_preprocessing(&$default_values){ |
a23f0aaf |
266 | if (count($this->_feedbacks)) { |
267 | $key = 0; |
268 | foreach ($this->_feedbacks as $feedback){ |
269 | $default_values['feedbacktext['.$key.']'] = $feedback->feedbacktext; |
270 | if ($feedback->mingrade > 0) { |
271 | $default_values['feedbackboundaries['.$key.']'] = (100.0 * $feedback->mingrade / $default_values['grade']) . '%'; |
272 | } |
273 | $key++; |
274 | } |
a23f0aaf |
275 | } |
298daa21 |
276 | |
277 | if (isset($default_values['timelimit'])) { |
278 | $default_values['timelimitenable'] = $default_values['timelimit'] > 0; |
a23f0aaf |
279 | } |
280 | |
281 | if (isset($default_values['review'])){ |
282 | $review = (int)$default_values['review']; |
283 | unset($default_values['review']); |
284 | |
285 | $default_values['responsesimmediately'] = $review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_IMMEDIATELY; |
a23f0aaf |
286 | $default_values['answersimmediately'] = $review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_IMMEDIATELY; |
00719c02 |
287 | $default_values['feedbackimmediately'] = $review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_IMMEDIATELY; |
a23f0aaf |
288 | $default_values['generalfeedbackimmediately'] = $review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_IMMEDIATELY; |
00719c02 |
289 | $default_values['scoreimmediately'] = $review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_IMMEDIATELY; |
290 | $default_values['overallfeedbackimmediately'] = $review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_IMMEDIATELY; |
a23f0aaf |
291 | |
292 | $default_values['responsesopen'] = $review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_OPEN; |
a23f0aaf |
293 | $default_values['answersopen'] = $review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_OPEN; |
00719c02 |
294 | $default_values['feedbackopen'] = $review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_OPEN; |
a23f0aaf |
295 | $default_values['generalfeedbackopen'] = $review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_OPEN; |
00719c02 |
296 | $default_values['scoreopen'] = $review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_OPEN; |
297 | $default_values['overallfeedbackopen'] = $review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_OPEN; |
a23f0aaf |
298 | |
299 | $default_values['responsesclosed'] = $review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_CLOSED; |
a23f0aaf |
300 | $default_values['answersclosed'] = $review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_CLOSED; |
00719c02 |
301 | $default_values['feedbackclosed'] = $review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_CLOSED; |
a23f0aaf |
302 | $default_values['generalfeedbackclosed'] = $review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_CLOSED; |
00719c02 |
303 | $default_values['scoreclosed'] = $review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_CLOSED; |
304 | $default_values['overallfeedbackclosed'] = $review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_CLOSED; |
a23f0aaf |
305 | } |
306 | |
307 | if (isset($default_values['optionflags'])){ |
308 | $default_values['adaptive'] = $default_values['optionflags'] & QUESTION_ADAPTIVE; |
309 | unset($default_values['optionflags']); |
310 | } |
ab0a8ff2 |
311 | |
312 | // Password field - different in form to stop browsers that remember passwords |
313 | // getting confused. |
2ee60b49 |
314 | if (isset($default_values['password'])) { |
ab0a8ff2 |
315 | $default_values['quizpassword'] = $default_values['password']; |
316 | unset($default_values['password']); |
317 | } |
2ee60b49 |
318 | } |
a23f0aaf |
319 | |
a78890d5 |
320 | function validation($data, $files) { |
321 | $errors = parent::validation($data, $files); |
60243313 |
322 | |
a23f0aaf |
323 | // Check open and close times are consistent. |
324 | if ($data['timeopen'] != 0 && $data['timeclose'] != 0 && $data['timeclose'] < $data['timeopen']) { |
325 | $errors['timeclose'] = get_string('closebeforeopen', 'quiz'); |
326 | } |
327 | |
328 | // Check the boundary value is a number or a percentage, and in range. |
329 | $i = 0; |
330 | while (!empty($data['feedbackboundaries'][$i] )) { |
331 | $boundary = trim($data['feedbackboundaries'][$i]); |
332 | if (strlen($boundary) > 0 && $boundary[strlen($boundary) - 1] == '%') { |
333 | $boundary = trim(substr($boundary, 0, -1)); |
334 | if (is_numeric($boundary)) { |
335 | $boundary = $boundary * $data['grade'] / 100.0; |
336 | } else { |
337 | $errors["feedbackboundaries[$i]"] = get_string('feedbackerrorboundaryformat', 'quiz', $i + 1); |
338 | } |
339 | } |
340 | if (is_numeric($boundary) && $boundary <= 0 || $boundary >= $data['grade'] ) { |
341 | $errors["feedbackboundaries[$i]"] = get_string('feedbackerrorboundaryoutofrange', 'quiz', $i + 1); |
342 | } |
343 | if (is_numeric($boundary) && $i > 0 && $boundary >= $data['feedbackboundaries'][$i - 1]) { |
344 | $errors["feedbackboundaries[$i]"] = get_string('feedbackerrororder', 'quiz', $i + 1); |
345 | } |
346 | $data['feedbackboundaries'][$i] = $boundary; |
347 | $i += 1; |
348 | } |
349 | $numboundaries = $i; |
350 | |
351 | // Check there is nothing in the remaining unused fields. |
352 | for ($i = $numboundaries; $i < count($data['feedbackboundaries'] ); $i += 1) { |
353 | if (!empty($data['feedbackboundaries'][$i] ) && trim($data['feedbackboundaries'][$i] ) != '') { |
354 | $errors["feedbackboundaries[$i]"] = get_string('feedbackerrorjunkinboundary', 'quiz', $i + 1); |
355 | } |
356 | } |
357 | for ($i = $numboundaries + 1; $i < count($data['feedbacktext'] ); $i += 1) { |
358 | if (!empty($data['feedbacktext'][$i] ) && trim($data['feedbacktext'][$i] ) != '') { |
359 | $errors["feedbacktext[$i]"] = get_string('feedbackerrorjunkinfeedback', 'quiz', $i + 1); |
360 | } |
361 | } |
60243313 |
362 | |
32648682 |
363 | return $errors; |
2ee60b49 |
364 | } |
a23f0aaf |
365 | |
366 | } |
2ee60b49 |
367 | ?> |