ILIAS  Release_4_2_x_branch Revision 61807
 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 
68  $ilBench->stop('LearningProgress','9182_LPStatusTestPassed_inProgress');
69  return $users ? $users : array();
70  }
71 
72  function _getCompleted($a_obj_id)
73  {
74  global $ilDB;
75 
76  global $ilBench;
77  $ilBench->start('LearningProgress','9183_LPStatusTestPassed_completed');
78 
79  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
80  include_once './Services/Tracking/classes/class.ilTestResultCache.php';
81 
82  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
83  foreach($status_info['results'] as $user_data)
84  {
85  if($user_data['passed'])
86  {
87  $user_ids[] = $user_data['user_id'];
88  }
89  }
90  $ilBench->stop('LearningProgress','9183_LPStatusTestPassed_completed');
91  return $user_ids ? $user_ids : array();
92  }
93 
94  function _getFailed($a_obj_id)
95  {
96  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
97  foreach($status_info['results'] as $user_data)
98  {
99  if($user_data['failed'])
100  {
101  $user_ids[] = $user_data['user_id'];
102  }
103  }
104  return $user_ids ? $user_ids : array();
105  }
106 
107  function _getStatusInfo($a_obj_id)
108  {
109  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
110  $status_info['results'] = ilObjTestAccess::_getPassedUsers($a_obj_id);
111  return $status_info;
112  }
113 
146  function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
147  {
148  global $ilObjDataCache, $ilDB, $ilLog;
149 
150  $status = LP_STATUS_NOT_ATTEMPTED_NUM;
151 
152  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
153 
154  $res = $ilDB->query("SELECT tries FROM tst_active".
155  " WHERE user_fi = ".$ilDB->quote($a_user_id, "integer").
156  " AND test_fi = ".$ilDB->quote(ilObjTestAccess::_getTestIDFromObjectID($a_obj_id)));
157 
158  if ($rec = $ilDB->fetchAssoc($res))
159  {
160  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
161  if (ilObjTestAccess::_isPassed($a_user_id, $a_obj_id))
162  {
163  $status = LP_STATUS_COMPLETED_NUM;
164  }
165  else
166  {
167  $status = LP_STATUS_FAILED_NUM;
168  }
169 
170  }
171 
172  return $status;
173  }
174 
183  function determinePercentage($a_obj_id, $a_user_id, $a_obj = null)
184  {
185  global $ilDB;
186 
187  $set = $ilDB->query("SELECT tst_result_cache.*, tst_active.user_fi FROM ".
188  "tst_result_cache JOIN tst_active ON (tst_active.active_id = tst_result_cache.active_fi)".
189  " JOIN tst_tests ON (tst_tests.test_id = tst_active.test_fi) ".
190  " WHERE tst_tests.obj_fi = ".$ilDB->quote($a_obj_id, "integer").
191  " AND tst_active.user_fi = ".$ilDB->quote($a_user_id, "integer"));
192  $per = 0;
193  if ($rec = $ilDB->fetchAssoc($set))
194  {
195  if ($rec["max_points"] > 0)
196  {
197  $per = min(100, 100 / $rec["max_points"] * $rec["reached_points"]);
198  }
199  else
200  {
201  $per = 100;
202  }
203  }
204  return (int) $per;
205  }
206 
207 
208 }
209 ?>