ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilXapiStatementEvaluation Class Reference
+ Collaboration diagram for ilXapiStatementEvaluation:

Public Member Functions

 __construct (ilLogger $log, ilObject $object)
 ilXapiStatementEvaluation constructor. More...
 
 evaluateReport (ilCmiXapiStatementsReport $report)
 
 getCmixUser (object $xapiStatement)
 
 evaluateStatement (object $xapiStatement, int $usrId)
 

Protected Member Functions

 isValidXapiStatement (object $xapiStatement)
 
 isValidObject (object $xapiStatement)
 
 getXapiVerb (object $xapiStatement)
 
 getResultStatusForXapiVerb (string $xapiVerb)
 
 hasResultStatusRelevantXapiVerb (string $xapiVerb)
 
 getResultProgressForXapiVerb (string $xapiVerb)
 
 hasResultProgressRelevantXapiVerb (string $xapiVerb)
 
 hasXapiScore (object $xapiStatement)
 
 getXapiScore (object $xapiStatement)
 
 getProgressedScore (object $xapiStatement)
 
 getUserResult (int $usrId)
 
 isResultStatusToBeReplaced (string $oldResultStatus, string $newResultStatus)
 
 isLpModeInterestedInResultStatus (string $resultStatus, ?bool $deactivated=true)
 
 doesNewResultStatusDominateOldOne (string $oldResultStatus, string $newResultStatus)
 
 needsAvoidFailedEvaluation (string $oldResultStatus, string $newResultStatus)
 
 sendSatisfiedStatement (ilCmiXapiUser $cmixUser)
 

Protected Attributes

array $resultStatusByXapiVerbMap
 http://adlnet.gov/expapi/verbs/satisfied: should never be sent by AU https://github.com/AICC/CMI-5_Spec_Current/blob/quartz/cmi5_spec.md#939-satisfied More...
 
array $resultProgressByXapiVerbMap
 
ilObject $object
 
ilLogger $log
 
int $lpMode
 

Detailed Description

Definition at line 30 of file class.ilXapiStatementEvaluation.php.

Constructor & Destructor Documentation

◆ __construct()

ilXapiStatementEvaluation::__construct ( ilLogger  $log,
ilObject  $object 
)

ilXapiStatementEvaluation constructor.

Definition at line 58 of file class.ilXapiStatementEvaluation.php.

References $log, $object, ilObjectLP\getInstance(), and ILIAS\Repository\object().

59  {
60  $this->log = $log;
61  $this->object = $object;
62 
63  $objLP = ilObjectLP::getInstance($this->object->getId());
64  $this->lpMode = $objLP->getCurrentMode();
65  }
static getInstance(int $obj_id)
+ Here is the call graph for this function:

Member Function Documentation

◆ doesNewResultStatusDominateOldOne()

ilXapiStatementEvaluation::doesNewResultStatusDominateOldOne ( string  $oldResultStatus,
string  $newResultStatus 
)
protected

Definition at line 325 of file class.ilXapiStatementEvaluation.php.

Referenced by isResultStatusToBeReplaced().

325  : bool
326  {
327  if ($oldResultStatus == '') {
328  return true;
329  }
330 
331  if (in_array($newResultStatus, ['passed', 'failed'])) {
332  return true;
333  }
334 
335  if (!in_array($oldResultStatus, ['passed', 'failed'])) {
336  return true;
337  }
338 
339  return false;
340  }
+ Here is the caller graph for this function:

◆ evaluateReport()

ilXapiStatementEvaluation::evaluateReport ( ilCmiXapiStatementsReport  $report)

Definition at line 67 of file class.ilXapiStatementEvaluation.php.

References ilLPStatusWrapper\_updateStatus(), ANONYMOUS_USER_ID, evaluateStatement(), getCmixUser(), ilCmiXapiStatementsReport\getStatements(), and ILIAS\Repository\object().

67  : void
68  {
69  foreach ($report->getStatements() as $xapiStatement) {
70  #$this->log->debug(
71  # "handle statement:\n".json_encode($xapiStatement, JSON_PRETTY_PRINT)
72  #);
73 
74  // ensure json decoded non assoc
75  $xapiStatement = json_decode(json_encode($xapiStatement));
76  $cmixUser = $this->getCmixUser($xapiStatement);
77 
78  if ($cmixUser != null) {
79  $this->evaluateStatement($xapiStatement, $cmixUser->getUsrId());
80 
81  $this->log->debug('update lp for object (' . $this->object->getId() . ')');
82  if ($cmixUser->getUsrId() != ANONYMOUS_USER_ID) {
83  ilLPStatusWrapper::_updateStatus($this->object->getId(), $cmixUser->getUsrId());
84  }
85  }
86  }
87  }
const ANONYMOUS_USER_ID
Definition: constants.php:27
evaluateStatement(object $xapiStatement, int $usrId)
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
+ Here is the call graph for this function:

◆ evaluateStatement()

ilXapiStatementEvaluation::evaluateStatement ( object  $xapiStatement,
int  $usrId 
)

Definition at line 108 of file class.ilXapiStatementEvaluation.php.

References $DIC, ilCmiXapiVerbList\COMPLETED, ilObjCmiXapi\CONT_TYPE_CMI5, getCmixUser(), getProgressedScore(), getResultStatusForXapiVerb(), getUserResult(), getXapiScore(), getXapiVerb(), hasResultProgressRelevantXapiVerb(), hasResultStatusRelevantXapiVerb(), hasXapiScore(), isLpModeInterestedInResultStatus(), isResultStatusToBeReplaced(), isValidObject(), isValidXapiStatement(), ILIAS\Repository\object(), ilCmiXapiVerbList\PASSED, and sendSatisfiedStatement().

Referenced by evaluateReport().

108  : void
109  {
110  global $DIC;
111  $xapiVerb = $this->getXapiVerb($xapiStatement);
112 
113  if ($this->isValidXapiStatement($xapiStatement)) {
114  // result status and if exists scaled score
115  if ($this->hasResultStatusRelevantXapiVerb($xapiVerb)) {
116  if (!$this->isValidObject($xapiStatement)) {
117  return;
118  }
119  $userResult = $this->getUserResult($usrId);
120 
121  $oldResultStatus = $userResult->getStatus();
122  $newResultStatus = $this->getResultStatusForXapiVerb($xapiVerb);
123 
124  // this is for both xapi and cmi5
125  if ($this->isResultStatusToBeReplaced($oldResultStatus, $newResultStatus)) {
126  $this->log->debug("isResultStatusToBeReplaced: true");
127  $userResult->setStatus($newResultStatus);
128  }
129 
130  if ($this->hasXapiScore($xapiStatement)) {
131  $xapiScore = $this->getXapiScore($xapiStatement);
132  $this->log->debug("Score: " . $xapiScore);
133  $userResult->setScore((float) $xapiScore);
134  }
135  $userResult->save();
136 
137  // only cmi5
138  if ($this->object->getContentType() == ilObjCmiXapi::CONT_TYPE_CMI5) {
139  if (($xapiVerb == ilCmiXapiVerbList::COMPLETED || $xapiVerb == ilCmiXapiVerbList::PASSED) && $this->isLpModeInterestedInResultStatus($newResultStatus, false)) {
140  // it is possible to check against authToken usrId!
141  $cmixUser = $this->getCmixUser($xapiStatement);
142  if ($cmixUser != null) {
143  $cmixUser->setSatisfied(true);
144  $cmixUser->save();
145  $this->sendSatisfiedStatement($cmixUser);
146  }
147  }
148  }
149  }
150  // result progress (i think only cmi5 relevant)
151  if ($this->hasResultProgressRelevantXapiVerb($xapiVerb)) {
152  $userResult = $this->getUserResult($usrId);
153  $progressedScore = $this->getProgressedScore($xapiStatement);
154  if ($progressedScore !== null && $progressedScore > 0) {
155  $userResult->setScore((float) ($progressedScore / 100));
156  $userResult->save();
157  }
158  }
159  }
160  }
isResultStatusToBeReplaced(string $oldResultStatus, string $newResultStatus)
isLpModeInterestedInResultStatus(string $resultStatus, ?bool $deactivated=true)
sendSatisfiedStatement(ilCmiXapiUser $cmixUser)
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCmixUser()

ilXapiStatementEvaluation::getCmixUser ( object  $xapiStatement)

Definition at line 89 of file class.ilXapiStatementEvaluation.php.

References ilObjCmiXapi\CONT_TYPE_CMI5, ilCmiXapiUser\getInstanceByObjectIdAndUsrIdent(), and ILIAS\Repository\object().

Referenced by evaluateReport(), and evaluateStatement().

90  {
91  $cmixUser = null;
92  if ($this->object->getContentType() == ilObjCmiXapi::CONT_TYPE_CMI5) {
93  if (isset($xapiStatement->actor->account->name)) {
95  $this->object->getId(),
96  $xapiStatement->actor->account->name
97  );
98  }
99  } else {
101  $this->object->getId(),
102  str_replace('mailto:', '', $xapiStatement->actor->mbox)
103  );
104  }
105  return $cmixUser;
106  }
static getInstanceByObjectIdAndUsrIdent(int $objId, string $usrIdent)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getProgressedScore()

ilXapiStatementEvaluation::getProgressedScore ( object  $xapiStatement)
protected

Definition at line 239 of file class.ilXapiStatementEvaluation.php.

Referenced by evaluateStatement().

239  : ?float
240  {
241  if (!isset($xapiStatement->result)) {
242  return null;
243  }
244 
245  if (!isset($xapiStatement->result->extensions)) {
246  return null;
247  }
248 
249  if (!isset($xapiStatement->result->extensions->{'https://w3id.org/xapi/cmi5/result/extensions/progress'})) {
250  return null;
251  }
252  return (float) $xapiStatement->result->extensions->{'https://w3id.org/xapi/cmi5/result/extensions/progress'};
253  }
+ Here is the caller graph for this function:

◆ getResultProgressForXapiVerb()

ilXapiStatementEvaluation::getResultProgressForXapiVerb ( string  $xapiVerb)
protected

Definition at line 207 of file class.ilXapiStatementEvaluation.php.

208  {
209  return $this->resultProgressByXapiVerbMap[$xapiVerb];
210  }

◆ getResultStatusForXapiVerb()

ilXapiStatementEvaluation::getResultStatusForXapiVerb ( string  $xapiVerb)
protected

Definition at line 197 of file class.ilXapiStatementEvaluation.php.

Referenced by evaluateStatement().

197  : string
198  {
199  return $this->resultStatusByXapiVerbMap[$xapiVerb];
200  }
+ Here is the caller graph for this function:

◆ getUserResult()

ilXapiStatementEvaluation::getUserResult ( int  $usrId)
protected

Definition at line 255 of file class.ilXapiStatementEvaluation.php.

References Vendor\Package\$e, ilCmiXapiResult\getEmptyInstance(), ilCmiXapiResult\getInstanceByObjIdAndUsrId(), and ILIAS\Repository\object().

Referenced by evaluateStatement().

256  {
257  try {
258  $result = ilCmiXapiResult::getInstanceByObjIdAndUsrId($this->object->getId(), $usrId);
259  } catch (ilCmiXapiException $e) {
261  $result->setObjId($this->object->getId());
262  $result->setUsrId($usrId);
263  }
264 
265  return $result;
266  }
static getInstanceByObjIdAndUsrId(int $objId, int $usrId)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getXapiScore()

ilXapiStatementEvaluation::getXapiScore ( object  $xapiStatement)
protected

Definition at line 234 of file class.ilXapiStatementEvaluation.php.

Referenced by evaluateStatement().

235  {
236  return $xapiStatement->result->score->scaled;
237  }
+ Here is the caller graph for this function:

◆ getXapiVerb()

ilXapiStatementEvaluation::getXapiVerb ( object  $xapiStatement)
protected

Definition at line 192 of file class.ilXapiStatementEvaluation.php.

Referenced by evaluateStatement().

192  : string
193  {
194  return $xapiStatement->verb->id;
195  }
+ Here is the caller graph for this function:

◆ hasResultProgressRelevantXapiVerb()

ilXapiStatementEvaluation::hasResultProgressRelevantXapiVerb ( string  $xapiVerb)
protected

Definition at line 212 of file class.ilXapiStatementEvaluation.php.

Referenced by evaluateStatement().

212  : bool
213  {
214  return isset($this->resultProgressByXapiVerbMap[$xapiVerb]);
215  }
+ Here is the caller graph for this function:

◆ hasResultStatusRelevantXapiVerb()

ilXapiStatementEvaluation::hasResultStatusRelevantXapiVerb ( string  $xapiVerb)
protected

Definition at line 202 of file class.ilXapiStatementEvaluation.php.

Referenced by evaluateStatement().

202  : bool
203  {
204  return isset($this->resultStatusByXapiVerbMap[$xapiVerb]);
205  }
+ Here is the caller graph for this function:

◆ hasXapiScore()

ilXapiStatementEvaluation::hasXapiScore ( object  $xapiStatement)
protected

Definition at line 217 of file class.ilXapiStatementEvaluation.php.

Referenced by evaluateStatement().

217  : bool
218  {
219  if (!isset($xapiStatement->result)) {
220  return false;
221  }
222 
223  if (!isset($xapiStatement->result->score)) {
224  return false;
225  }
226 
227  if (!isset($xapiStatement->result->score->scaled)) {
228  return false;
229  }
230 
231  return true;
232  }
+ Here is the caller graph for this function:

◆ isLpModeInterestedInResultStatus()

ilXapiStatementEvaluation::isLpModeInterestedInResultStatus ( string  $resultStatus,
?bool  $deactivated = true 
)
protected

Definition at line 288 of file class.ilXapiStatementEvaluation.php.

References ilLPObjSettings\LP_MODE_CMIX_COMPL_OR_PASSED_WITH_FAILED, ilLPObjSettings\LP_MODE_CMIX_COMPL_WITH_FAILED, ilLPObjSettings\LP_MODE_CMIX_COMPLETED, ilLPObjSettings\LP_MODE_CMIX_COMPLETED_OR_PASSED, ilLPObjSettings\LP_MODE_CMIX_PASSED, ilLPObjSettings\LP_MODE_CMIX_PASSED_WITH_FAILED, and ilLPObjSettings\LP_MODE_DEACTIVATED.

Referenced by evaluateStatement(), and isResultStatusToBeReplaced().

288  : ?bool
289  {
290  if ($this->lpMode == ilLPObjSettings::LP_MODE_DEACTIVATED) {
291  return $deactivated;
292  }
293 
294  switch ($resultStatus) {
295  case 'failed':
296 
297  return in_array($this->lpMode, [
301  ]);
302 
303  case 'passed':
304 
305  return in_array($this->lpMode, [
310  ]);
311 
312  case 'completed':
313 
314  return in_array($this->lpMode, [
319  ]);
320  }
321 
322  return false;
323  }
const LP_MODE_CMIX_COMPL_OR_PASSED_WITH_FAILED
+ Here is the caller graph for this function:

◆ isResultStatusToBeReplaced()

ilXapiStatementEvaluation::isResultStatusToBeReplaced ( string  $oldResultStatus,
string  $newResultStatus 
)
protected

Definition at line 268 of file class.ilXapiStatementEvaluation.php.

References doesNewResultStatusDominateOldOne(), isLpModeInterestedInResultStatus(), and needsAvoidFailedEvaluation().

Referenced by evaluateStatement().

268  : bool
269  {
270  if (!$this->isLpModeInterestedInResultStatus($newResultStatus)) {
271  $this->log->debug("isLpModeInterestedInResultStatus: false");
272  return false;
273  }
274 
275  if (!$this->doesNewResultStatusDominateOldOne($oldResultStatus, $newResultStatus)) {
276  $this->log->debug("doesNewResultStatusDominateOldOne: false");
277  return false;
278  }
279 
280  if ($this->needsAvoidFailedEvaluation($oldResultStatus, $newResultStatus)) {
281  $this->log->debug("needsAvoidFailedEvaluation: false");
282  return false;
283  }
284 
285  return true;
286  }
isLpModeInterestedInResultStatus(string $resultStatus, ?bool $deactivated=true)
doesNewResultStatusDominateOldOne(string $oldResultStatus, string $newResultStatus)
needsAvoidFailedEvaluation(string $oldResultStatus, string $newResultStatus)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValidObject()

ilXapiStatementEvaluation::isValidObject ( object  $xapiStatement)
protected

Definition at line 182 of file class.ilXapiStatementEvaluation.php.

Referenced by evaluateStatement().

182  : bool
183  {
184  if ($xapiStatement->object->id != $this->object->getActivityId()) {
185  $this->log->debug($xapiStatement->object->id . " != " . $this->object->getActivityId());
186  return false;
187  }
188  return true;
189  }
+ Here is the caller graph for this function:

◆ isValidXapiStatement()

ilXapiStatementEvaluation::isValidXapiStatement ( object  $xapiStatement)
protected

Definition at line 162 of file class.ilXapiStatementEvaluation.php.

Referenced by evaluateStatement().

162  : bool
163  {
164  if (!isset($xapiStatement->actor)) {
165  return false;
166  }
167 
168  if (!isset($xapiStatement->verb) || !isset($xapiStatement->verb->id)) {
169  return false;
170  }
171 
172  if (!isset($xapiStatement->object) || !isset($xapiStatement->object->id)) {
173  return false;
174  }
175 
176  return true;
177  }
+ Here is the caller graph for this function:

◆ needsAvoidFailedEvaluation()

ilXapiStatementEvaluation::needsAvoidFailedEvaluation ( string  $oldResultStatus,
string  $newResultStatus 
)
protected

Definition at line 342 of file class.ilXapiStatementEvaluation.php.

References ILIAS\Repository\object().

Referenced by isResultStatusToBeReplaced().

342  : bool
343  {
344  if (!$this->object->isKeepLpStatusEnabled()) {
345  return false;
346  }
347 
348  if ($newResultStatus != 'failed') {
349  return false;
350  }
351 
352  return $oldResultStatus == 'completed' || $oldResultStatus == 'passed';
353  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendSatisfiedStatement()

ilXapiStatementEvaluation::sendSatisfiedStatement ( ilCmiXapiUser  $cmixUser)
protected

Definition at line 355 of file class.ilXapiStatementEvaluation.php.

References $client, $DIC, Vendor\Package\$e, ilCmiXapiAbstractRequest\buildQuery(), and ilCmiXapiAbstractRequest\checkResponse().

Referenced by evaluateStatement().

355  : void
356  {
357  global $DIC;
358 
359  $lrsType = $this->object->getLrsType();
360  $defaultLrs = $lrsType->getLrsEndpoint();
361  //$fallbackLrs = $lrsType->getLrsFallbackEndpoint();
362  $defaultBasicAuth = $lrsType->getBasicAuth();
363  //$fallbackBasicAuth = $lrsType->getFallbackBasicAuth();
364  $defaultHeaders = [
365  'X-Experience-API-Version' => '1.0.3',
366  'Authorization' => $defaultBasicAuth,
367  'Content-Type' => 'application/json;charset=utf-8',
368  'Cache-Control' => 'no-cache, no-store, must-revalidate'
369  ];
370  /*
371  $fallbackHeaders = [
372  'X-Experience-API-Version' => '1.0.3',
373  'Authorization' => $fallbackBasicAuth,
374  'Content-Type' => 'application/json;charset=utf-8',
375  'Cache-Control' => 'no-cache, no-store, must-revalidate'
376  ];
377  */
378  $satisfiedStatement = $this->object->getSatisfiedStatement($cmixUser);
379  $satisfiedStatementParams = [];
380  $satisfiedStatementParams['statementId'] = $satisfiedStatement['id'];
381  $defaultStatementsUrl = $defaultLrs . "/statements";
382  $defaultSatisfiedStatementUrl = $defaultStatementsUrl . '?' . ilCmiXapiAbstractRequest::buildQuery($satisfiedStatementParams);
383 
384  $client = new GuzzleHttp\Client();
385  $req_opts = array(
386  GuzzleHttp\RequestOptions::VERIFY => true,
387  GuzzleHttp\RequestOptions::CONNECT_TIMEOUT => 10,
388  GuzzleHttp\RequestOptions::HTTP_ERRORS => false
389  );
390 
391  $defaultSatisfiedStatementRequest = new GuzzleHttp\Psr7\Request(
392  'PUT',
393  $defaultSatisfiedStatementUrl,
394  $defaultHeaders,
395  json_encode($satisfiedStatement)
396  );
397  $promises = array();
398  $promises['defaultSatisfiedStatement'] = $client->sendAsync($defaultSatisfiedStatementRequest, $req_opts);
399  try {
400  $responses = GuzzleHttp\Promise\Utils::settle($promises)->wait();
401  $body = '';
402  ilCmiXapiAbstractRequest::checkResponse($responses['defaultSatisfiedStatement'], $body, [204]);
403  } catch (Exception $e) {
404  $this->log->error('error:' . $e->getMessage());
405  }
406  }
global $DIC
Definition: feed.php:28
$client
static buildQuery(array $params, $encoding=PHP_QUERY_RFC3986)
static checkResponse(array $response, &$body, array $allowedStatus=[200, 204])
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $log

ilLogger ilXapiStatementEvaluation::$log
protected

Definition at line 51 of file class.ilXapiStatementEvaluation.php.

Referenced by __construct().

◆ $lpMode

int ilXapiStatementEvaluation::$lpMode
protected

Definition at line 53 of file class.ilXapiStatementEvaluation.php.

◆ $object

ilObject ilXapiStatementEvaluation::$object
protected

Definition at line 48 of file class.ilXapiStatementEvaluation.php.

Referenced by __construct().

◆ $resultProgressByXapiVerbMap

array ilXapiStatementEvaluation::$resultProgressByXapiVerbMap
protected
Initial value:
= [

Definition at line 43 of file class.ilXapiStatementEvaluation.php.

◆ $resultStatusByXapiVerbMap

array ilXapiStatementEvaluation::$resultStatusByXapiVerbMap
protected

The documentation for this class was generated from the following file: