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