ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilAssQuestionHintList.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHint.php';
5
15{
22 private $questionHints = array();
23
30 public function current()
31 {
32 return current($this->questionHints);
33 }
34
41 public function rewind()
42 {
43 return reset($this->questionHints);
44 }
45
52 public function next()
53 {
54 return next($this->questionHints);
55 }
56
63 public function key()
64 {
65 return key($this->questionHints);
66 }
67
74 public function valid()
75 {
76 return key($this->questionHints) !== null;
77 }
78
84 public function __construct()
85 {
86 }
87
94 public function addHint(ilAssQuestionHint $questionHint)
95 {
96 $this->questionHints[] = $questionHint;
97 }
98
106 public function getHint($hintId)
107 {
108 foreach ($this as $questionHint) {
109 /* @var $questionHint ilAssQuestionHint */
110
111 if ($questionHint->getId() == $hintId) {
112 return $questionHint;
113 }
114 }
115
116 require_once 'Modules/TestQuestionPool/exceptions/class.ilTestQuestionPoolException.php';
117 throw new ilTestQuestionPoolException("hint with id $hintId does not exist in this list");
118 }
119
128 public function hintExists($hintId)
129 {
130 foreach ($this as $questionHint) {
131 /* @var $questionHint ilAssQuestionHint */
132
133 if ($questionHint->getId() == $hintId) {
134 return true;
135 }
136 }
137
138 return false;
139 }
140
150 public function reIndex()
151 {
152 $counter = 0;
153
154 foreach ($this as $questionHint) {
155 /* @var $questionHint ilAssQuestionHint */
156
157 $questionHint->setIndex(++$counter);
158 $questionHint->save();
159 }
160 }
161
171 public static function duplicateListForQuestion($originalQuestionId, $duplicateQuestionId)
172 {
173 $hintIds = array();
174
175 $questionHintList = self::getListByQuestionId($originalQuestionId);
176
177 foreach ($questionHintList as $questionHint) {
178 /* @var $questionHint ilAssQuestionHint */
179
180 $originalHintId = $questionHint->getId();
181
182 $questionHint->setId(null);
183 $questionHint->setQuestionId($duplicateQuestionId);
184
185 $questionHint->save();
186
187 $duplicateHintId = $questionHint->getId();
188
189 $hintIds[$originalHintId] = $duplicateHintId;
190 }
191
192 return $hintIds;
193 }
194
202 public function getTableData()
203 {
204 $tableData = array();
205
206 foreach ($this as $questionHint) {
207 /* @var $questionHint ilAssQuestionHint */
208
209 $tableData[] = array(
210 'hint_id' => $questionHint->getId(),
211 'hint_index' => $questionHint->getIndex(),
212 'hint_points' => $questionHint->getPoints(),
213 'hint_text' => $questionHint->getText()
214 );
215 }
216
217 return $tableData;
218 }
219
229 public static function getListByQuestionId($questionId)
230 {
231 global $DIC;
232 $ilDB = $DIC['ilDB'];
233
234 $query = "
235 SELECT qht_hint_id,
236 qht_question_fi,
237 qht_hint_index,
238 qht_hint_points,
239 qht_hint_text
240
241 FROM qpl_hints
242
243 WHERE qht_question_fi = %s
244
245 ORDER BY qht_hint_index ASC
246 ";
247
248 $res = $ilDB->queryF(
249 $query,
250 array('integer'),
251 array((int) $questionId)
252 );
253
254 $questionHintList = new self();
255
256 while ($row = $ilDB->fetchAssoc($res)) {
257 $questionHint = new ilAssQuestionHint();
258
259 ilAssQuestionHint::assignDbRow($questionHint, $row);
260
261 $questionHintList->addHint($questionHint);
262 }
263
264 return $questionHintList;
265 }
266
276 public static function getListByHintIds($hintIds)
277 {
278 global $DIC;
279 $ilDB = $DIC['ilDB'];
280
281 $qht_hint_id__IN__hintIds = $ilDB->in('qht_hint_id', $hintIds, false, 'integer');
282
283 $query = "
284 SELECT qht_hint_id,
285 qht_question_fi,
286 qht_hint_index,
287 qht_hint_points,
288 qht_hint_text
289
290 FROM qpl_hints
291
292 WHERE $qht_hint_id__IN__hintIds
293
294 ORDER BY qht_hint_index ASC
295 ";
296
297 $res = $ilDB->query($query);
298
299 $questionHintList = new self();
300
301 while ($row = $ilDB->fetchAssoc($res)) {
302 $questionHint = new ilAssQuestionHint();
303
304 ilAssQuestionHint::assignDbRow($questionHint, $row);
305
306 $questionHintList->addHint($questionHint);
307 }
308
309 return $questionHintList;
310 }
311
323 public static function getNextIndexByQuestionId($questionId)
324 {
325 global $DIC;
326 $ilDB = $DIC['ilDB'];
327
328 $query = "
329 SELECT 1 + COALESCE( MAX(qht_hint_index), 0 ) next_index
330
331 FROM qpl_hints
332
333 WHERE qht_question_fi = %s
334 ";
335
336 $res = $ilDB->queryF(
337 $query,
338 array('integer'),
339 array((int) $questionId)
340 );
341
342 $row = $ilDB->fetchAssoc($res);
343
344 return $row['next_index'];
345 }
346
353 public static function deleteHintsByQuestionIds($questionIds)
354 {
355 global $DIC;
356 $ilDB = $DIC['ilDB'];
357
358 $__qht_question_fi__IN__questionIds = $ilDB->in('qht_question_fi', $questionIds, false, 'integer');
359
360 $query = "
361 DELETE FROM qpl_hints
362 WHERE $__qht_question_fi__IN__questionIds
363 ";
364
365 return $ilDB->manipulate($query);
366 }
367}
An exception for terminatinating execution or to throw for unit testing.
rewind()
iterator interface method
getHint($hintId)
returns the question hint object relating to the passed hint id
key()
iterator interface method
current()
iterator interface method
valid()
iterator interface method
static deleteHintsByQuestionIds($questionIds)
Deletes all question hints relating to questions included in given question ids.
static getNextIndexByQuestionId($questionId)
determines the next index to be used for a new hint that is to be added to the list of existing hints...
hintExists($hintId)
checks wether a question hint object relating to the passed id exists or not
getTableData()
returns an array with data of the hints in this list that is adopted to be used as table gui data
reIndex()
re-indexes the list's hints sequentially by current order (starting with index "1")
next()
iterator interface method
addHint(ilAssQuestionHint $questionHint)
adds a question hint object to the current list instance
static duplicateListForQuestion($originalQuestionId, $duplicateQuestionId)
duplicates a hint list from given original question id to given duplicate question id and returns an ...
static getListByHintIds($hintIds)
instantiates a question hint list for the passed hint ids
static getListByQuestionId($questionId)
instantiates a question hint list for the passed question id
static assignDbRow(self $questionHint, $hintDbRow)
assigns the field elements of passed hint db row array to the corresponding hint object properties of...
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$DIC
Definition: xapitoken.php:46