ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilAssQuestionHint.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/exceptions/class.ilTestQuestionPoolException.php';
5 
15 {
16  const PAGE_OBJECT_TYPE = 'qht';
17 
24  private $id = null;
25 
32  private $questionId = null;
33 
41  private $index = null;
42 
50  private $points = null;
51 
58  private $text = null;
59 
65  public function __construct()
66  {
67 
68  }
69 
76  public function getId()
77  {
78  return $this->id;
79  }
80 
87  public function setId($id)
88  {
89  $this->id = (int)$id;
90  }
91 
98  public function getQuestionId()
99  {
100  return $this->questionId;
101  }
102 
109  public function setQuestionId($questionId)
110  {
111  $this->questionId = (int)$questionId;
112  }
113 
120  public function getIndex()
121  {
122  return $this->index;
123  }
124 
131  public function setIndex($index)
132  {
133  $this->index = (int)$index;
134  }
135 
142  public function getPoints()
143  {
144  return $this->points;
145  }
146 
153  public function setPoints($points)
154  {
155  $this->points = (float)$points;
156  }
157 
164  public function getText()
165  {
166  return $this->text;
167  }
168 
175  public function setText($text)
176  {
177  $this->text = $text;
178  }
179 
189  public function load($id)
190  {
191  global $ilDB;
192 
193  $query = "
194  SELECT qht_hint_id,
195  qht_question_fi,
196  qht_hint_index,
197  qht_hint_points,
198  qht_hint_text
199 
200  FROM qpl_hints
201 
202  WHERE qht_hint_id = %s
203  ";
204 
205  $res = $ilDB->queryF(
206  $query, array('integer'), array((int)$id)
207  );
208 
209  while( $row = $ilDB->fetchAssoc($res) )
210  {
211  self::assignDbRow($this, $row);
212 
213  return true;
214  }
215 
216  return false;
217  }
218 
228  public function save()
229  {
230  if( $this->getId() ) return $this->update();
231  else return $this->insert();
232  }
233 
242  private function update()
243  {
244  global $ilDB;
245 
246  return $ilDB->update(
247  'qpl_hints',
248  array(
249  'qht_question_fi' => array('integer', $this->getQuestionId()),
250  'qht_hint_index' => array('integer', $this->getIndex()),
251  'qht_hint_points' => array('float', $this->getPoints()),
252  'qht_hint_text' => array('clob', $this->getText())
253  ),
254  array(
255  'qht_hint_id' => array('integer', $this->getId())
256  )
257  );
258  }
259 
268  private function insert()
269  {
270  global $ilDB;
271 
272  $this->setId($ilDB->nextId('qpl_hints'));
273 
274  return $ilDB->insert('qpl_hints', array(
275  'qht_hint_id' => array('integer', $this->getId()),
276  'qht_question_fi' => array('integer', $this->getQuestionId()),
277  'qht_hint_index' => array('integer', $this->getIndex()),
278  'qht_hint_points' => array('float', $this->getPoints()),
279  'qht_hint_text' => array('clob', $this->getText())
280  ));
281  }
282 
289  public function delete()
290  {
291  return self::deleteById($this->getId());
292  }
293 
303  public static function assignDbRow(self $questionHint, $hintDbRow)
304  {
305  foreach($hintDbRow as $field => $value)
306  {
307  switch($field)
308  {
309  case 'qht_hint_id': $questionHint->setId($value); break;
310  case 'qht_question_fi': $questionHint->setQuestionId($value); break;
311  case 'qht_hint_index': $questionHint->setIndex($value); break;
312  case 'qht_hint_points': $questionHint->setPoints($value); break;
313  case 'qht_hint_text': $questionHint->setText($value); break;
314 
315  default: throw new ilTestQuestionPoolException("invalid db field identifier ($field) given!");
316  }
317  }
318  }
319 
330  public static function deleteById($hintId)
331  {
332  global $ilDB;
333 
334  $query = "
335  DELETE FROM qpl_hints
336  WHERE qht_hint_id = %s
337  ";
338 
339  return $ilDB->manipulateF(
340  $query, array('integer'), array($hintId)
341  );
342  }
343 
353  public static function getInstanceById($hintId)
354  {
355  $questionHint = new self();
356  $questionHint->load($hintId);
357  return $questionHint;
358  }
359 
360  public function getPageObjectType()
361  {
362  return self::PAGE_OBJECT_TYPE;
363  }
364 
365  public static function getHintIndexLabel(ilLanguage $lng, $hintIndex)
366  {
367  return sprintf($lng->txt('tst_question_hints_index_column_label'), $hintIndex);
368  }
369 }
setId($id)
sets the passed hint id
setPoints($points)
sets the passed points to ground-off for this hint
load($id)
loads the hint dataset with passed id from database and assigns it the to this hint object instance ...
static getInstanceById($hintId)
creates a hint object instance, loads the persisted hint dataset identified by passed hint id from da...
getIndex()
returns the ordering index of hint
static deleteById($hintId)
deletes the persisted hint object in database by deleting the hint dataset identified by hint id ...
update()
persists the current object state to database by updating an existing dataset identified by hint id ...
getQuestionId()
returns the question id the hint currently relates to
setIndex($index)
sets the passed hint ordering index
getId()
returns the hint id
insert()
persists the current object state to database by inserting a new dataset with a new hint id fetched f...
save()
saves the current hint object state to database.
static getHintIndexLabel(ilLanguage $lng, $hintIndex)
setQuestionId($questionId)
sets the passed question id so hint relates to it
setText($text)
sets the passed hint text
Create styles array
The data for the language used.
static assignDbRow(self $questionHint, $hintDbRow)
assigns the field elements of passed hint db row array to the corresponding hint object properties of...
getPoints()
returns the points to ground-off for this hint
global $lng
Definition: privfeed.php:17
global $ilDB
language handling
getText()
returns the hint text
txt($a_topic, $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...