ILIAS  release_8 Revision v8.24
class.ilAssQuestionPreviewHintTracking.php
Go to the documentation of this file.
1<?php
2
26{
30 private $db;
31
36
38 {
39 $this->db = $db;
40 $this->previewSession = $previewSession;
41 }
42
43 public function requestsExist(): bool
44 {
45 return (
46 $this->previewSession->getNumRequestedHints() > 0
47 );
48 }
49
50 public function requestsPossible(): bool
51 {
52 $query = "
53 SELECT COUNT(qht_hint_id) cnt_available
54 FROM qpl_hints
55 WHERE qht_question_fi = %s
56 ";
57
58 $res = $this->db->queryF(
59 $query,
60 array('integer'),
61 array($this->previewSession->getQuestionId())
62 );
63
64 $row = $this->db->fetchAssoc($res);
65
66 if ($row['cnt_available'] > $this->previewSession->getNumRequestedHints()) {
67 return true;
68 }
69
70 return false;
71 }
72
74 {
75 $query = "
76 SELECT qht_hint_id
77
78 FROM qpl_hints
79
80 WHERE qht_question_fi = %s
81
82 ORDER BY qht_hint_index ASC
83 ";
84
85 $res = $this->db->queryF(
86 $query,
87 array('integer'),
88 array($this->previewSession->getQuestionId())
89 );
90
91 while ($row = $this->db->fetchAssoc($res)) {
92 if (!$this->isRequested($row['qht_hint_id'])) {
93 return ilAssQuestionHint::getInstanceById($row['qht_hint_id']);
94 }
95 }
96
97 throw new ilTestException(
98 "no next hint found for questionId={$this->previewSession->getQuestionId()}, userId={$this->previewSession->getUserId()}"
99 );
100 }
101
102 public function storeRequest(ilAssQuestionHint $questionHint): void
103 {
104 $this->previewSession->addRequestedHint($questionHint->getId());
105 }
106
107 public function isRequested($hintId): bool
108 {
109 return $this->previewSession->isHintRequested($hintId);
110 }
111
112 public function getNumExistingRequests(): int
113 {
114 return $this->previewSession->getNumRequestedHints();
115 }
116
118 {
119 $hintIds = $this->previewSession->getRequestedHints();
120
121 $requestedHintsList = ilAssQuestionHintList::getListByHintIds($hintIds);
122
123 return $requestedHintsList;
124 }
125
127 {
128 $count = 0;
129 $points = 0;
130
131 foreach ($this->getRequestedHintsList() as $hint) {
132 $count++;
133 $points += $hint->getPoints();
134 }
135
136 $requestsStatisticData = new ilAssQuestionHintRequestStatisticData();
137 $requestsStatisticData->setRequestsCount($count);
138 $requestsStatisticData->setRequestsPoints($points);
139
140 return $requestsStatisticData;
141 }
142}
static getListByHintIds($hintIds)
instantiates a question hint list for the passed hint ids
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
__construct(ilDBInterface $db, ilAssQuestionPreviewSession $previewSession)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query