ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 require_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 $ilDB;
232 
233  $query = "
234  SELECT qht_hint_id,
235  qht_question_fi,
236  qht_hint_index,
237  qht_hint_points,
238  qht_hint_text
239 
240  FROM qpl_hints
241 
242  WHERE qht_question_fi = %s
243 
244  ORDER BY qht_hint_index ASC
245  ";
246 
247  $res = $ilDB->queryF(
248  $query,
249  array('integer'),
250  array((int) $questionId)
251  );
252 
253  $questionHintList = new self();
254 
255  while ($row = $ilDB->fetchAssoc($res)) {
256  $questionHint = new ilAssQuestionHint();
257 
258  ilAssQuestionHint::assignDbRow($questionHint, $row);
259 
260  $questionHintList->addHint($questionHint);
261  }
262 
263  return $questionHintList;
264  }
265 
275  public static function getListByHintIds($hintIds)
276  {
277  global $ilDB;
278 
279  $qht_hint_id__IN__hintIds = $ilDB->in('qht_hint_id', $hintIds, false, 'integer');
280 
281  $query = "
282  SELECT qht_hint_id,
283  qht_question_fi,
284  qht_hint_index,
285  qht_hint_points,
286  qht_hint_text
287 
288  FROM qpl_hints
289 
290  WHERE $qht_hint_id__IN__hintIds
291 
292  ORDER BY qht_hint_index ASC
293  ";
294 
295  $res = $ilDB->query($query);
296 
297  $questionHintList = new self();
298 
299  while ($row = $ilDB->fetchAssoc($res)) {
300  $questionHint = new ilAssQuestionHint();
301 
302  ilAssQuestionHint::assignDbRow($questionHint, $row);
303 
304  $questionHintList->addHint($questionHint);
305  }
306 
307  return $questionHintList;
308  }
309 
321  public static function getNextIndexByQuestionId($questionId)
322  {
323  global $ilDB;
324 
325  $query = "
326  SELECT 1 + COALESCE( MAX(qht_hint_index), 0 ) next_index
327 
328  FROM qpl_hints
329 
330  WHERE qht_question_fi = %s
331  ";
332 
333  $res = $ilDB->queryF(
334  $query,
335  array('integer'),
336  array((int) $questionId)
337  );
338 
339  $row = $ilDB->fetchAssoc($res);
340 
341  return $row['next_index'];
342  }
343 
350  public static function deleteHintsByQuestionIds($questionIds)
351  {
352  global $ilDB;
353 
354  $__qht_question_fi__IN__questionIds = $ilDB->in('qht_question_fi', $questionIds, false, 'integer');
355 
356  $query = "
357  DELETE FROM qpl_hints
358  WHERE $__qht_question_fi__IN__questionIds
359  ";
360 
361  return $ilDB->manipulate($query);
362  }
363 }
static getListByQuestionId($questionId)
instantiates a question hint list for the passed question id
rewind()
iterator interface method
$counter
static deleteHintsByQuestionIds($questionIds)
Deletes all question hints relating to questions included in given question ids.
static getListByHintIds($hintIds)
instantiates a question hint list for the passed hint ids
hintExists($hintId)
checks wether a question hint object relating to the passed id exists or not
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...
foreach($_POST as $key=> $value) $res
key()
iterator interface method
$query
Create styles array
The data for the language used.
static duplicateListForQuestion($originalQuestionId, $duplicateQuestionId)
duplicates a hint list from given original question id to given duplicate question id and returns an ...
next()
iterator interface method
reIndex()
re-indexes the list&#39;s hints sequentially by current order (starting with index "1") ...
valid()
iterator interface method
static assignDbRow(self $questionHint, $hintDbRow)
assigns the field elements of passed hint db row array to the corresponding hint object properties of...
addHint(ilAssQuestionHint $questionHint)
adds a question hint object to the current list instance
global $ilDB
current()
iterator interface method
getTableData()
returns an array with data of the hints in this list that is adopted to be used as table gui data ...
getHint($hintId)
returns the question hint object relating to the passed hint id