ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilAssQuestionHintTracking.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/classes/class.ilAssQuestionHintList.php';
5
15{
16 private $questionId;
17
18 private $activeId;
19
20 private $pass;
21
23 {
24 $this->questionId = $questionId;
25 $this->activeId = $activeId;
26 $this->pass = $pass;
27 }
28
29 public function setActiveId($activeId)
30 {
31 $this->activeId = $activeId;
32 }
33
34 public function getActiveId()
35 {
36 return $this->activeId;
37 }
38
39 public function setPass($pass)
40 {
41 $this->pass = $pass;
42 }
43
44 public function getPass()
45 {
46 return $this->pass;
47 }
48
49 public function setQuestionId($questionId)
50 {
51 $this->questionId = $questionId;
52 }
53
54 public function getQuestionId()
55 {
56 return $this->questionId;
57 }
58
67 public function requestsExist()
68 {
69 if (self::getNumExistingRequests($this->getQuestionId(), $this->getActiveId(), $this->getPass()) > 0) {
70 return true;
71 }
72
73 return false;
74 }
75
84 public function getNumExistingRequests()
85 {
86 global $ilDB;
87
88 $query = "
89 SELECT COUNT(qhtr_track_id) cnt
90
91 FROM qpl_hint_tracking
92
93 WHERE qhtr_question_fi = %s
94 AND qhtr_active_fi = %s
95 AND qhtr_pass = %s
96 ";
97
98 $res = $ilDB->queryF(
99 $query,
100 array('integer', 'integer', 'integer'),
101 array($this->getQuestionId(), $this->getActiveId(), $this->getPass())
102 );
103
104 $row = $ilDB->fetchAssoc($res);
105
106 return $row['cnt'];
107 }
108
117 public function requestsPossible()
118 {
119 global $ilDB;
120
121 $query = "
122 SELECT COUNT(qht_hint_id) cnt_available,
123 COUNT(qhtr_track_id) cnt_requested
124
125 FROM qpl_hints
126
127 LEFT JOIN qpl_hint_tracking
128 ON qhtr_hint_fi = qht_hint_id
129 AND qhtr_active_fi = %s
130 AND qhtr_pass = %s
131
132 WHERE qht_question_fi = %s
133 ";
134
135 $res = $ilDB->queryF(
136 $query,
137 array('integer', 'integer', 'integer'),
138 array($this->getActiveId(), $this->getPass(), $this->getQuestionId())
139 );
140
141 $row = $ilDB->fetchAssoc($res);
142
143 if ($row['cnt_available'] > $row['cnt_requested']) {
144 return true;
145 }
146
147 return false;
148 }
149
159 public function isRequested($hintId)
160 {
161 global $ilDB;
162
163 $query = "
164 SELECT COUNT(qhtr_track_id) cnt
165
166 FROM qpl_hint_tracking
167
168 WHERE qhtr_hint_fi = %s
169 AND qhtr_active_fi = %s
170 AND qhtr_pass = %s
171 ";
172
173 $res = $ilDB->queryF(
174 $query,
175 array('integer', 'integer', 'integer'),
176 array($hintId, $this->getActiveId(), $this->getPass())
177 );
178
179 $row = $ilDB->fetchAssoc($res);
180
181 if ($row['cnt'] > 0) {
182 return true;
183 }
184
185 return false;
186 }
187
197 public function getNextRequestableHint()
198 {
199 global $ilDB;
200
201 $query = "
202 SELECT qht_hint_id
203
204 FROM qpl_hints
205
206 LEFT JOIN qpl_hint_tracking
207 ON qhtr_hint_fi = qht_hint_id
208 AND qhtr_active_fi = %s
209 AND qhtr_pass = %s
210
211 WHERE qht_question_fi = %s
212 AND qhtr_track_id IS NULL
213
214 ORDER BY qht_hint_index ASC
215 ";
216
217 $ilDB->setLimit(1);
218
219 $res = $ilDB->queryF(
220 $query,
221 array('integer', 'integer', 'integer'),
222 array($this->getActiveId(), $this->getPass(), $this->getQuestionId())
223 );
224
225 while ($row = $ilDB->fetchAssoc($res)) {
226 $nextHint = ilAssQuestionHint::getInstanceById($row['qht_hint_id']);
227
228 return $nextHint;
229 }
230
231 require_once 'Modules/Test/exceptions/class.ilTestNoNextRequestableHintExistsException.php';
232
234 "no next hint found for questionId={$this->getQuestionId()}, activeId={$this->getActiveId()}, pass={$this->getPass()}"
235 );
236 }
237
247 public function getRequestedHintsList()
248 {
249 global $ilDB;
250
251 $query = "
252 SELECT qhtr_hint_fi
253
254 FROM qpl_hint_tracking
255
256 WHERE qhtr_question_fi = %s
257 AND qhtr_active_fi = %s
258 AND qhtr_pass = %s
259 ";
260
261 $res = $ilDB->queryF(
262 $query,
263 array('integer', 'integer', 'integer'),
264 array($this->getQuestionId(), $this->getActiveId(), $this->getPass())
265 );
266
267 $hintIds = array();
268
269 while ($row = $ilDB->fetchAssoc($res)) {
270 $hintIds[] = $row['qhtr_hint_fi'];
271 }
272
273 $requestedHintsList = ilAssQuestionHintList::getListByHintIds($hintIds);
274
275 return $requestedHintsList;
276 }
277
286 public function storeRequest(ilAssQuestionHint $questionHint)
287 {
288 global $ilDB;
289
290 $trackId = $ilDB->nextId('qpl_hint_tracking');
291
292 $ilDB->insert('qpl_hint_tracking', array(
293 'qhtr_track_id' => array('integer', $trackId),
294 'qhtr_active_fi' => array('integer', $this->getActiveId()),
295 'qhtr_pass' => array('integer', $this->getPass()),
296 'qhtr_question_fi' => array('integer', $this->getQuestionId()),
297 'qhtr_hint_fi' => array('integer', $questionHint->getId()),
298 ));
299 }
300
313 {
314 global $ilDB;
315
316 $query = "
317 SELECT COUNT(qhtr_track_id) requests_count,
318 SUM(qht_hint_points) requests_points
319
320 FROM qpl_hint_tracking
321
322 INNER JOIN qpl_hints
323 ON qht_hint_id = qhtr_hint_fi
324
325 WHERE qhtr_question_fi = %s
326 AND qhtr_active_fi = %s
327 AND qhtr_pass = %s
328 ";
329
330 $res = $ilDB->queryF(
331 $query,
332 array('integer', 'integer', 'integer'),
333 array($this->getQuestionId(), $this->getActiveId(), $this->getPass())
334 );
335
336 $row = $ilDB->fetchAssoc($res);
337
338 if ($row['requests_points'] === null) {
339 $row['requests_points'] = 0;
340 }
341
342 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestStatisticData.php';
343
344 $requestsStatisticData = new ilAssQuestionHintRequestStatisticData();
345 $requestsStatisticData->setRequestsCount($row['requests_count']);
346 $requestsStatisticData->setRequestsPoints($row['requests_points']);
347
348 return $requestsStatisticData;
349 }
350
356 {
357 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestStatisticRegister.php';
358 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestStatisticData.php';
359
360 /* @var ILIAS\DI\Container $DIC */ global $DIC;
361 $db = $DIC->database();
362
363 $query = "
364 SELECT qhtr_pass requests_pass,
365 qhtr_question_fi requests_question,
366 COUNT(qhtr_track_id) requests_count,
367 SUM(qht_hint_points) requests_points
368
369 FROM qpl_hint_tracking
370
371 INNER JOIN qpl_hints
372 ON qht_hint_id = qhtr_hint_fi
373
374 WHERE qhtr_active_fi = %s
375
376 GROUP BY qhtr_pass, qhtr_question_fi
377 ";
378
379 $res = $db->queryF(
380 $query,
381 array('integer'),
382 array($activeId)
383 );
384
386
387 while ($row = $db->fetchAssoc($res)) {
388 if ($row['requests_points'] === null) {
389 $row['requests_points'] = 0;
390 }
391
392 $requestsStatisticData = new ilAssQuestionHintRequestStatisticData();
393 $requestsStatisticData->setRequestsCount($row['requests_count']);
394 $requestsStatisticData->setRequestsPoints($row['requests_points']);
395
396 $register->addRequestByTestPassIndexAndQuestionId($row['requests_pass'], $row['requests_question'], $requestsStatisticData);
397 }
398
399 return $register;
400 }
401
406 public static function deleteRequestsByQuestionIds($questionIds)
407 {
411 global $ilDB;
412
413 $__question_fi__IN__questionIds = $ilDB->in('qhtr_question_fi', $questionIds, false, 'integer');
414
415 $query = "
416 DELETE FROM qpl_hint_tracking
417 WHERE $__question_fi__IN__questionIds
418 ";
419
420 $ilDB->manipulate($query);
421 }
422
430 public static function deleteRequestsByActiveIds($activeIds)
431 {
432 global $ilDB;
433
434 $__active_fi__IN__activeIds = $ilDB->in('qhtr_active_fi', $activeIds, false, 'integer');
435
436 $query = "
437 DELETE FROM qpl_hint_tracking
438 WHERE $__active_fi__IN__activeIds
439 ";
440
441 $ilDB->manipulate($query);
442 }
443}
An exception for terminatinating execution or to throw for unit testing.
static getListByHintIds($hintIds)
instantiates a question hint list for the passed hint ids
static deleteRequestsByActiveIds($activeIds)
Deletes all hint requests relating to a testactive included in given active ids.
__construct($questionId, $activeId, $pass)
isRequested($hintId)
Returns the fact wether the hint for given id is requested for the given testactive and testpass.
getRequestStatisticDataByQuestionAndTestpass()
Returns a question hint request statistic data container containing the statistics for all requests r...
getNextRequestableHint()
Returns the next requestable hint for given question relating to given testactive and testpass.
requestsPossible()
Returns the fact wether (further) hint requests are possible for the given question relating to the g...
storeRequest(ilAssQuestionHint $questionHint)
Tracks the given hint as requested for the given question, testactive and testpass.
static getRequestRequestStatisticDataRegisterByActiveId($activeId)
getRequestedHintsList()
Returns an object of class ilAssQuestionHintList containing objects of class ilAssQuestionHint for al...
getNumExistingRequests()
Returns the number existing hint requests for the given question relating to the given testactive and...
requestsExist()
Returns the fact wether there exists hint requests for the given question relating to the given testa...
static getInstanceById($hintId)
creates a hint object instance, loads the persisted hint dataset identified by passed hint id from da...
getId()
returns the hint id
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB