ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 throw new ilTestException(
231 "no next hint found for questionId={$this->getQuestionId()}, activeId={$this->getActiveId()}, pass={$this->getPass()}"
232 );
233 }
234
244 public function getRequestedHintsList()
245 {
246 global $ilDB;
247
248 $query = "
249 SELECT qhtr_hint_fi
250
251 FROM qpl_hint_tracking
252
253 WHERE qhtr_question_fi = %s
254 AND qhtr_active_fi = %s
255 AND qhtr_pass = %s
256 ";
257
258 $res = $ilDB->queryF(
259 $query, array('integer', 'integer', 'integer'),
260 array($this->getQuestionId(), $this->getActiveId(), $this->getPass())
261 );
262
263 $hintIds = array();
264
265 while( $row = $ilDB->fetchAssoc($res) )
266 {
267 $hintIds[] = $row['qhtr_hint_fi'];
268 }
269
270 $requestedHintsList = ilAssQuestionHintList::getListByHintIds($hintIds);
271
272 return $requestedHintsList;
273 }
274
283 public function storeRequest(ilAssQuestionHint $questionHint)
284 {
285 global $ilDB;
286
287 $trackId = $ilDB->nextId('qpl_hint_tracking');
288
289 $ilDB->insert('qpl_hint_tracking', array(
290 'qhtr_track_id' => array('integer', $trackId),
291 'qhtr_active_fi' => array('integer', $this->getActiveId()),
292 'qhtr_pass' => array('integer', $this->getPass()),
293 'qhtr_question_fi' => array('integer', $this->getQuestionId()),
294 'qhtr_hint_fi' => array('integer', $questionHint->getId()),
295 ));
296 }
297
310 {
311 global $ilDB;
312
313 $query = "
314 SELECT COUNT(qhtr_track_id) requests_count,
315 SUM(qht_hint_points) requests_points
316
317 FROM qpl_hint_tracking
318
319 INNER JOIN qpl_hints
320 ON qht_hint_id = qhtr_hint_fi
321
322 WHERE qhtr_question_fi = %s
323 AND qhtr_active_fi = %s
324 AND qhtr_pass = %s
325 ";
326
327 $res = $ilDB->queryF(
328 $query, array('integer', 'integer', 'integer'),
329 array($this->getQuestionId(), $this->getActiveId(), $this->getPass())
330 );
331
332 $row = $ilDB->fetchAssoc($res);
333
334 if( $row['requests_points'] === null )
335 {
336 $row['requests_points'] = 0;
337 }
338
339 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestStatisticData.php';
340
341 $requestsStatisticData = new ilAssQuestionHintRequestStatisticData();
342 $requestsStatisticData->setRequestsCount($row['requests_count']);
343 $requestsStatisticData->setRequestsPoints($row['requests_points']);
344
345 return $requestsStatisticData;
346 }
347
355 public function deleteRequestsByQuestionIds($questionIds)
356 {
357 global $ilDB;
358
359 $__question_fi__IN__questionIds = $ilDB->in('qhtr_question_fi', $questionIds, false, 'integer');
360
361 $query = "
362 DELETE FROM qpl_hint_tracking
363 WHERE $__question_fi__IN__questionIds
364 ";
365
366 $ilDB->manipulate($query);
367 }
368
376 public function deleteRequestsByActiveIds($activeIds)
377 {
378 global $ilDB;
379
380 $__active_fi__IN__activeIds = $ilDB->in('qhtr_active_fi', $activeIds, false, 'integer');
381
382 $query = "
383 DELETE FROM qpl_hint_tracking
384 WHERE $__active_fi__IN__activeIds
385 ";
386
387 $ilDB->manipulate($query);
388 }
389}
390
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
Base Exception for all Exceptions relating to Modules/Test.
global $ilDB