ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
71 return true;
72 }
73
74 return false;
75 }
76
85 public function getNumExistingRequests()
86 {
87 global $ilDB;
88
89 $query = "
90 SELECT COUNT(qhtr_track_id) cnt
91
92 FROM qpl_hint_tracking
93
94 WHERE qhtr_question_fi = %s
95 AND qhtr_active_fi = %s
96 AND qhtr_pass = %s
97 ";
98
99 $res = $ilDB->queryF(
100 $query, 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, array('integer', 'integer', 'integer'),
137 array($this->getActiveId(), $this->getPass(), $this->getQuestionId())
138 );
139
140 $row = $ilDB->fetchAssoc($res);
141
142 if( $row['cnt_available'] > $row['cnt_requested'] )
143 {
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, array('integer', 'integer', 'integer'), array($hintId, $this->getActiveId(), $this->getPass())
175 );
176
177 $row = $ilDB->fetchAssoc($res);
178
179 if( $row['cnt'] > 0 )
180 {
181 return true;
182 }
183
184 return false;
185 }
186
196 public function getNextRequestableHint()
197 {
198 global $ilDB;
199
200 $query = "
201 SELECT qht_hint_id
202
203 FROM qpl_hints
204
205 LEFT JOIN qpl_hint_tracking
206 ON qhtr_hint_fi = qht_hint_id
207 AND qhtr_active_fi = %s
208 AND qhtr_pass = %s
209
210 WHERE qht_question_fi = %s
211 AND qhtr_track_id IS NULL
212
213 ORDER BY qht_hint_index ASC
214 ";
215
216 $ilDB->setLimit(1);
217
218 $res = $ilDB->queryF(
219 $query, array('integer', 'integer', 'integer'),
220 array($this->getActiveId(), $this->getPass(), $this->getQuestionId())
221 );
222
223 while( $row = $ilDB->fetchAssoc($res) )
224 {
225 $nextHint = ilAssQuestionHint::getInstanceById($row['qht_hint_id']);
226
227 return $nextHint;
228 }
229
230 require_once 'Modules/Test/exceptions/class.ilTestNoNextRequestableHintExistsException.php';
231
233 "no next hint found for questionId={$this->getQuestionId()}, activeId={$this->getActiveId()}, pass={$this->getPass()}"
234 );
235 }
236
246 public function getRequestedHintsList()
247 {
248 global $ilDB;
249
250 $query = "
251 SELECT qhtr_hint_fi
252
253 FROM qpl_hint_tracking
254
255 WHERE qhtr_question_fi = %s
256 AND qhtr_active_fi = %s
257 AND qhtr_pass = %s
258 ";
259
260 $res = $ilDB->queryF(
261 $query, array('integer', 'integer', 'integer'),
262 array($this->getQuestionId(), $this->getActiveId(), $this->getPass())
263 );
264
265 $hintIds = array();
266
267 while( $row = $ilDB->fetchAssoc($res) )
268 {
269 $hintIds[] = $row['qhtr_hint_fi'];
270 }
271
272 $requestedHintsList = ilAssQuestionHintList::getListByHintIds($hintIds);
273
274 return $requestedHintsList;
275 }
276
285 public function storeRequest(ilAssQuestionHint $questionHint)
286 {
287 global $ilDB;
288
289 $trackId = $ilDB->nextId('qpl_hint_tracking');
290
291 $ilDB->insert('qpl_hint_tracking', array(
292 'qhtr_track_id' => array('integer', $trackId),
293 'qhtr_active_fi' => array('integer', $this->getActiveId()),
294 'qhtr_pass' => array('integer', $this->getPass()),
295 'qhtr_question_fi' => array('integer', $this->getQuestionId()),
296 'qhtr_hint_fi' => array('integer', $questionHint->getId()),
297 ));
298 }
299
312 {
313 global $ilDB;
314
315 $query = "
316 SELECT COUNT(qhtr_track_id) requests_count,
317 SUM(qht_hint_points) requests_points
318
319 FROM qpl_hint_tracking
320
321 INNER JOIN qpl_hints
322 ON qht_hint_id = qhtr_hint_fi
323
324 WHERE qhtr_question_fi = %s
325 AND qhtr_active_fi = %s
326 AND qhtr_pass = %s
327 ";
328
329 $res = $ilDB->queryF(
330 $query, array('integer', 'integer', 'integer'),
331 array($this->getQuestionId(), $this->getActiveId(), $this->getPass())
332 );
333
334 $row = $ilDB->fetchAssoc($res);
335
336 if( $row['requests_points'] === null )
337 {
338 $row['requests_points'] = 0;
339 }
340
341 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestStatisticData.php';
342
343 $requestsStatisticData = new ilAssQuestionHintRequestStatisticData();
344 $requestsStatisticData->setRequestsCount($row['requests_count']);
345 $requestsStatisticData->setRequestsPoints($row['requests_points']);
346
347 return $requestsStatisticData;
348 }
349
357 public function deleteRequestsByQuestionIds($questionIds)
358 {
359 global $ilDB;
360
361 $__question_fi__IN__questionIds = $ilDB->in('qhtr_question_fi', $questionIds, false, 'integer');
362
363 $query = "
364 DELETE FROM qpl_hint_tracking
365 WHERE $__question_fi__IN__questionIds
366 ";
367
368 $ilDB->manipulate($query);
369 }
370
378 public function deleteRequestsByActiveIds($activeIds)
379 {
380 global $ilDB;
381
382 $__active_fi__IN__activeIds = $ilDB->in('qhtr_active_fi', $activeIds, false, 'integer');
383
384 $query = "
385 DELETE FROM qpl_hint_tracking
386 WHERE $__active_fi__IN__activeIds
387 ";
388
389 $ilDB->manipulate($query);
390 }
391}
392
static getListByHintIds($hintIds)
instantiates a question hint list for the passed hint 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.
deleteRequestsByActiveIds($activeIds)
Deletes all hint requests relating to a testactive included in given active ids.
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.
getRequestedHintsList()
Returns an object of class ilAssQuestionHintList containing objects of class ilAssQuestionHint for al...
deleteRequestsByQuestionIds($questionIds)
Deletes all hint requests relating to a question included in given question ids.
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 $ilDB