ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLPStatusTestPassed.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 include_once './Services/Tracking/classes/class.ilLPStatus.php';
34 
36 {
37 
38  function ilLPStatusTestPassed($a_obj_id)
39  {
40  global $ilDB;
41 
42  parent::ilLPStatus($a_obj_id);
43  $this->db =& $ilDB;
44  }
45 
46  function _getInProgress($a_obj_id)
47  {
48  global $ilDB;
49 
50  global $ilBench;
51  $ilBench->start('LearningProgress','9182_LPStatusTestPassed_inProgress');
52 
53 
54  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
55 
56  $query = "SELECT DISTINCT(user_fi) FROM tst_active ".
57  "WHERE test_fi = '".ilObjTestAccess::_getTestIDFromObjectID($a_obj_id)."'";
58 
59  $res = $ilDB->query($query);
60  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
61  {
62  $user_ids[] = $row->user_fi;
63  }
64 
65  $users = array_diff((array) $user_ids,ilLPStatusWrapper::_getCompleted($a_obj_id));
66  $users = array_diff((array) $users,ilLPStatusWrapper::_getFailed($a_obj_id));
67  $users = array_diff((array) $users,ilLPStatusWrapper::_getNotAttempted($a_obj_id));
68 
69  $ilBench->stop('LearningProgress','9182_LPStatusTestPassed_inProgress');
70  return $users ? $users : array();
71  }
72 
73  function _getCompleted($a_obj_id)
74  {
75  global $ilDB;
76 
77  global $ilBench;
78  $ilBench->start('LearningProgress','9183_LPStatusTestPassed_completed');
79 
80  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
81  include_once './Services/Tracking/classes/class.ilTestResultCache.php';
82 
83  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
84  foreach($status_info['results'] as $user_data)
85  {
86  if($user_data['passed'])
87  {
88  $user_ids[] = $user_data['user_id'];
89  }
90  }
91 
92  $ilBench->stop('LearningProgress','9183_LPStatusTestPassed_completed');
93  return $user_ids ? $user_ids : array();
94  }
95 
96  function _getNotAttempted($a_obj_id)
97  {
98  $user_ids = array();
99 
100  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
101 
102  foreach($status_info['results'] as $user_data)
103  {
104  if( !$user_data['failed'] && !$user_data['passed'] )
105  {
106  $user_ids[] = $user_data['user_id'];
107  }
108  }
109  return $user_ids;
110  }
111 
112  function _getFailed($a_obj_id)
113  {
114  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
115  foreach($status_info['results'] as $user_data)
116  {
117  if($user_data['failed'])
118  {
119  $user_ids[] = $user_data['user_id'];
120  }
121  }
122  return $user_ids ? $user_ids : array();
123  }
124 
125  function _getStatusInfo($a_obj_id)
126  {
127  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
128  $status_info['results'] = ilObjTestAccess::_getPassedUsers($a_obj_id);
129  return $status_info;
130  }
131 
164  function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
165  {
166  global $ilObjDataCache, $ilDB, $ilLog;
167 
168  $status = LP_STATUS_NOT_ATTEMPTED_NUM;
169 
170  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
171 
172  $res = $ilDB->query("
173  SELECT tst_active.active_id, tst_active.tries, count(tst_sequence.active_fi) sequences
174  FROM tst_active
175  LEFT JOIN tst_sequence
176  ON tst_sequence.active_fi = tst_active.active_id
177  WHERE tst_active.user_fi = {$ilDB->quote($a_user_id, "integer")}
178  AND tst_active.test_fi = {$ilDB->quote(ilObjTestAccess::_getTestIDFromObjectID($a_obj_id))}
179  GROUP BY tst_active.active_id, tst_active.tries
180  ");
181 
182  if ($rec = $ilDB->fetchAssoc($res))
183  {
184  if( $rec['sequences'] > 0 )
185  {
186  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
187  if (ilObjTestAccess::_isPassed($a_user_id, $a_obj_id))
188  {
189  $status = LP_STATUS_COMPLETED_NUM;
190  }
191  else
192  {
193  $status = LP_STATUS_FAILED_NUM;
194  }
195  }
196  else
197  {
198  $status = LP_STATUS_NOT_ATTEMPTED_NUM;
199  }
200  }
201 
202  return $status;
203  }
204 
213  function determinePercentage($a_obj_id, $a_user_id, $a_obj = null)
214  {
215  global $ilDB;
216 
217  $set = $ilDB->query("SELECT tst_result_cache.*, tst_active.user_fi FROM ".
218  "tst_result_cache JOIN tst_active ON (tst_active.active_id = tst_result_cache.active_fi)".
219  " JOIN tst_tests ON (tst_tests.test_id = tst_active.test_fi) ".
220  " WHERE tst_tests.obj_fi = ".$ilDB->quote($a_obj_id, "integer").
221  " AND tst_active.user_fi = ".$ilDB->quote($a_user_id, "integer"));
222  $per = 0;
223  if ($rec = $ilDB->fetchAssoc($set))
224  {
225  if ($rec["max_points"] > 0)
226  {
227  $per = min(100, 100 / $rec["max_points"] * $rec["reached_points"]);
228  }
229  else
230  {
231  // According to mantis #12305
232  $per = 0;
233  }
234  }
235  return (int) $per;
236  }
237 
238 
239 }
240 ?>