ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 public function __construct($a_obj_id)
38 {
39 global $ilDB;
40
41 parent::__construct($a_obj_id);
42 $this->db = $ilDB;
43 }
44
45 public static function _getInProgress($a_obj_id)
46 {
47 global $ilBench;
48
49 $ilBench->start('LearningProgress', '9182_LPStatusTestPassed_inProgress');
50 $userIds = self::getUserIdsByResultArrayStatus($a_obj_id, 'in_progress');
51 $ilBench->stop('LearningProgress', '9182_LPStatusTestPassed_inProgress');
52
53 return $userIds;
54 }
55
56 public static function _getCompleted($a_obj_id)
57 {
58 global $ilBench;
59
60 $ilBench->start('LearningProgress', '9183_LPStatusTestPassed_completed');
61 $userIds = self::getUserIdsByResultArrayStatus($a_obj_id, 'passed');
62 $ilBench->stop('LearningProgress', '9183_LPStatusTestPassed_completed');
63
64 return $userIds;
65 }
66
67 public static function _getNotAttempted($a_obj_id)
68 {
69 return self::getUserIdsByResultArrayStatus($a_obj_id, 'not_attempted');
70 }
71
72 public static function _getFailed($a_obj_id)
73 {
74 return self::getUserIdsByResultArrayStatus($a_obj_id, 'failed');
75 }
76
77 private static function getUserIdsByResultArrayStatus($objId, $resultArrayStatus)
78 {
79 $status_info = ilLPStatusWrapper::_getStatusInfo($objId);
80
81 $user_ids = array();
82
83 foreach ($status_info['results'] as $user_data) {
84 if ($user_data[$resultArrayStatus]) {
85 $user_ids[] = $user_data['user_id'];
86 }
87 }
88
89 return $user_ids;
90 }
91
92 public static function _getStatusInfo($a_obj_id)
93 {
94 include_once './Modules/Test/classes/class.ilObjTestAccess.php';
95 $status_info['results'] = ilObjTestAccess::_getPassedUsers($a_obj_id);
96 return $status_info;
97 }
98
131 public function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
132 {
133 global $ilDB;
134
136 require_once 'Modules/Test/classes/class.ilObjTestAccess.php';
137 $res = $ilDB->query("
138 SELECT tst_active.active_id, tst_active.tries, count(tst_sequence.active_fi) " . $ilDB->quoteIdentifier("sequences") . ", tst_active.last_finished_pass,
139 CASE WHEN
140 (tst_tests.nr_of_tries - 1) = tst_active.last_finished_pass
141 THEN '1'
142 ELSE '0'
143 END is_last_pass
144 FROM tst_active
145 LEFT JOIN tst_sequence
146 ON tst_sequence.active_fi = tst_active.active_id
147 LEFT JOIN tst_tests
148 ON tst_tests.test_id = tst_active.test_fi
149 WHERE tst_active.user_fi = {$ilDB->quote($a_user_id, "integer")}
150 AND tst_active.test_fi = {$ilDB->quote(ilObjTestAccess::_getTestIDFromObjectID($a_obj_id))}
151 GROUP BY tst_active.active_id, tst_active.tries, is_last_pass
152 ");
153
154 if ($rec = $ilDB->fetchAssoc($res)) {
155 if ($rec['sequences'] > 0) {
156 require_once 'Modules/Test/classes/class.ilObjTest.php';
157
158 $test_obj = new ilObjTest($a_obj_id, false);
159 $is_passed = ilObjTestAccess::_isPassed($a_user_id, $a_obj_id);
160
161 if ($test_obj->getPassScoring() == SCORE_LAST_PASS) {
162 $is_finished = false;
163 if ($rec['last_finished_pass'] != null && $rec['sequences'] - 1 == $rec['last_finished_pass']) {
164 $is_finished = true;
165 }
166 $status = $this->determineStatusForScoreLastPassTests($is_finished, $is_passed);
167 } elseif ($test_obj->getPassScoring() == SCORE_BEST_PASS) {
169
170 if ($rec['last_finished_pass'] != null) {
171 $status = $this->determineLpStatus($is_passed);
172 }
173
174 if (!$rec['is_last_pass'] && $status == self::LP_STATUS_FAILED_NUM) {
176 }
177 }
178 }
179 }
180
181 return $status;
182 }
183
189 protected function determineStatusForScoreLastPassTests($is_finished, $passed)
190 {
192
193 if ($is_finished) {
194 $status = $this->determineLpStatus($passed);
195 }
196
197 return $status;
198 }
199
204 protected function determineLpStatus($passed)
205 {
207
208 if ($passed) {
210 }
211
212 return $status;
213 }
214
223 public function determinePercentage($a_obj_id, $a_user_id, $a_obj = null)
224 {
225 global $ilDB;
226
227 $set = $ilDB->query("SELECT tst_result_cache.*, tst_active.user_fi FROM " .
228 "tst_result_cache JOIN tst_active ON (tst_active.active_id = tst_result_cache.active_fi)" .
229 " JOIN tst_tests ON (tst_tests.test_id = tst_active.test_fi) " .
230 " WHERE tst_tests.obj_fi = " . $ilDB->quote($a_obj_id, "integer") .
231 " AND tst_active.user_fi = " . $ilDB->quote($a_user_id, "integer"));
232 $per = 0;
233 if ($rec = $ilDB->fetchAssoc($set)) {
234 if ($rec["max_points"] > 0) {
235 $per = min(100, 100 / $rec["max_points"] * $rec["reached_points"]);
236 } else {
237 // According to mantis #12305
238 $per = 0;
239 }
240 }
241 return (int) $per;
242 }
243}
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
foreach($_POST as $key=> $value) $res
global $ilDB