ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAssQuestionHintList.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHint.php';
6 
16 {
23  private $questionHints = array();
24 
31  public function current() { return current($this->questionHints); }
32 
39  public function rewind() { return reset($this->questionHints); }
40 
47  public function next() { return next($this->questionHints); }
48 
55  public function key() { return key($this->questionHints); }
56 
63  public function valid() { return key($this->questionHints) !== null; }
64 
70  public function __construct() { }
71 
78  public function addHint(ilAssQuestionHint $questionHint)
79  {
80  $this->questionHints[] = $questionHint;
81  }
82 
90  public function getHint($hintId)
91  {
92  foreach($this as $questionHint)
93  {
94  /* @var $questionHint ilAssQuestionHint */
95 
96  if( $questionHint->getId() == $hintId )
97  {
98  return $questionHint;
99  }
100  }
101 
102  require_once 'Modules/TestQuestionPool/exceptions/class.ilTestQuestionPoolException.php';
103  throw new ilTestQuestionPoolException("hint with id $hintId does not exist in this list");
104  }
105 
114  public function hintExists($hintId)
115  {
116  foreach($this as $questionHint)
117  {
118  /* @var $questionHint ilAssQuestionHint */
119 
120  if( $questionHint->getId() == $hintId )
121  {
122  return true;
123  }
124  }
125 
126  return false;
127  }
128 
138  public function reIndex()
139  {
140  $counter = 0;
141 
142  foreach($this as $questionHint)
143  {
144  /* @var $questionHint ilAssQuestionHint */
145 
146  $questionHint->setIndex(++$counter);
147  $questionHint->save();
148  }
149  }
150 
151  public static function duplicateListForQuestion($originalQuestionId, $duplicateQuestionId)
152  {
153  $questionHintList = self::getListByQuestionId($originalQuestionId);
154 
155  foreach($questionHintList as $questionHint)
156  {
157  /* @var $questionHint ilAssQuestionHint */
158 
159  $questionHint->setId(null);
160  $questionHint->setQuestionId($duplicateQuestionId);
161 
162  $questionHint->save();
163  }
164  }
165 
173  public function getTableData()
174  {
175  $tableData = array();
176 
177  foreach($this as $questionHint)
178  {
179  /* @var $questionHint ilAssQuestionHint */
180 
181  $tableData[] = array(
182  'hint_id' => $questionHint->getId(),
183  'hint_index' => $questionHint->getIndex(),
184  'hint_points' => $questionHint->getPoints(),
185  'hint_text' => $questionHint->getText()
186  );
187  }
188 
189  return $tableData;
190  }
191 
201  public static function getListByQuestionId($questionId)
202  {
203  global $ilDB;
204 
205  $query = "
206  SELECT qht_hint_id,
207  qht_question_fi,
208  qht_hint_index,
209  qht_hint_points,
210  qht_hint_text
211 
212  FROM qpl_hints
213 
214  WHERE qht_question_fi = %s
215 
216  ORDER BY qht_hint_index ASC
217  ";
218 
219  $res = $ilDB->queryF(
220  $query, array('integer'), array((int)$questionId)
221  );
222 
223  $questionHintList = new self();
224 
225  while( $row = $ilDB->fetchAssoc($res) )
226  {
227  $questionHint = new ilAssQuestionHint();
228 
229  ilAssQuestionHint::assignDbRow($questionHint, $row);
230 
231  $questionHintList->addHint($questionHint);
232  }
233 
234  return $questionHintList;
235  }
236 
246  public static function getListByHintIds($hintIds)
247  {
248  global $ilDB;
249 
250  $qht_hint_id__IN__hintIds = $ilDB->in('qht_hint_id', $hintIds, false, 'integer');
251 
252  $query = "
253  SELECT qht_hint_id,
254  qht_question_fi,
255  qht_hint_index,
256  qht_hint_points,
257  qht_hint_text
258 
259  FROM qpl_hints
260 
261  WHERE $qht_hint_id__IN__hintIds
262 
263  ORDER BY qht_hint_index ASC
264  ";
265 
266  $res = $ilDB->query($query);
267 
268  $questionHintList = new self();
269 
270  while( $row = $ilDB->fetchAssoc($res) )
271  {
272  $questionHint = new ilAssQuestionHint();
273 
274  ilAssQuestionHint::assignDbRow($questionHint, $row);
275 
276  $questionHintList->addHint($questionHint);
277  }
278 
279  return $questionHintList;
280  }
281 
293  public static function getNextIndexByQuestionId($questionId)
294  {
295  global $ilDB;
296 
297  $query = "
298  SELECT 1 + COALESCE( MAX(qht_hint_index), 0 ) next_index
299 
300  FROM qpl_hints
301 
302  WHERE qht_question_fi = %s
303  ";
304 
305  $res = $ilDB->queryF(
306  $query, array('integer'), array((int)$questionId)
307  );
308 
309  $row = $ilDB->fetchAssoc($res);
310 
311  return $row['next_index'];
312  }
313 
320  public static function deleteHintsByQuestionIds($questionIds)
321  {
322  global $ilDB;
323 
324  $__qht_question_fi__IN__questionIds = $ilDB->in('qht_question_fi', $questionIds, false, 'integer');
325 
326  $query = "
327  DELETE FROM qpl_hints
328  WHERE $__qht_question_fi__IN__questionIds
329  ";
330 
331  return $ilDB->manipulate($query);
332  }
333 }