ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAssQuestionHintTracking.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintList.php';
6 
16 {
29  public static function requestsExist($questionId, $activeId, $pass)
30  {
31  if( self::getNumExistingRequests($questionId, $activeId, $pass) > 0 )
32  {
33  return true;
34  }
35 
36  return false;
37  }
38 
51  public static function getNumExistingRequests($questionId, $activeId, $pass)
52  {
53  global $ilDB;
54 
55  $query = "
56  SELECT COUNT(qhtr_track_id) cnt
57 
58  FROM qpl_hint_tracking
59 
60  WHERE qhtr_question_fi = %s
61  AND qhtr_active_fi = %s
62  AND qhtr_pass = %s
63  ";
64 
65  $res = $ilDB->queryF(
66  $query, array('integer', 'integer', 'integer'), array($questionId, $activeId, $pass)
67  );
68 
69  $row = $ilDB->fetchAssoc($res);
70 
71  return $row['cnt'];
72  }
73 
86  public static function requestsPossible($questionId, $activeId, $pass)
87  {
88  global $ilDB;
89 
90  $query = "
91  SELECT COUNT(qht_hint_id) cnt_available,
92  COUNT(qhtr_track_id) cnt_requested
93 
94  FROM qpl_hints
95 
96  LEFT JOIN qpl_hint_tracking
97  ON qhtr_hint_fi = qht_hint_id
98  AND qhtr_active_fi = %s
99  AND qhtr_pass = %s
100 
101  WHERE qht_question_fi = %s
102  ";
103 
104  $res = $ilDB->queryF(
105  $query, array('integer', 'integer', 'integer'), array($activeId, $pass, $questionId)
106  );
107 
108  $row = $ilDB->fetchAssoc($res);
109 
110  if( $row['cnt_available'] > $row['cnt_requested'] )
111  {
112  return true;
113  }
114 
115  return false;
116  }
117 
130  public static function isRequested($hintId, $activeId, $pass)
131  {
132  global $ilDB;
133 
134  $query = "
135  SELECT COUNT(qhtr_track_id) cnt
136 
137  FROM qpl_hint_tracking
138 
139  WHERE qhtr_hint_fi = %s
140  AND qhtr_active_fi = %s
141  AND qhtr_pass = %s
142  ";
143 
144  $res = $ilDB->queryF(
145  $query, array('integer', 'integer', 'integer'), array($hintId, $activeId, $pass)
146  );
147 
148  $row = $ilDB->fetchAssoc($res);
149 
150  if( $row['cnt'] > 0 )
151  {
152  return true;
153  }
154 
155  return false;
156  }
157 
171  public static function getNextRequestableHint($questionId, $activeId, $pass)
172  {
173  global $ilDB;
174 
175  $query = "
176  SELECT qht_hint_id
177 
178  FROM qpl_hints
179 
180  LEFT JOIN qpl_hint_tracking
181  ON qhtr_hint_fi = qht_hint_id
182  AND qhtr_active_fi = %s
183  AND qhtr_pass = %s
184 
185  WHERE qht_question_fi = %s
186  AND qhtr_track_id IS NULL
187 
188  ORDER BY qht_hint_index ASC
189  ";
190 
191  $ilDB->setLimit(1);
192 
193  $res = $ilDB->queryF(
194  $query, array('integer', 'integer', 'integer'), array($activeId, $pass, $questionId)
195  );
196 
197  while( $row = $ilDB->fetchAssoc($res) )
198  {
199  $nextHint = ilAssQuestionHint::getInstanceById($row['qht_hint_id']);
200 
201  return $nextHint;
202  }
203 
204  throw new ilTestException("no next hint found for questionId=$questionId, activeId=$activeId, pass=$pass");
205  }
206 
220  public static function getRequestedHintsList($questionId, $activeId, $pass)
221  {
222  global $ilDB;
223 
224  $query = "
225  SELECT qhtr_hint_fi
226 
227  FROM qpl_hint_tracking
228 
229  WHERE qhtr_question_fi = %s
230  AND qhtr_active_fi = %s
231  AND qhtr_pass = %s
232  ";
233 
234  $res = $ilDB->queryF(
235  $query, array('integer', 'integer', 'integer'), array($questionId, $activeId, $pass)
236  );
237 
238  $hintIds = array();
239 
240  while( $row = $ilDB->fetchAssoc($res) )
241  {
242  $hintIds[] = $row['qhtr_hint_fi'];
243  }
244 
245  $requestedHintsList = ilAssQuestionHintList::getListByHintIds($hintIds);
246 
247  return $requestedHintsList;
248  }
249 
262  public static function storeRequest(ilAssQuestionHint $questionHint, $questionId, $activeId, $pass)
263  {
264  global $ilDB;
265 
266  $trackId = $ilDB->nextId('qpl_hint_tracking');
267 
268  $ilDB->insert('qpl_hint_tracking', array(
269  'qhtr_track_id' => array('integer', $trackId),
270  'qhtr_active_fi' => array('integer', $activeId),
271  'qhtr_pass' => array('integer', $pass),
272  'qhtr_question_fi' => array('integer', $questionId),
273  'qhtr_hint_fi' => array('integer', $questionHint->getId()),
274  ));
275  }
276 
292  public static function getRequestStatisticDataByQuestionAndTestpass($questionId, $activeId, $pass)
293  {
294  global $ilDB;
295 
296  $query = "
297  SELECT COUNT(qhtr_track_id) requests_count,
298  SUM(qht_hint_points) requests_points
299 
300  FROM qpl_hint_tracking
301 
302  INNER JOIN qpl_hints
303  ON qht_hint_id = qhtr_hint_fi
304 
305  WHERE qhtr_question_fi = %s
306  AND qhtr_active_fi = %s
307  AND qhtr_pass = %s
308  ";
309 
310  $res = $ilDB->queryF(
311  $query, array('integer', 'integer', 'integer'), array($questionId, $activeId, $pass)
312  );
313 
314  $row = $ilDB->fetchAssoc($res);
315 
316  if( $row['requests_points'] === null )
317  {
318  $row['requests_points'] = 0;
319  }
320 
321  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestStatisticData.php';
322 
323  $requestsStatisticData = new ilAssQuestionHintRequestStatisticData();
324  $requestsStatisticData->setRequestsCount($row['requests_count']);
325  $requestsStatisticData->setRequestsPoints($row['requests_points']);
326 
327  return $requestsStatisticData;
328  }
329 
338  public static function deleteRequestsByQuestionIds($questionIds)
339  {
340  global $ilDB;
341 
342  $__question_fi__IN__questionIds = $ilDB->in('qhtr_question_fi', $questionIds, false, 'integer');
343 
344  $query = "
345  DELETE FROM qpl_hint_tracking
346  WHERE $__question_fi__IN__questionIds
347  ";
348 
349  $ilDB->manipulate($query);
350  }
351 
360  public static function deleteRequestsByActiveIds($activeIds)
361  {
362  global $ilDB;
363 
364  $__active_fi__IN__activeIds = $ilDB->in('qhtr_active_fi', $activeIds, false, 'integer');
365 
366  $query = "
367  DELETE FROM qpl_hint_tracking
368  WHERE $__active_fi__IN__activeIds
369  ";
370 
371  $ilDB->manipulate($query);
372  }
373 }
374