ILIAS  Release_4_4_x_branch Revision 61816
 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 
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 
91  $ilBench->stop('LearningProgress','9183_LPStatusTestPassed_completed');
92  return $user_ids ? $user_ids : array();
93  }
94 
95  function _getNotAttempted($a_obj_id)
96  {
97  $user_ids = array();
98 
99  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
100 
101  foreach($status_info['results'] as $user_data)
102  {
103  if( !$user_data['failed'] && !$user_data['passed'] )
104  {
105  $user_ids[] = $user_data['user_id'];
106  }
107  }
108  return $user_ids;
109  }
110 
111  function _getFailed($a_obj_id)
112  {
113  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
114  foreach($status_info['results'] as $user_data)
115  {
116  if($user_data['failed'])
117  {
118  $user_ids[] = $user_data['user_id'];
119  }
120  }
121  return $user_ids ? $user_ids : array();
122  }
123 
124  function _getStatusInfo($a_obj_id)
125  {
126  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
127  $status_info['results'] = ilObjTestAccess::_getPassedUsers($a_obj_id);
128  return $status_info;
129  }
130 
163  function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
164  {
165  global $ilObjDataCache, $ilDB, $ilLog;
166 
168 
169  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
170 
171  $res = $ilDB->query("
172  SELECT tst_active.active_id, tst_active.tries, count(tst_sequence.active_fi) sequences
173  FROM tst_active
174  LEFT JOIN tst_sequence
175  ON tst_sequence.active_fi = tst_active.active_id
176  WHERE tst_active.user_fi = {$ilDB->quote($a_user_id, "integer")}
177  AND tst_active.test_fi = {$ilDB->quote(ilObjTestAccess::_getTestIDFromObjectID($a_obj_id))}
178  GROUP BY tst_active.active_id, tst_active.tries
179  ");
180 
181  if ($rec = $ilDB->fetchAssoc($res))
182  {
183  if( $rec['sequences'] > 0 )
184  {
185  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
186  if (ilObjTestAccess::_isPassed($a_user_id, $a_obj_id))
187  {
189  }
190  else
191  {
192  $status = self::LP_STATUS_FAILED_NUM;
193  }
194  }
195  else
196  {
198  }
199  }
200 
201  return $status;
202  }
203 
212  function determinePercentage($a_obj_id, $a_user_id, $a_obj = null)
213  {
214  global $ilDB;
215 
216  $set = $ilDB->query("SELECT tst_result_cache.*, tst_active.user_fi FROM ".
217  "tst_result_cache JOIN tst_active ON (tst_active.active_id = tst_result_cache.active_fi)".
218  " JOIN tst_tests ON (tst_tests.test_id = tst_active.test_fi) ".
219  " WHERE tst_tests.obj_fi = ".$ilDB->quote($a_obj_id, "integer").
220  " AND tst_active.user_fi = ".$ilDB->quote($a_user_id, "integer"));
221  $per = 0;
222  if ($rec = $ilDB->fetchAssoc($set))
223  {
224  if ($rec["max_points"] > 0)
225  {
226  $per = min(100, 100 / $rec["max_points"] * $rec["reached_points"]);
227  }
228  else
229  {
230  // According to mantis #12305
231  $per = 0;
232  }
233  }
234  return (int) $per;
235  }
236 
237 
238 }
239 ?>