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