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