ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
14 abstract class ilLPStatusCmiXapiAbstract extends ilLPStatus
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  {
59  return self::getUserIdsByLpStatusNum(
60  $a_obj_id,
62  );
63  }
64 
65  public static function _getInProgress($a_obj_id)
66  {
67  return self::getUserIdsByLpStatusNum(
68  $a_obj_id,
70  );
71  }
72 
73  public static function _getCompleted($a_obj_id)
74  {
75  return self::getUserIdsByLpStatusNum(
76  $a_obj_id,
78  );
79  }
80 
81  public static function _getFailed($a_obj_id)
82  {
83  return self::getUserIdsByLpStatusNum(
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) {
143  return self::LP_STATUS_COMPLETED_NUM;
144  }
145 
146  if ($this->resultSatisfyFailed($cmixUserResult)) {
147  return self::LP_STATUS_FAILED_NUM;
148  }
149 
150  return self::LP_STATUS_IN_PROGRESS_NUM;
151  }
152 
153  if (ilCmiXapiUser::exists($a_obj_id, $a_usr_id)) {
154  return self::LP_STATUS_IN_PROGRESS_NUM;
155  }
156 
157  return self::LP_STATUS_NOT_ATTEMPTED_NUM;
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 }
const LP_STATUS_COMPLETED_NUM
static getResultsForObject($objId)
static _resultSatisfyFailed(ilCmiXapiResult $result, $a_obj_id)
static getUsersForObject($objId, $asUsrId=false)
$result
const LP_STATUS_IN_PROGRESS_NUM
determinePercentage($a_obj_id, $a_usr_id, $a_obj=null)
$objId
Definition: xapitoken.php:41
determineStatus($a_obj_id, $a_usr_id, $a_obj=null)
resultSatisfyCompleted(ilCmiXapiResult $result)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static getInstanceByObjIdAndUsrId($objId, $usrId)
static _resultSatisfyCompleted(ilCmiXapiResult $result, $a_obj_id)
const LP_STATUS_NOT_ATTEMPTED_NUM
static exists($objId, $usrId, $privacyIdent=999)
static getUserIdsByLpStatusNum($objId, $lpStatusNum)
resultSatisfyFailed(ilCmiXapiResult $result)
const LP_STATUS_FAILED_NUM