ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLPStatusCmiXapiAbstract.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
30{
31 protected array $cmixUserResult = array();
32
33 private static array $statusInfoCache = array();
34
35 public function getCmixUserResult(int $objId, int $usrId): ?\ilCmiXapiResult
36 {
37 if (!isset($this->cmixUserResult[$objId])) {
38 $this->cmixUserResult[$objId] = array();
39 }
40
41 if (!isset($this->cmixUserResult[$objId][$usrId])) {
42 try {
44 $this->cmixUserResult[$objId][$usrId] = $cmixUserResult;
45 } catch (ilCmiXapiException $e) {
46 $this->cmixUserResult[$objId][$usrId] = null;
47 }
48 }
49
50 return $this->cmixUserResult[$objId][$usrId];
51 }
52
58 protected function ensureObject(int $objId, ?ilObject $object = null): ?\ilObject
59 {
60 if (!($object instanceof ilObjCmiXapi)) {
62 }
63
64 return $object;
65 }
66
70 public static function _getNotAttempted(int $a_obj_id): array
71 {
73 $a_obj_id,
75 );
76 }
77
81 public static function _getInProgress(int $a_obj_id): array
82 {
84 $a_obj_id,
86 );
87 }
88
92 public static function _getCompleted(int $a_obj_id): array
93 {
95 $a_obj_id,
97 );
98 }
99
103 public static function _getFailed(int $a_obj_id): array
104 {
106 $a_obj_id,
108 );
109 }
110
114 private static function getUserIdsByLpStatusNum(int $objId, int $lpStatusNum): array
115 {
116 $statusInfo = self::_getStatusInfo($objId);
117 return $statusInfo[$lpStatusNum];
118 }
119
123 public static function _getStatusInfo(?int $a_obj_id): array
124 {
125 if (!isset(self::$statusInfoCache[$a_obj_id]) || self::$statusInfoCache[$a_obj_id] === null) {
126 self::$statusInfoCache[$a_obj_id] = self::loadStatusInfo($a_obj_id);
127 }
128
129 return self::$statusInfoCache[$a_obj_id];
130 }
131
135 private static function loadStatusInfo(int $a_obj_id): array
136 {
137 $statusInfo = [
142 ];
143
144 $cmixUsers = ilCmiXapiUser::getUsersForObject($a_obj_id);
145 $userResults = ilCmiXapiResult::getResultsForObject($a_obj_id);
146
147 foreach ($cmixUsers as $cmixUser) {
149
150 if (isset($userResults[$cmixUser->getUsrId()])) {
151 $userResult = $userResults[$cmixUser->getUsrId()];
152
153 if (self::_resultSatisfyCompleted($userResult, $a_obj_id)) {
155 }
156
157 if (self::_resultSatisfyFailed($userResult, $a_obj_id)) {
159 }
160 }
161
162 $statusInfo[$status][] = $cmixUser->getUsrId();
163 }
164
165 return $statusInfo;
166 }
167
171 public function determineStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj = null): int
172 {
173 $cmixUserResult = $this->getCmixUserResult($a_obj_id, $a_usr_id);
174
175 if ($cmixUserResult instanceof ilCmiXapiResult) {
176 if ($this->resultSatisfyCompleted($cmixUserResult)) {
178 }
179
180 if ($this->resultSatisfyFailed($cmixUserResult)) {
182 }
183
185 }
186
187 if (ilCmiXapiUser::exists($a_obj_id, $a_usr_id)) {
189 }
190
192 }
193
194 public function determinePercentage(int $a_obj_id, int $a_usr_id, ?object $a_obj = null): int
195 {
196 $cmixResult = $this->getCmixUserResult($a_obj_id, $a_usr_id);
197 if ($cmixResult == null) {
198 return 0;
199 }
200 return (int) round((100 * $cmixResult->getScore()));
201 }
202
203 abstract protected function resultSatisfyCompleted(ilCmiXapiResult $result): bool;
204
205 protected static function _resultSatisfyCompleted(ilCmiXapiResult $result, int $a_obj_id): bool
206 {
207 $lpStatusDetermination = new static($a_obj_id);
208 return $lpStatusDetermination->resultSatisfyCompleted($result);
209 }
210
211 abstract protected function resultSatisfyFailed(ilCmiXapiResult $result): bool;
212
213 protected static function _resultSatisfyFailed(ilCmiXapiResult $result, int $a_obj_id): bool
214 {
215 $lpStatusDetermination = new static($a_obj_id);
216 return $lpStatusDetermination->resultSatisfyFailed($result);
217 }
218}
static getInstanceByObjIdAndUsrId(int $objId, int $usrId)
static getResultsForObject(int $objId)
static exists(int $objId, int $usrId, int $privacyIdent=999)
static getUsersForObject(int $objId, bool $asUsrId=false)
determineStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
determinePercentage(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
static _resultSatisfyCompleted(ilCmiXapiResult $result, int $a_obj_id)
resultSatisfyCompleted(ilCmiXapiResult $result)
static _resultSatisfyFailed(ilCmiXapiResult $result, int $a_obj_id)
static getUserIdsByLpStatusNum(int $objId, int $lpStatusNum)
ensureObject(int $objId, ?ilObject $object=null)
resultSatisfyFailed(ilCmiXapiResult $result)
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 getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
Class ilObject Basic functions for all objects.
$objId
Definition: xapitoken.php:57