ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
4require_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
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 $DIC;
191 $ilDB = $DIC['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,
207 array('integer'),
208 array((int) $id)
209 );
210
211 while ($row = $ilDB->fetchAssoc($res)) {
212 self::assignDbRow($this, $row);
213
214 return true;
215 }
216
217 return false;
218 }
219
229 public function save()
230 {
231 if ($this->getId()) {
232 return $this->update();
233 } else {
234 return $this->insert();
235 }
236 }
237
246 private function update()
247 {
248 global $DIC;
249 $ilDB = $DIC['ilDB'];
250
251 return $ilDB->update(
252 'qpl_hints',
253 array(
254 'qht_question_fi' => array('integer', $this->getQuestionId()),
255 'qht_hint_index' => array('integer', $this->getIndex()),
256 'qht_hint_points' => array('float', $this->getPoints()),
257 'qht_hint_text' => array('clob', $this->getText())
258 ),
259 array(
260 'qht_hint_id' => array('integer', $this->getId())
261 )
262 );
263 }
264
273 private function insert()
274 {
275 global $DIC;
276 $ilDB = $DIC['ilDB'];
277
278 $this->setId($ilDB->nextId('qpl_hints'));
279
280 return $ilDB->insert('qpl_hints', array(
281 'qht_hint_id' => array('integer', $this->getId()),
282 'qht_question_fi' => array('integer', $this->getQuestionId()),
283 'qht_hint_index' => array('integer', $this->getIndex()),
284 'qht_hint_points' => array('float', $this->getPoints()),
285 'qht_hint_text' => array('clob', $this->getText())
286 ));
287 }
288
295 public function delete()
296 {
297 return self::deleteById($this->getId());
298 }
299
309 public static function assignDbRow(self $questionHint, $hintDbRow)
310 {
311 foreach ($hintDbRow as $field => $value) {
312 switch ($field) {
313 case 'qht_hint_id': $questionHint->setId($value); break;
314 case 'qht_question_fi': $questionHint->setQuestionId($value); break;
315 case 'qht_hint_index': $questionHint->setIndex($value); break;
316 case 'qht_hint_points': $questionHint->setPoints($value); break;
317 case 'qht_hint_text': $questionHint->setText($value); break;
318
319 default: throw new ilTestQuestionPoolException("invalid db field identifier ($field) given!");
320 }
321 }
322 }
323
334 public static function deleteById($hintId)
335 {
336 global $DIC;
337 $ilDB = $DIC['ilDB'];
338
339 $query = "
340 DELETE FROM qpl_hints
341 WHERE qht_hint_id = %s
342 ";
343
344 return $ilDB->manipulateF(
345 $query,
346 array('integer'),
347 array($hintId)
348 );
349 }
350
360 public static function getInstanceById($hintId)
361 {
362 $questionHint = new self();
363 $questionHint->load($hintId);
364 return $questionHint;
365 }
366
367 public function getPageObjectType()
368 {
370 }
371
372 public static function getHintIndexLabel(ilLanguage $lng, $hintIndex)
373 {
374 return sprintf($lng->txt('tst_question_hints_index_column_label'), $hintIndex);
375 }
376}
An exception for terminatinating execution or to throw for unit testing.
getPoints()
returns the points to ground-off for this hint
save()
saves the current hint object state to database.
static deleteById($hintId)
deletes the persisted hint object in database by deleting the hint dataset identified by hint id
static assignDbRow(self $questionHint, $hintDbRow)
assigns the field elements of passed hint db row array to the corresponding hint object properties of...
update()
persists the current object state to database by updating an existing dataset identified by hint id
getText()
returns the hint text
insert()
persists the current object state to database by inserting a new dataset with a new hint id fetched f...
getQuestionId()
returns the question id the hint currently relates to
setId($id)
sets the passed hint id
static getInstanceById($hintId)
creates a hint object instance, loads the persisted hint dataset identified by passed hint id from da...
load($id)
loads the hint dataset with passed id from database and assigns it the to this hint object instance
getIndex()
returns the ordering index of hint
setQuestionId($questionId)
sets the passed question id so hint relates to it
setText($text)
sets the passed hint text
setPoints($points)
sets the passed points to ground-off for this hint
setIndex($index)
sets the passed hint ordering index
getId()
returns the hint id
static getHintIndexLabel(ilLanguage $lng, $hintIndex)
language handling
$row
$query
global $DIC
Definition: saml.php:7
$lng
foreach($_POST as $key=> $value) $res
global $ilDB