ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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() { return current($this->questionHints); }
31
38 public function rewind() { return reset($this->questionHints); }
39
46 public function next() { return next($this->questionHints); }
47
54 public function key() { return key($this->questionHints); }
55
62 public function valid() { return key($this->questionHints) !== null; }
63
69 public function __construct() { }
70
77 public function addHint(ilAssQuestionHint $questionHint)
78 {
79 $this->questionHints[] = $questionHint;
80 }
81
89 public function getHint($hintId)
90 {
91 foreach($this as $questionHint)
92 {
93 /* @var $questionHint ilAssQuestionHint */
94
95 if( $questionHint->getId() == $hintId )
96 {
97 return $questionHint;
98 }
99 }
100
101 require_once 'Modules/TestQuestionPool/exceptions/class.ilTestQuestionPoolException.php';
102 throw new ilTestQuestionPoolException("hint with id $hintId does not exist in this list");
103 }
104
113 public function hintExists($hintId)
114 {
115 foreach($this as $questionHint)
116 {
117 /* @var $questionHint ilAssQuestionHint */
118
119 if( $questionHint->getId() == $hintId )
120 {
121 return true;
122 }
123 }
124
125 return false;
126 }
127
137 public function reIndex()
138 {
139 $counter = 0;
140
141 foreach($this as $questionHint)
142 {
143 /* @var $questionHint ilAssQuestionHint */
144
145 $questionHint->setIndex(++$counter);
146 $questionHint->save();
147 }
148 }
149
159 public static function duplicateListForQuestion($originalQuestionId, $duplicateQuestionId)
160 {
161 $hintIds = array();
162
163 $questionHintList = self::getListByQuestionId($originalQuestionId);
164
165 foreach($questionHintList as $questionHint)
166 {
167 /* @var $questionHint ilAssQuestionHint */
168
169 $originalHintId = $questionHint->getId();
170
171 $questionHint->setId(null);
172 $questionHint->setQuestionId($duplicateQuestionId);
173
174 $questionHint->save();
175
176 $duplicateHintId = $questionHint->getId();
177
178 $hintIds[$originalHintId] = $duplicateHintId;
179 }
180
181 return $hintIds;
182 }
183
191 public function getTableData()
192 {
193 $tableData = array();
194
195 foreach($this as $questionHint)
196 {
197 /* @var $questionHint ilAssQuestionHint */
198
199 $tableData[] = array(
200 'hint_id' => $questionHint->getId(),
201 'hint_index' => $questionHint->getIndex(),
202 'hint_points' => $questionHint->getPoints(),
203 'hint_text' => $questionHint->getText()
204 );
205 }
206
207 return $tableData;
208 }
209
219 public static function getListByQuestionId($questionId)
220 {
221 global $ilDB;
222
223 $query = "
224 SELECT qht_hint_id,
225 qht_question_fi,
226 qht_hint_index,
227 qht_hint_points,
228 qht_hint_text
229
230 FROM qpl_hints
231
232 WHERE qht_question_fi = %s
233
234 ORDER BY qht_hint_index ASC
235 ";
236
237 $res = $ilDB->queryF(
238 $query, array('integer'), array((int)$questionId)
239 );
240
241 $questionHintList = new self();
242
243 while( $row = $ilDB->fetchAssoc($res) )
244 {
245 $questionHint = new ilAssQuestionHint();
246
247 ilAssQuestionHint::assignDbRow($questionHint, $row);
248
249 $questionHintList->addHint($questionHint);
250 }
251
252 return $questionHintList;
253 }
254
264 public static function getListByHintIds($hintIds)
265 {
266 global $ilDB;
267
268 $qht_hint_id__IN__hintIds = $ilDB->in('qht_hint_id', $hintIds, false, 'integer');
269
270 $query = "
271 SELECT qht_hint_id,
272 qht_question_fi,
273 qht_hint_index,
274 qht_hint_points,
275 qht_hint_text
276
277 FROM qpl_hints
278
279 WHERE $qht_hint_id__IN__hintIds
280
281 ORDER BY qht_hint_index ASC
282 ";
283
284 $res = $ilDB->query($query);
285
286 $questionHintList = new self();
287
288 while( $row = $ilDB->fetchAssoc($res) )
289 {
290 $questionHint = new ilAssQuestionHint();
291
292 ilAssQuestionHint::assignDbRow($questionHint, $row);
293
294 $questionHintList->addHint($questionHint);
295 }
296
297 return $questionHintList;
298 }
299
311 public static function getNextIndexByQuestionId($questionId)
312 {
313 global $ilDB;
314
315 $query = "
316 SELECT 1 + COALESCE( MAX(qht_hint_index), 0 ) next_index
317
318 FROM qpl_hints
319
320 WHERE qht_question_fi = %s
321 ";
322
323 $res = $ilDB->queryF(
324 $query, array('integer'), array((int)$questionId)
325 );
326
327 $row = $ilDB->fetchAssoc($res);
328
329 return $row['next_index'];
330 }
331
338 public static function deleteHintsByQuestionIds($questionIds)
339 {
340 global $ilDB;
341
342 $__qht_question_fi__IN__questionIds = $ilDB->in('qht_question_fi', $questionIds, false, 'integer');
343
344 $query = "
345 DELETE FROM qpl_hints
346 WHERE $__qht_question_fi__IN__questionIds
347 ";
348
349 return $ilDB->manipulate($query);
350 }
351}
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...
global $ilDB