ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAssQuestionHint.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/exceptions/class.ilTestQuestionPoolException.php';
6 
16 {
23  private $id = null;
24 
31  private $questionId = null;
32 
40  private $index = null;
41 
49  private $points = null;
50 
57  private $text = null;
58 
64  public function __construct()
65  {
66 
67  }
68 
75  public function getId()
76  {
77  return $this->id;
78  }
79 
86  public function setId($id)
87  {
88  $this->id = (int)$id;
89  }
90 
97  public function getQuestionId()
98  {
99  return $this->questionId;
100  }
101 
108  public function setQuestionId($questionId)
109  {
110  $this->questionId = (int)$questionId;
111  }
112 
119  public function getIndex()
120  {
121  return $this->index;
122  }
123 
130  public function setIndex($index)
131  {
132  $this->index = (int)$index;
133  }
134 
141  public function getPoints()
142  {
143  return $this->points;
144  }
145 
152  public function setPoints($points)
153  {
154  $this->points = (float)$points;
155  }
156 
163  public function getText()
164  {
165  return $this->text;
166  }
167 
174  public function setText($text)
175  {
176  $this->text = $text;
177  }
178 
188  public function load($id)
189  {
190  global $ilDB;
191 
192  $query = "
193  SELECT qht_hint_id,
194  qht_question_fi,
195  qht_hint_index,
196  qht_hint_points,
197  qht_hint_text
198 
199  FROM qpl_hints
200 
201  WHERE qht_hint_id = %s
202  ";
203 
204  $res = $ilDB->queryF(
205  $query, array('integer'), array((int)$id)
206  );
207 
208  while( $row = $ilDB->fetchAssoc($res) )
209  {
210  self::assignDbRow($this, $row);
211 
212  return true;
213  }
214 
215  return false;
216  }
217 
227  public function save()
228  {
229  if( $this->getId() ) return $this->update();
230  else return $this->insert();
231  }
232 
241  private function update()
242  {
243  global $ilDB;
244 
245  return $ilDB->update(
246  'qpl_hints',
247  array(
248  'qht_question_fi' => array('integer', $this->getQuestionId()),
249  'qht_hint_index' => array('integer', $this->getIndex()),
250  'qht_hint_points' => array('float', $this->getPoints()),
251  'qht_hint_text' => array('clob', $this->getText())
252  ),
253  array(
254  'qht_hint_id' => array('integer', $this->getId())
255  )
256  );
257  }
258 
267  private function insert()
268  {
269  global $ilDB;
270 
271  $this->setId($ilDB->nextId('qpl_hints'));
272 
273  return $ilDB->insert('qpl_hints', array(
274  'qht_hint_id' => array('integer', $this->getId()),
275  'qht_question_fi' => array('integer', $this->getQuestionId()),
276  'qht_hint_index' => array('integer', $this->getIndex()),
277  'qht_hint_points' => array('float', $this->getPoints()),
278  'qht_hint_text' => array('clob', $this->getText())
279  ));
280  }
281 
288  public function delete()
289  {
290  return self::deleteById($this->getId());
291  }
292 
302  public static function assignDbRow(self $questionHint, $hintDbRow)
303  {
304  foreach($hintDbRow as $field => $value)
305  {
306  switch($field)
307  {
308  case 'qht_hint_id': $questionHint->setId($value); break;
309  case 'qht_question_fi': $questionHint->setQuestionId($value); break;
310  case 'qht_hint_index': $questionHint->setIndex($value); break;
311  case 'qht_hint_points': $questionHint->setPoints($value); break;
312  case 'qht_hint_text': $questionHint->setText($value); break;
313 
314  default: throw new ilTestQuestionPoolException("invalid db field identifier ($field) given!");
315  }
316  }
317  }
318 
329  public static function deleteById($hintId)
330  {
331  global $ilDB;
332 
333  $query = "
334  DELETE FROM qpl_hints
335  WHERE qht_hint_id = %s
336  ";
337 
338  return $ilDB->manipulateF(
339  $query, array('integer'), array($hintId)
340  );
341  }
342 
352  public static function getInstanceById($hintId)
353  {
354  $questionHint = new self();
355  $questionHint->load($hintId);
356  return $questionHint;
357  }
358 }