ILIAS  release_8 Revision v8.24
class.ilAssQuestionHintTracking.php
Go to the documentation of this file.
1<?php
2
28{
29 private $questionId;
30
31 private $activeId;
32
33 private $pass;
34
36 {
37 $this->questionId = $questionId;
38 $this->activeId = $activeId;
39 $this->pass = $pass;
40 }
41
42 public function setActiveId($activeId): void
43 {
44 $this->activeId = $activeId;
45 }
46
47 public function getActiveId()
48 {
49 return $this->activeId;
50 }
51
52 public function setPass($pass): void
53 {
54 $this->pass = $pass;
55 }
56
57 public function getPass()
58 {
59 return $this->pass;
60 }
61
62 public function setQuestionId($questionId): void
63 {
64 $this->questionId = $questionId;
65 }
66
67 public function getQuestionId()
68 {
69 return $this->questionId;
70 }
71
80 public function requestsExist(): bool
81 {
82 if (self::getNumExistingRequests($this->getQuestionId(), $this->getActiveId(), $this->getPass()) > 0) {
83 return true;
84 }
85
86 return false;
87 }
88
97 public function getNumExistingRequests(): int
98 {
99 global $DIC;
100 $ilDB = $DIC['ilDB'];
101
102 $query = "
103 SELECT COUNT(qhtr_track_id) cnt
104
105 FROM qpl_hint_tracking
106
107 WHERE qhtr_question_fi = %s
108 AND qhtr_active_fi = %s
109 AND qhtr_pass = %s
110 ";
111
112 $res = $ilDB->queryF(
113 $query,
114 array('integer', 'integer', 'integer'),
115 array($this->getQuestionId(), $this->getActiveId(), $this->getPass())
116 );
117
118 $row = $ilDB->fetchAssoc($res);
119
120 return $row['cnt'];
121 }
122
131 public function requestsPossible(): bool
132 {
133 global $DIC;
134 $ilDB = $DIC['ilDB'];
135
136 $query = "
137 SELECT COUNT(qht_hint_id) cnt_available,
138 COUNT(qhtr_track_id) cnt_requested
139
140 FROM qpl_hints
141
142 LEFT JOIN qpl_hint_tracking
143 ON qhtr_hint_fi = qht_hint_id
144 AND qhtr_active_fi = %s
145 AND qhtr_pass = %s
146
147 WHERE qht_question_fi = %s
148 ";
149
150 $res = $ilDB->queryF(
151 $query,
152 array('integer', 'integer', 'integer'),
153 array($this->getActiveId(), $this->getPass(), $this->getQuestionId())
154 );
155
156 $row = $ilDB->fetchAssoc($res);
157
158 if ($row['cnt_available'] > $row['cnt_requested']) {
159 return true;
160 }
161
162 return false;
163 }
164
174 public function isRequested($hintId): bool
175 {
176 global $DIC;
177 $ilDB = $DIC['ilDB'];
178
179 $query = "
180 SELECT COUNT(qhtr_track_id) cnt
181
182 FROM qpl_hint_tracking
183
184 WHERE qhtr_hint_fi = %s
185 AND qhtr_active_fi = %s
186 AND qhtr_pass = %s
187 ";
188
189 $res = $ilDB->queryF(
190 $query,
191 array('integer', 'integer', 'integer'),
192 array($hintId, $this->getActiveId(), $this->getPass())
193 );
194
195 $row = $ilDB->fetchAssoc($res);
196
197 if ($row['cnt'] > 0) {
198 return true;
199 }
200
201 return false;
202 }
203
214 {
215 global $DIC;
216 $ilDB = $DIC['ilDB'];
217
218 $query = "
219 SELECT qht_hint_id
220
221 FROM qpl_hints
222
223 LEFT JOIN qpl_hint_tracking
224 ON qhtr_hint_fi = qht_hint_id
225 AND qhtr_active_fi = %s
226 AND qhtr_pass = %s
227
228 WHERE qht_question_fi = %s
229 AND qhtr_track_id IS NULL
230
231 ORDER BY qht_hint_index ASC
232 ";
233
234 $ilDB->setLimit(1);
235
236 $res = $ilDB->queryF(
237 $query,
238 array('integer', 'integer', 'integer'),
239 array($this->getActiveId(), $this->getPass(), $this->getQuestionId())
240 );
241
242 while ($row = $ilDB->fetchAssoc($res)) {
243 $nextHint = ilAssQuestionHint::getInstanceById($row['qht_hint_id']);
244
245 return $nextHint;
246 }
247
248 require_once 'Modules/Test/exceptions/class.ilTestNoNextRequestableHintExistsException.php';
249
251 "no next hint found for questionId={$this->getQuestionId()}, activeId={$this->getActiveId()}, pass={$this->getPass()}"
252 );
253 }
254
265 {
266 global $DIC;
267 $ilDB = $DIC['ilDB'];
268
269 $query = "
270 SELECT qhtr_hint_fi
271
272 FROM qpl_hint_tracking
273
274 WHERE qhtr_question_fi = %s
275 AND qhtr_active_fi = %s
276 AND qhtr_pass = %s
277 ";
278
279 $res = $ilDB->queryF(
280 $query,
281 array('integer', 'integer', 'integer'),
282 array($this->getQuestionId(), $this->getActiveId(), $this->getPass())
283 );
284
285 $hintIds = array();
286
287 while ($row = $ilDB->fetchAssoc($res)) {
288 $hintIds[] = $row['qhtr_hint_fi'];
289 }
290
291 $requestedHintsList = ilAssQuestionHintList::getListByHintIds($hintIds);
292
293 return $requestedHintsList;
294 }
295
304 public function storeRequest(ilAssQuestionHint $questionHint): void
305 {
306 global $DIC;
307 $ilDB = $DIC['ilDB'];
308
309 $trackId = $ilDB->nextId('qpl_hint_tracking');
310
311 $ilDB->insert('qpl_hint_tracking', array(
312 'qhtr_track_id' => array('integer', $trackId),
313 'qhtr_active_fi' => array('integer', $this->getActiveId()),
314 'qhtr_pass' => array('integer', $this->getPass()),
315 'qhtr_question_fi' => array('integer', $this->getQuestionId()),
316 'qhtr_hint_fi' => array('integer', $questionHint->getId()),
317 ));
318 }
319
332 {
333 global $DIC;
334 $ilDB = $DIC['ilDB'];
335
336 $query = "
337 SELECT COUNT(qhtr_track_id) requests_count,
338 SUM(qht_hint_points) requests_points
339
340 FROM qpl_hint_tracking
341
342 INNER JOIN qpl_hints
343 ON qht_hint_id = qhtr_hint_fi
344
345 WHERE qhtr_question_fi = %s
346 AND qhtr_active_fi = %s
347 AND qhtr_pass = %s
348 ";
349
350 $res = $ilDB->queryF(
351 $query,
352 array('integer', 'integer', 'integer'),
353 array($this->getQuestionId(), $this->getActiveId(), $this->getPass())
354 );
355
356 $row = $ilDB->fetchAssoc($res);
357
358 if ($row['requests_points'] === null) {
359 $row['requests_points'] = 0;
360 }
361
362 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestStatisticData.php';
363
364 $requestsStatisticData = new ilAssQuestionHintRequestStatisticData();
365 $requestsStatisticData->setRequestsCount($row['requests_count']);
366 $requestsStatisticData->setRequestsPoints($row['requests_points']);
367
368 return $requestsStatisticData;
369 }
370
376 {
377 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestStatisticRegister.php';
378 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestStatisticData.php';
379
380 /* @var ILIAS\DI\Container $DIC */ global $DIC;
381 $db = $DIC->database();
382
383 $query = "
384 SELECT qhtr_pass requests_pass,
385 qhtr_question_fi requests_question,
386 COUNT(qhtr_track_id) requests_count,
387 SUM(qht_hint_points) requests_points
388
389 FROM qpl_hint_tracking
390
391 INNER JOIN qpl_hints
392 ON qht_hint_id = qhtr_hint_fi
393
394 WHERE qhtr_active_fi = %s
395
396 GROUP BY qhtr_pass, qhtr_question_fi
397 ";
398
399 $res = $db->queryF(
400 $query,
401 array('integer'),
402 array($activeId)
403 );
404
406
407 while ($row = $db->fetchAssoc($res)) {
408 if ($row['requests_points'] === null) {
409 $row['requests_points'] = 0;
410 }
411
412 $requestsStatisticData = new ilAssQuestionHintRequestStatisticData();
413 $requestsStatisticData->setRequestsCount($row['requests_count']);
414 $requestsStatisticData->setRequestsPoints($row['requests_points']);
415
416 $register->addRequestByTestPassIndexAndQuestionId($row['requests_pass'], $row['requests_question'], $requestsStatisticData);
417 }
418
419 return $register;
420 }
421
426 public static function deleteRequestsByQuestionIds($questionIds): void
427 {
431 global $DIC;
432 $ilDB = $DIC['ilDB'];
433
434 $__question_fi__IN__questionIds = $ilDB->in('qhtr_question_fi', $questionIds, false, 'integer');
435
436 $query = "
437 DELETE FROM qpl_hint_tracking
438 WHERE $__question_fi__IN__questionIds
439 ";
440
441 $ilDB->manipulate($query);
442 }
443
451 public static function deleteRequestsByActiveIds($activeIds): void
452 {
453 global $DIC;
454 $ilDB = $DIC['ilDB'];
455
456 $__active_fi__IN__activeIds = $ilDB->in('qhtr_active_fi', $activeIds, false, 'integer');
457
458 $query = "
459 DELETE FROM qpl_hint_tracking
460 WHERE $__active_fi__IN__activeIds
461 ";
462
463 $ilDB->manipulate($query);
464 }
465}
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
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
$query