ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
33include_once './Services/Tracking/classes/class.ilLPStatus.php';
34
36{
37
38 function __construct($a_obj_id)
39 {
40 global $ilDB;
41
42 parent::__construct($a_obj_id);
43 $this->db = $ilDB;
44 }
45
46 static function _getInProgress($a_obj_id)
47 {
48 global $ilBench;
49
50 $ilBench->start('LearningProgress','9182_LPStatusTestPassed_inProgress');
51 $userIds = self::getUserIdsByResultArrayStatus($a_obj_id, 'in_progress');
52 $ilBench->stop('LearningProgress','9182_LPStatusTestPassed_inProgress');
53
54 return $userIds;
55 }
56
57 static function _getCompleted($a_obj_id)
58 {
59 global $ilBench;
60
61 $ilBench->start('LearningProgress','9183_LPStatusTestPassed_completed');
62 $userIds = self::getUserIdsByResultArrayStatus($a_obj_id, 'passed');
63 $ilBench->stop('LearningProgress','9183_LPStatusTestPassed_completed');
64
65 return $userIds;
66 }
67
68 static function _getNotAttempted($a_obj_id)
69 {
70 return self::getUserIdsByResultArrayStatus($a_obj_id, 'not_attempted');
71 }
72
73 static function _getFailed($a_obj_id)
74 {
75 return self::getUserIdsByResultArrayStatus($a_obj_id, 'failed');
76 }
77
78 private static function getUserIdsByResultArrayStatus($objId, $resultArrayStatus)
79 {
80 $status_info = ilLPStatusWrapper::_getStatusInfo($objId);
81
82 $user_ids = array();
83
84 foreach($status_info['results'] as $user_data)
85 {
86 if($user_data[$resultArrayStatus])
87 {
88 $user_ids[] = $user_data['user_id'];
89 }
90 }
91
92 return $user_ids;
93 }
94
95 static function _getStatusInfo($a_obj_id)
96 {
97 include_once './Modules/Test/classes/class.ilObjTestAccess.php';
98 $status_info['results'] = ilObjTestAccess::_getPassedUsers($a_obj_id);
99 return $status_info;
100 }
101
134 function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
135 {
136 global $ilDB;
137
139 require_once 'Modules/Test/classes/class.ilObjTestAccess.php';
140 $res = $ilDB->query("
141 SELECT tst_active.active_id, tst_active.tries, count(tst_sequence.active_fi) " . $ilDB->quoteIdentifier("sequences") . ", tst_active.last_finished_pass,
142 CASE WHEN
143 (tst_tests.nr_of_tries - 1) = tst_active.last_finished_pass
144 THEN '1'
145 ELSE '0'
146 END is_last_pass
147 FROM tst_active
148 LEFT JOIN tst_sequence
149 ON tst_sequence.active_fi = tst_active.active_id
150 LEFT JOIN tst_tests
151 ON tst_tests.test_id = tst_active.test_fi
152 WHERE tst_active.user_fi = {$ilDB->quote($a_user_id, "integer")}
153 AND tst_active.test_fi = {$ilDB->quote(ilObjTestAccess::_getTestIDFromObjectID($a_obj_id))}
154 GROUP BY tst_active.active_id, tst_active.tries, is_last_pass
155 ");
156
157 if ($rec = $ilDB->fetchAssoc($res))
158 {
159 if( $rec['sequences'] > 0 )
160 {
161 require_once 'Modules/Test/classes/class.ilObjTest.php';
162
163 $test_obj = new ilObjTest($a_obj_id, false);
164 $is_passed = ilObjTestAccess::_isPassed($a_user_id, $a_obj_id);
165
166 if($test_obj->getPassScoring() == SCORE_LAST_PASS)
167 {
168 $is_finished = false;
169 if($rec['last_finished_pass'] != null && $rec['sequences'] - 1 == $rec['last_finished_pass'])
170 {
171 $is_finished = true;
172 }
173 $status = $this->determineStatusForScoreLastPassTests($is_finished, $is_passed);
174 }
175 else if($test_obj->getPassScoring() == SCORE_BEST_PASS)
176 {
178
179 if($rec['last_finished_pass'] != null)
180 {
181 $status = $this->determineLpStatus($is_passed);
182 }
183
184 if( !$rec['is_last_pass'] && $status == self::LP_STATUS_FAILED_NUM )
185 {
187 }
188 }
189 }
190 }
191
192 return $status;
193 }
194
200 protected function determineStatusForScoreLastPassTests($is_finished, $passed)
201 {
203
204 if($is_finished)
205 {
206 $status = $this->determineLpStatus($passed);
207 }
208
209 return $status;
210 }
211
216 protected function determineLpStatus($passed)
217 {
219
220 if ($passed)
221 {
223 }
224
225 return $status;
226 }
227
236 function determinePercentage($a_obj_id, $a_user_id, $a_obj = null)
237 {
238 global $ilDB;
239
240 $set = $ilDB->query("SELECT tst_result_cache.*, tst_active.user_fi FROM ".
241 "tst_result_cache JOIN tst_active ON (tst_active.active_id = tst_result_cache.active_fi)".
242 " JOIN tst_tests ON (tst_tests.test_id = tst_active.test_fi) ".
243 " WHERE tst_tests.obj_fi = ".$ilDB->quote($a_obj_id, "integer").
244 " AND tst_active.user_fi = ".$ilDB->quote($a_user_id, "integer"));
245 $per = 0;
246 if ($rec = $ilDB->fetchAssoc($set))
247 {
248 if ($rec["max_points"] > 0)
249 {
250 $per = min(100, 100 / $rec["max_points"] * $rec["reached_points"]);
251 }
252 else
253 {
254 // According to mantis #12305
255 $per = 0;
256 }
257 }
258 return (int) $per;
259 }
260
261
262}
263?>
An exception for terminatinating execution or to throw for unit testing.
determinePercentage($a_obj_id, $a_user_id, $a_obj=null)
Determine percentage.
determineStatusForScoreLastPassTests($is_finished, $passed)
static getUserIdsByResultArrayStatus($objId, $resultArrayStatus)
determineStatus($a_obj_id, $a_user_id, $a_obj=null)
Determine status.
static _getStatusInfo($a_obj_id)
Reads informations about the object e.g test results, tlt, number of visits.
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
const LP_STATUS_FAILED_NUM
static _getPassedUsers($a_obj_id)
Returns an array containing the users who passed the test.
static _isPassed($user_id, $a_obj_id)
Returns TRUE if the user with the user id $user_id passed the test with the object id $a_obj_id.
global $ilBench
Definition: ilias.php:18
const SCORE_BEST_PASS
const SCORE_LAST_PASS
global $ilDB