ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilLPStatusCmiXapiAbstract.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
15{
16 protected $cmixUserResult = array();
17
18 private static $statusInfoCache = array();
19
25 public function getCmixUserResult($objId, $usrId)
26 {
27 if (!isset($this->cmixUserResult[$objId])) {
28 $this->cmixUserResult[$objId] = array();
29 }
30
31 if (!isset($this->cmixUserResult[$objId][$usrId])) {
32 try {
34 $this->cmixUserResult[$objId][$usrId] = $cmixUserResult;
35 } catch (ilCmiXapiException $e) {
36 $this->cmixUserResult[$objId][$usrId] = null;
37 }
38 }
39
40 return $this->cmixUserResult[$objId][$usrId];
41 }
42
48 protected function ensureObject($objId, $object = null)
49 {
50 if (!($object instanceof ilObjCmiXapi)) {
52 }
53
54 return $object;
55 }
56
57 public static function _getNotAttempted($a_obj_id)
58 {
60 $a_obj_id,
62 );
63 }
64
65 public static function _getInProgress($a_obj_id)
66 {
68 $a_obj_id,
70 );
71 }
72
73 public static function _getCompleted($a_obj_id)
74 {
76 $a_obj_id,
78 );
79 }
80
81 public static function _getFailed($a_obj_id)
82 {
84 $a_obj_id,
86 );
87 }
88
89 private static function getUserIdsByLpStatusNum($objId, $lpStatusNum)
90 {
91 $statusInfo = self::_getStatusInfo($objId);
92 return $statusInfo[$lpStatusNum];
93 }
94
95 public static function _getStatusInfo($a_obj_id)
96 {
97 if (self::$statusInfoCache[$a_obj_id] === null) {
98 self::$statusInfoCache[$a_obj_id] = self::loadStatusInfo($a_obj_id);
99 }
100
101 return self::$statusInfoCache[$a_obj_id];
102 }
103
104 private static function loadStatusInfo($a_obj_id)
105 {
106 $statusInfo = [
111 ];
112
113 $cmixUsers = ilCmiXapiUser::getUsersForObject($a_obj_id);
114 $userResults = ilCmiXapiResult::getResultsForObject($a_obj_id);
115
116 foreach ($cmixUsers as $cmixUser) {
118
119 if (isset($userResults[$cmixUser->getUsrId()])) {
120 $userResult = $userResults[$cmixUser->getUsrId()];
121
122 if (self::_resultSatisfyCompleted($userResult, $a_obj_id)) {
124 }
125
126 if (self::_resultSatisfyFailed($userResult, $a_obj_id)) {
128 }
129 }
130
131 $statusInfo[$status][] = $cmixUser->getUsrId();
132 }
133
134 return $statusInfo;
135 }
136
137 public function determineStatus($a_obj_id, $a_usr_id, $a_obj = null)
138 {
139 $cmixUserResult = $this->getCmixUserResult($a_obj_id, $a_usr_id);
140
141 if ($cmixUserResult instanceof ilCmiXapiResult) {
144 }
145
148 }
149
151 }
152
153 if (ilCmiXapiUser::exists($a_obj_id, $a_usr_id)) {
155 }
156
158 }
159
160 public function determinePercentage($a_obj_id, $a_usr_id, $a_obj = null)
161 {
162 $cmixResult = $this->getCmixUserResult($a_obj_id, $a_usr_id);
163
164 if ($cmixResult instanceof ilCmiXapiResult) {
165 return 100 * (float) $cmixResult->getScore();
166 }
167
168 return 0;
169 }
170
175 abstract protected function resultSatisfyCompleted(ilCmiXapiResult $result);
176
182 protected static function _resultSatisfyCompleted(ilCmiXapiResult $result, $a_obj_id)
183 {
184 $lpStatusDetermination = new static($a_obj_id);
185 return $lpStatusDetermination->resultSatisfyCompleted($result);
186 }
187
192 abstract protected function resultSatisfyFailed(ilCmiXapiResult $result);
193
199 protected static function _resultSatisfyFailed(ilCmiXapiResult $result, $a_obj_id)
200 {
201 $lpStatusDetermination = new static($a_obj_id);
202 return $lpStatusDetermination->resultSatisfyFailed($result);
203 }
204}
$result
An exception for terminatinating execution or to throw for unit testing.
static getInstanceByObjIdAndUsrId($objId, $usrId)
static getResultsForObject($objId)
static getUsersForObject($objId, $asUsrId=false)
static exists($objId, $usrId, $privacyIdent=999)
determineStatus($a_obj_id, $a_usr_id, $a_obj=null)
Determine status.
static _resultSatisfyCompleted(ilCmiXapiResult $result, $a_obj_id)
static getUserIdsByLpStatusNum($objId, $lpStatusNum)
resultSatisfyCompleted(ilCmiXapiResult $result)
static _resultSatisfyFailed(ilCmiXapiResult $result, $a_obj_id)
resultSatisfyFailed(ilCmiXapiResult $result)
determinePercentage($a_obj_id, $a_usr_id, $a_obj=null)
Determine percentage.
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($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
$objId
Definition: xapitoken.php:41