ILIAS  trunk Revision v11.0_alpha-1838-g59fc79e306b
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  ['integer', 'integer', 'integer'],
115  [$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  ['integer', 'integer', 'integer'],
153  [$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  ['integer', 'integer', 'integer'],
192  [$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  ['integer', 'integer', 'integer'],
239  [$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 
249  "no next hint found for questionId={$this->getQuestionId()}, activeId={$this->getActiveId()}, pass={$this->getPass()}"
250  );
251  }
252 
263  {
264  global $DIC;
265  $ilDB = $DIC['ilDB'];
266 
267  $query = "
268  SELECT qhtr_hint_fi
269 
270  FROM qpl_hint_tracking
271 
272  WHERE qhtr_question_fi = %s
273  AND qhtr_active_fi = %s
274  AND qhtr_pass = %s
275  ";
276 
277  $res = $ilDB->queryF(
278  $query,
279  ['integer', 'integer', 'integer'],
280  [$this->getQuestionId(), $this->getActiveId(), $this->getPass()]
281  );
282 
283  $hintIds = [];
284 
285  while ($row = $ilDB->fetchAssoc($res)) {
286  $hintIds[] = $row['qhtr_hint_fi'];
287  }
288 
289  $requestedHintsList = ilAssQuestionHintList::getListByHintIds($hintIds);
290 
291  return $requestedHintsList;
292  }
293 
302  public function storeRequest(ilAssQuestionHint $questionHint): void
303  {
304  global $DIC;
305  $ilDB = $DIC['ilDB'];
306 
307  $trackId = $ilDB->nextId('qpl_hint_tracking');
308 
309  $ilDB->insert('qpl_hint_tracking', [
310  'qhtr_track_id' => ['integer', $trackId],
311  'qhtr_active_fi' => ['integer', $this->getActiveId()],
312  'qhtr_pass' => ['integer', $this->getPass()],
313  'qhtr_question_fi' => ['integer', $this->getQuestionId()],
314  'qhtr_hint_fi' => ['integer', $questionHint->getId()],
315  ]);
316  }
317 
330  {
331  global $DIC;
332  $ilDB = $DIC['ilDB'];
333 
334  $query = "
335  SELECT COUNT(qhtr_track_id) requests_count,
336  SUM(qht_hint_points) requests_points
337 
338  FROM qpl_hint_tracking
339 
340  INNER JOIN qpl_hints
341  ON qht_hint_id = qhtr_hint_fi
342 
343  WHERE qhtr_question_fi = %s
344  AND qhtr_active_fi = %s
345  AND qhtr_pass = %s
346  ";
347 
348  $res = $ilDB->queryF(
349  $query,
350  ['integer', 'integer', 'integer'],
351  [$this->getQuestionId(), $this->getActiveId(), $this->getPass()]
352  );
353 
354  $row = $ilDB->fetchAssoc($res);
355 
356  if ($row['requests_points'] === null) {
357  $row['requests_points'] = 0;
358  }
359 
360  $requestsStatisticData = new ilAssQuestionHintRequestStatisticData();
361  $requestsStatisticData->setRequestsCount($row['requests_count']);
362  $requestsStatisticData->setRequestsPoints($row['requests_points']);
363 
364  return $requestsStatisticData;
365  }
366 
372  {
373  global $DIC;
374  $db = $DIC->database();
375 
376  $query = "
377  SELECT qhtr_pass requests_pass,
378  qhtr_question_fi requests_question,
379  COUNT(qhtr_track_id) requests_count,
380  SUM(qht_hint_points) requests_points
381 
382  FROM qpl_hint_tracking
383 
384  INNER JOIN qpl_hints
385  ON qht_hint_id = qhtr_hint_fi
386 
387  WHERE qhtr_active_fi = %s
388 
389  GROUP BY qhtr_pass, qhtr_question_fi
390  ";
391 
392  $res = $db->queryF(
393  $query,
394  ['integer'],
395  [$activeId]
396  );
397 
399 
400  while ($row = $db->fetchAssoc($res)) {
401  if ($row['requests_points'] === null) {
402  $row['requests_points'] = 0;
403  }
404 
405  $requestsStatisticData = new ilAssQuestionHintRequestStatisticData();
406  $requestsStatisticData->setRequestsCount($row['requests_count']);
407  $requestsStatisticData->setRequestsPoints($row['requests_points']);
408 
409  $register->addRequestByTestPassIndexAndQuestionId($row['requests_pass'], $row['requests_question'], $requestsStatisticData);
410  }
411 
412  return $register;
413  }
414 
419  public static function deleteRequestsByQuestionIds($questionIds): void
420  {
424  global $DIC;
425  $ilDB = $DIC['ilDB'];
426 
427  $__question_fi__IN__questionIds = $ilDB->in('qhtr_question_fi', $questionIds, false, 'integer');
428 
429  $query = "
430  DELETE FROM qpl_hint_tracking
431  WHERE $__question_fi__IN__questionIds
432  ";
433 
434  $ilDB->manipulate($query);
435  }
436 
444  public static function deleteRequestsByActiveIds($activeIds): void
445  {
446  global $DIC;
447  $ilDB = $DIC['ilDB'];
448 
449  $__active_fi__IN__activeIds = $ilDB->in('qhtr_active_fi', $activeIds, false, 'integer');
450 
451  $query = "
452  DELETE FROM qpl_hint_tracking
453  WHERE $__active_fi__IN__activeIds
454  ";
455 
456  $ilDB->manipulate($query);
457  }
458 }
$res
Definition: ltiservices.php:66
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...
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
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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
storeRequest(ilAssQuestionHint $questionHint)
Tracks the given hint as requested for the given question, testactive and testpass.
global $DIC
Definition: shib_login.php:22
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...