ILIAS  release_7 Revision v7.30-3-g800a261c036
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 = abs((float) $points);
155 }
156
163 public function getText()
164 {
165 return $this->text;
166 }
167
174 public function setText($text)
175 {
176 if ($text !== null) {
177 $this->text = $this->getHtmlQuestionContentPurifier()->purify($text);
178 }
179 }
180
190 public function load($id)
191 {
192 global $DIC;
193 $ilDB = $DIC['ilDB'];
194
195 $query = "
196 SELECT qht_hint_id,
197 qht_question_fi,
198 qht_hint_index,
199 qht_hint_points,
200 qht_hint_text
201
202 FROM qpl_hints
203
204 WHERE qht_hint_id = %s
205 ";
206
207 $res = $ilDB->queryF(
208 $query,
209 array('integer'),
210 array((int) $id)
211 );
212
213 while ($row = $ilDB->fetchAssoc($res)) {
214 self::assignDbRow($this, $row);
215
216 return true;
217 }
218
219 return false;
220 }
221
231 public function save()
232 {
233 if ($this->getId()) {
234 return $this->update();
235 } else {
236 return $this->insert();
237 }
238 }
239
248 private function update()
249 {
250 global $DIC;
251 $ilDB = $DIC['ilDB'];
252
253 return $ilDB->update(
254 'qpl_hints',
255 array(
256 'qht_question_fi' => array('integer', $this->getQuestionId()),
257 'qht_hint_index' => array('integer', $this->getIndex()),
258 'qht_hint_points' => array('float', $this->getPoints()),
259 'qht_hint_text' => array('clob', $this->getText())
260 ),
261 array(
262 'qht_hint_id' => array('integer', $this->getId())
263 )
264 );
265 }
266
275 private function insert()
276 {
277 global $DIC;
278 $ilDB = $DIC['ilDB'];
279
280 $this->setId($ilDB->nextId('qpl_hints'));
281
282 return $ilDB->insert('qpl_hints', array(
283 'qht_hint_id' => array('integer', $this->getId()),
284 'qht_question_fi' => array('integer', $this->getQuestionId()),
285 'qht_hint_index' => array('integer', $this->getIndex()),
286 'qht_hint_points' => array('float', $this->getPoints()),
287 'qht_hint_text' => array('clob', $this->getText())
288 ));
289 }
290
297 public function delete()
298 {
299 return self::deleteById($this->getId());
300 }
301
311 public static function assignDbRow(self $questionHint, $hintDbRow)
312 {
313 foreach ($hintDbRow as $field => $value) {
314 switch ($field) {
315 case 'qht_hint_id': $questionHint->setId($value); break;
316 case 'qht_question_fi': $questionHint->setQuestionId($value); break;
317 case 'qht_hint_index': $questionHint->setIndex($value); break;
318 case 'qht_hint_points': $questionHint->setPoints($value); break;
319 case 'qht_hint_text': $questionHint->setText($value); break;
320
321 default: throw new ilTestQuestionPoolException("invalid db field identifier ($field) given!");
322 }
323 }
324 }
325
336 public static function deleteById($hintId)
337 {
338 global $DIC;
339 $ilDB = $DIC['ilDB'];
340
341 $query = "
342 DELETE FROM qpl_hints
343 WHERE qht_hint_id = %s
344 ";
345
346 return $ilDB->manipulateF(
347 $query,
348 array('integer'),
349 array($hintId)
350 );
351 }
352
362 public static function getInstanceById($hintId)
363 {
364 $questionHint = new self();
365 $questionHint->load($hintId);
366 return $questionHint;
367 }
368
369 public function getPageObjectType()
370 {
372 }
373
374 public static function getHintIndexLabel(ilLanguage $lng, $hintIndex)
375 {
376 return sprintf($lng->txt('tst_question_hints_index_column_label'), $hintIndex);
377 }
378
379
381 {
382 return ilHtmlPurifierFactory::_getInstanceByType('qpl_usersolution');
383 }
384}
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)
static _getInstanceByType(string $type)
Factory method for creating purifier instances.
language handling
global $DIC
Definition: goto.php:24
$query
$lng
foreach($_POST as $key=> $value) $res
global $ilDB