ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilLPStatusTestPassed.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
24
30{
31 public static function _getInProgress(int $a_obj_id): array
32 {
34 $a_obj_id,
35 'in_progress'
36 );
37 return $userIds;
38 }
39
40 public static function _getCompleted(int $a_obj_id): array
41 {
42 $userIds = self::getUserIdsByResultArrayStatus($a_obj_id, 'passed');
43 return $userIds;
44 }
45
46 public static function _getNotAttempted(int $a_obj_id): array
47 {
48 return self::getUserIdsByResultArrayStatus($a_obj_id, 'not_attempted');
49 }
50
51 public static function _getFailed(int $a_obj_id): array
52 {
53 return self::getUserIdsByResultArrayStatus($a_obj_id, 'failed');
54 }
55
56 private static function getUserIdsByResultArrayStatus(
57 $objId,
58 $resultArrayStatus
59 ) {
61
62 $user_ids = array();
63
64 foreach ($status_info['results'] as $user_data) {
65 if (isset($user_data[$resultArrayStatus]) && $user_data[$resultArrayStatus]) {
66 $user_ids[] = (int) $user_data['user_id'];
67 }
68 }
69
70 return $user_ids;
71 }
72
73 public static function _getStatusInfo(int $a_obj_id): array
74 {
76 $participant_repository = TestDIC::dic()['participant.repository'];
77 $test_id = ilObjTestAccess::_getTestIDFromObjectID($a_obj_id);
78
79 $lp_status = new self($a_obj_id);
80 $results = [];
81
82 foreach ($participant_repository->getParticipants($test_id) as $participant) {
83 $user_id = $participant->getUserId();
84 $status = $lp_status->determineStatus($a_obj_id, $user_id);
85
86 $results[] = [
87 'user_id' => $user_id,
88 'passed' => ($status === self::LP_STATUS_COMPLETED_NUM),
89 'failed' => ($status === self::LP_STATUS_FAILED_NUM),
90 'in_progress' => ($status === self::LP_STATUS_IN_PROGRESS_NUM),
91 'not_attempted' => ($status === self::LP_STATUS_NOT_ATTEMPTED_NUM)
92 ];
93 }
94
95 $status_info['results'] = $results;
96 return $status_info;
97 }
98
99 public function determineStatus(
100 int $a_obj_id,
101 int $a_usr_id,
102 ?object $a_obj = null
103 ): int {
105 $test_result_repository = TestDIC::dic()['results.data.repository'];
106
107 $old_status = ilLPStatus::_lookupStatus($a_obj_id, $a_usr_id, false);
109
110 $res = $this->db->query(
111 "
112 SELECT tst_active.active_id, tst_active.tries, count(tst_sequence.active_fi) " . $this->db->quoteIdentifier(
113 "sequences"
114 ) . ", tst_active.last_finished_pass,
115 CASE WHEN
116 (tst_test_settings.nr_of_tries - 1) = tst_active.last_finished_pass
117 THEN '1'
118 ELSE '0'
119 END is_last_pass
120 FROM tst_active
121 LEFT JOIN tst_sequence
122 ON tst_sequence.active_fi = tst_active.active_id
123 LEFT JOIN tst_tests
124 ON tst_tests.test_id = tst_active.test_fi
125 LEFT JOIN tst_test_settings
126 ON tst_test_settings.id = tst_tests.settings_id
127 WHERE tst_active.user_fi = {$this->db->quote($a_usr_id, "integer")}
128 AND tst_active.test_fi = {$this->db->quote(ilObjTestAccess::_getTestIDFromObjectID($a_obj_id), ilDBConstants::T_INTEGER)}
129 GROUP BY tst_active.active_id, tst_active.tries, is_last_pass
130 "
131 );
132
133 if (
134 ($rec = $this->db->fetchAssoc($res))
135 && $rec['sequences'] > 0
136 ) {
137 $test_obj = new ilObjTest($a_obj_id, false);
138 $is_passed = $test_result_repository->isPassed($a_usr_id, $a_obj_id);
139
140 if ($test_obj->getPassScoring() === ilObjTest::SCORE_LAST_PASS) {
141 $is_finished = false;
142 if ($rec['last_finished_pass'] !== null && $rec['sequences'] - 1 === $rec['last_finished_pass']) {
143 $is_finished = true;
144 }
146 $is_finished,
147 $is_passed
148 );
149 } elseif ($test_obj->getPassScoring() === ilObjTest::SCORE_BEST_PASS) {
151
152 if ($rec['last_finished_pass'] !== null) {
153 $status = $this->determineLpStatus($is_passed);
154 }
155 }
156 }
157
158 if ($old_status !== null
159 && $old_status !== self::LP_STATUS_NOT_ATTEMPTED_NUM
160 && $status === self::LP_STATUS_IN_PROGRESS_NUM) {
161 return $old_status;
162 }
163
164 return $status;
165 }
166
168 bool $is_finished,
169 bool $passed
170 ): int {
171 $status = self::LP_STATUS_IN_PROGRESS_NUM;
172
173 if ($is_finished) {
174 $status = $this->determineLpStatus($passed);
175 }
176
177 return $status;
178 }
179
180 protected function determineLpStatus(bool $passed): int
181 {
182 $status = self::LP_STATUS_FAILED_NUM;
183
184 if ($passed) {
185 $status = self::LP_STATUS_COMPLETED_NUM;
186 }
187
188 return $status;
189 }
190
191 public function determinePercentage(
192 int $a_obj_id,
193 int $a_usr_id,
194 ?object $a_obj = null
195 ): int {
196 $set = $this->db->query(
197 "SELECT tst_result_cache.*, tst_active.user_fi FROM " .
198 "tst_result_cache JOIN tst_active ON (tst_active.active_id = tst_result_cache.active_fi)" .
199 " JOIN tst_tests ON (tst_tests.test_id = tst_active.test_fi) " .
200 " WHERE tst_tests.obj_fi = " . $this->db->quote(
201 $a_obj_id,
202 "integer"
203 ) .
204 " AND tst_active.user_fi = " . $this->db->quote(
205 $a_usr_id,
206 "integer"
207 )
208 );
209 $per = 0;
210 if ($rec = $this->db->fetchAssoc($set)) {
211 if ($rec["max_points"] > 0) {
212 $per = (int) min(
213 100,
214 100 / $rec["max_points"] * $rec["reached_points"]
215 );
216 } else {
217 // According to mantis #12305
218 $per = 0;
219 }
220 }
221 return (int) $per;
222 }
223}
static _getNotAttempted(int $a_obj_id)
static getUserIdsByResultArrayStatus( $objId, $resultArrayStatus)
determineStatusForScoreLastPassTests(bool $is_finished, bool $passed)
determinePercentage(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
static _getFailed(int $a_obj_id)
static _getInProgress(int $a_obj_id)
static _getCompleted(int $a_obj_id)
static _getStatusInfo(int $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
determineStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
static _lookupStatus(int $a_obj_id, int $a_user_id, bool $a_create=true)
Lookup status.
static _getStatusInfo(int $a_obj_id)
static _getTestIDFromObjectID(int $object_id)
Returns the ILIAS test id for a given object id.
const SCORE_LAST_PASS
const SCORE_BEST_PASS
$res
Definition: ltiservices.php:69
$results
$objId
Definition: xapitoken.php:55