ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 require_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 $DIC;
87  $ilDB = $DIC['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,
101  array('integer', 'integer', 'integer'),
102  array($this->getQuestionId(), $this->getActiveId(), $this->getPass())
103  );
104 
105  $row = $ilDB->fetchAssoc($res);
106 
107  return $row['cnt'];
108  }
109 
118  public function requestsPossible()
119  {
120  global $DIC;
121  $ilDB = $DIC['ilDB'];
122 
123  $query = "
124  SELECT COUNT(qht_hint_id) cnt_available,
125  COUNT(qhtr_track_id) cnt_requested
126 
127  FROM qpl_hints
128 
129  LEFT JOIN qpl_hint_tracking
130  ON qhtr_hint_fi = qht_hint_id
131  AND qhtr_active_fi = %s
132  AND qhtr_pass = %s
133 
134  WHERE qht_question_fi = %s
135  ";
136 
137  $res = $ilDB->queryF(
138  $query,
139  array('integer', 'integer', 'integer'),
140  array($this->getActiveId(), $this->getPass(), $this->getQuestionId())
141  );
142 
143  $row = $ilDB->fetchAssoc($res);
144 
145  if ($row['cnt_available'] > $row['cnt_requested']) {
146  return true;
147  }
148 
149  return false;
150  }
151 
161  public function isRequested($hintId)
162  {
163  global $DIC;
164  $ilDB = $DIC['ilDB'];
165 
166  $query = "
167  SELECT COUNT(qhtr_track_id) cnt
168 
169  FROM qpl_hint_tracking
170 
171  WHERE qhtr_hint_fi = %s
172  AND qhtr_active_fi = %s
173  AND qhtr_pass = %s
174  ";
175 
176  $res = $ilDB->queryF(
177  $query,
178  array('integer', 'integer', 'integer'),
179  array($hintId, $this->getActiveId(), $this->getPass())
180  );
181 
182  $row = $ilDB->fetchAssoc($res);
183 
184  if ($row['cnt'] > 0) {
185  return true;
186  }
187 
188  return false;
189  }
190 
200  public function getNextRequestableHint()
201  {
202  global $DIC;
203  $ilDB = $DIC['ilDB'];
204 
205  $query = "
206  SELECT qht_hint_id
207 
208  FROM qpl_hints
209 
210  LEFT JOIN qpl_hint_tracking
211  ON qhtr_hint_fi = qht_hint_id
212  AND qhtr_active_fi = %s
213  AND qhtr_pass = %s
214 
215  WHERE qht_question_fi = %s
216  AND qhtr_track_id IS NULL
217 
218  ORDER BY qht_hint_index ASC
219  ";
220 
221  $ilDB->setLimit(1);
222 
223  $res = $ilDB->queryF(
224  $query,
225  array('integer', 'integer', 'integer'),
226  array($this->getActiveId(), $this->getPass(), $this->getQuestionId())
227  );
228 
229  while ($row = $ilDB->fetchAssoc($res)) {
230  $nextHint = ilAssQuestionHint::getInstanceById($row['qht_hint_id']);
231 
232  return $nextHint;
233  }
234 
235  require_once 'Modules/Test/exceptions/class.ilTestNoNextRequestableHintExistsException.php';
236 
238  "no next hint found for questionId={$this->getQuestionId()}, activeId={$this->getActiveId()}, pass={$this->getPass()}"
239  );
240  }
241 
251  public function getRequestedHintsList()
252  {
253  global $DIC;
254  $ilDB = $DIC['ilDB'];
255 
256  $query = "
257  SELECT qhtr_hint_fi
258 
259  FROM qpl_hint_tracking
260 
261  WHERE qhtr_question_fi = %s
262  AND qhtr_active_fi = %s
263  AND qhtr_pass = %s
264  ";
265 
266  $res = $ilDB->queryF(
267  $query,
268  array('integer', 'integer', 'integer'),
269  array($this->getQuestionId(), $this->getActiveId(), $this->getPass())
270  );
271 
272  $hintIds = array();
273 
274  while ($row = $ilDB->fetchAssoc($res)) {
275  $hintIds[] = $row['qhtr_hint_fi'];
276  }
277 
278  $requestedHintsList = ilAssQuestionHintList::getListByHintIds($hintIds);
279 
280  return $requestedHintsList;
281  }
282 
291  public function storeRequest(ilAssQuestionHint $questionHint)
292  {
293  global $DIC;
294  $ilDB = $DIC['ilDB'];
295 
296  $trackId = $ilDB->nextId('qpl_hint_tracking');
297 
298  $ilDB->insert('qpl_hint_tracking', array(
299  'qhtr_track_id' => array('integer', $trackId),
300  'qhtr_active_fi' => array('integer', $this->getActiveId()),
301  'qhtr_pass' => array('integer', $this->getPass()),
302  'qhtr_question_fi' => array('integer', $this->getQuestionId()),
303  'qhtr_hint_fi' => array('integer', $questionHint->getId()),
304  ));
305  }
306 
319  {
320  global $DIC;
321  $ilDB = $DIC['ilDB'];
322 
323  $query = "
324  SELECT COUNT(qhtr_track_id) requests_count,
325  SUM(qht_hint_points) requests_points
326 
327  FROM qpl_hint_tracking
328 
329  INNER JOIN qpl_hints
330  ON qht_hint_id = qhtr_hint_fi
331 
332  WHERE qhtr_question_fi = %s
333  AND qhtr_active_fi = %s
334  AND qhtr_pass = %s
335  ";
336 
337  $res = $ilDB->queryF(
338  $query,
339  array('integer', 'integer', 'integer'),
340  array($this->getQuestionId(), $this->getActiveId(), $this->getPass())
341  );
342 
343  $row = $ilDB->fetchAssoc($res);
344 
345  if ($row['requests_points'] === null) {
346  $row['requests_points'] = 0;
347  }
348 
349  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestStatisticData.php';
350 
351  $requestsStatisticData = new ilAssQuestionHintRequestStatisticData();
352  $requestsStatisticData->setRequestsCount($row['requests_count']);
353  $requestsStatisticData->setRequestsPoints($row['requests_points']);
354 
355  return $requestsStatisticData;
356  }
357 
363  {
364  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestStatisticRegister.php';
365  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestStatisticData.php';
366 
367  /* @var ILIAS\DI\Container $DIC */ global $DIC;
368  $db = $DIC->database();
369 
370  $query = "
371  SELECT qhtr_pass requests_pass,
372  qhtr_question_fi requests_question,
373  COUNT(qhtr_track_id) requests_count,
374  SUM(qht_hint_points) requests_points
375 
376  FROM qpl_hint_tracking
377 
378  INNER JOIN qpl_hints
379  ON qht_hint_id = qhtr_hint_fi
380 
381  WHERE qhtr_active_fi = %s
382 
383  GROUP BY qhtr_pass, qhtr_question_fi
384  ";
385 
386  $res = $db->queryF(
387  $query,
388  array('integer'),
389  array($activeId)
390  );
391 
393 
394  while ($row = $db->fetchAssoc($res)) {
395  if ($row['requests_points'] === null) {
396  $row['requests_points'] = 0;
397  }
398 
399  $requestsStatisticData = new ilAssQuestionHintRequestStatisticData();
400  $requestsStatisticData->setRequestsCount($row['requests_count']);
401  $requestsStatisticData->setRequestsPoints($row['requests_points']);
402 
403  $register->addRequestByTestPassIndexAndQuestionId($row['requests_pass'], $row['requests_question'], $requestsStatisticData);
404  }
405 
406  return $register;
407  }
408 
413  public static function deleteRequestsByQuestionIds($questionIds)
414  {
418  global $DIC;
419  $ilDB = $DIC['ilDB'];
420 
421  $__question_fi__IN__questionIds = $ilDB->in('qhtr_question_fi', $questionIds, false, 'integer');
422 
423  $query = "
424  DELETE FROM qpl_hint_tracking
425  WHERE $__question_fi__IN__questionIds
426  ";
427 
428  $ilDB->manipulate($query);
429  }
430 
438  public static function deleteRequestsByActiveIds($activeIds)
439  {
440  global $DIC;
441  $ilDB = $DIC['ilDB'];
442 
443  $__active_fi__IN__activeIds = $ilDB->in('qhtr_active_fi', $activeIds, false, 'integer');
444 
445  $query = "
446  DELETE FROM qpl_hint_tracking
447  WHERE $__active_fi__IN__activeIds
448  ";
449 
450  $ilDB->manipulate($query);
451  }
452 }
getNumExistingRequests()
Returns the number existing hint requests for the given question relating to the given testactive and...
static getInstanceById($hintId)
creates a hint object instance, loads the persisted hint dataset identified by passed hint id from da...
global $DIC
Definition: saml.php:7
getRequestedHintsList()
Returns an object of class ilAssQuestionHintList containing objects of class ilAssQuestionHint for al...
__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...
static getRequestRequestStatisticDataRegisterByActiveId($activeId)
requestsPossible()
Returns the fact wether (further) hint requests are possible for the given question relating to the g...
getId()
returns the hint id
getNextRequestableHint()
Returns the next requestable hint for given question relating to given testactive and testpass...
static getListByHintIds($hintIds)
instantiates a question hint list for the passed hint ids
foreach($_POST as $key=> $value) $res
storeRequest(ilAssQuestionHint $questionHint)
Tracks the given hint as requested for the given question, testactive and testpass.
$query
$row
global $ilDB
static deleteRequestsByActiveIds($activeIds)
Deletes all hint requests relating to a testactive included in given active ids.
requestsExist()
Returns the fact wether there exists hint requests for the given question relating to the given testa...