ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $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,
206 array('integer'),
207 array((int) $id)
208 );
209
210 while ($row = $ilDB->fetchAssoc($res)) {
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()) {
231 return $this->update();
232 } else {
233 return $this->insert();
234 }
235 }
236
245 private function update()
246 {
247 global $ilDB;
248
249 return $ilDB->update(
250 'qpl_hints',
251 array(
252 'qht_question_fi' => array('integer', $this->getQuestionId()),
253 'qht_hint_index' => array('integer', $this->getIndex()),
254 'qht_hint_points' => array('float', $this->getPoints()),
255 'qht_hint_text' => array('clob', $this->getText())
256 ),
257 array(
258 'qht_hint_id' => array('integer', $this->getId())
259 )
260 );
261 }
262
271 private function insert()
272 {
273 global $ilDB;
274
275 $this->setId($ilDB->nextId('qpl_hints'));
276
277 return $ilDB->insert('qpl_hints', array(
278 'qht_hint_id' => array('integer', $this->getId()),
279 'qht_question_fi' => array('integer', $this->getQuestionId()),
280 'qht_hint_index' => array('integer', $this->getIndex()),
281 'qht_hint_points' => array('float', $this->getPoints()),
282 'qht_hint_text' => array('clob', $this->getText())
283 ));
284 }
285
292 public function delete()
293 {
294 return self::deleteById($this->getId());
295 }
296
306 public static function assignDbRow(self $questionHint, $hintDbRow)
307 {
308 foreach ($hintDbRow as $field => $value) {
309 switch ($field) {
310 case 'qht_hint_id': $questionHint->setId($value); break;
311 case 'qht_question_fi': $questionHint->setQuestionId($value); break;
312 case 'qht_hint_index': $questionHint->setIndex($value); break;
313 case 'qht_hint_points': $questionHint->setPoints($value); break;
314 case 'qht_hint_text': $questionHint->setText($value); break;
315
316 default: throw new ilTestQuestionPoolException("invalid db field identifier ($field) given!");
317 }
318 }
319 }
320
331 public static function deleteById($hintId)
332 {
333 global $ilDB;
334
335 $query = "
336 DELETE FROM qpl_hints
337 WHERE qht_hint_id = %s
338 ";
339
340 return $ilDB->manipulateF(
341 $query,
342 array('integer'),
343 array($hintId)
344 );
345 }
346
356 public static function getInstanceById($hintId)
357 {
358 $questionHint = new self();
359 $questionHint->load($hintId);
360 return $questionHint;
361 }
362
363 public function getPageObjectType()
364 {
366 }
367
368 public static function getHintIndexLabel(ilLanguage $lng, $hintIndex)
369 {
370 return sprintf($lng->txt('tst_question_hints_index_column_label'), $hintIndex);
371 }
372}
sprintf('%.4f', $callTime)
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
global $lng
Definition: privfeed.php:17
$query
foreach($_POST as $key=> $value) $res
global $ilDB