ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
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 322 of file class.ilXapiStatementEvaluation.php.

Referenced by isResultStatusToBeReplaced().

322  : bool
323  {
324  if ($oldResultStatus == '') {
325  return true;
326  }
327 
328  if (in_array($newResultStatus, ['passed', 'failed'])) {
329  return true;
330  }
331 
332  if (!in_array($oldResultStatus, ['passed', 'failed'])) {
333  return true;
334  }
335 
336  return false;
337  }
+ 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  $this->evaluateStatement($xapiStatement, $cmixUser->getUsrId());
79 
80  $this->log->debug('update lp for object (' . $this->object->getId() . ')');
81  if ($cmixUser->getUsrId() != ANONYMOUS_USER_ID) {
82  ilLPStatusWrapper::_updateStatus($this->object->getId(), $cmixUser->getUsrId());
83  }
84  }
85  }
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 104 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().

104  : void
105  {
106  global $DIC;
107  $xapiVerb = $this->getXapiVerb($xapiStatement);
108 
109  if ($this->isValidXapiStatement($xapiStatement)) {
110  // result status and if exists scaled score
111  if ($this->hasResultStatusRelevantXapiVerb($xapiVerb)) {
112  if (!$this->isValidObject($xapiStatement)) {
113  return;
114  }
115  $userResult = $this->getUserResult($usrId);
116 
117  $oldResultStatus = $userResult->getStatus();
118  $newResultStatus = $this->getResultStatusForXapiVerb($xapiVerb);
119 
120  // this is for both xapi and cmi5
121  if ($this->isResultStatusToBeReplaced($oldResultStatus, $newResultStatus)) {
122  $this->log->debug("isResultStatusToBeReplaced: true");
123  $userResult->setStatus($newResultStatus);
124  }
125 
126  if ($this->hasXapiScore($xapiStatement)) {
127  $xapiScore = $this->getXapiScore($xapiStatement);
128  $this->log->debug("Score: " . $xapiScore);
129  $userResult->setScore((float) $xapiScore);
130  }
131  $userResult->save();
132 
133  // only cmi5
134  if ($this->object->getContentType() == ilObjCmiXapi::CONT_TYPE_CMI5) {
135  if (($xapiVerb == ilCmiXapiVerbList::COMPLETED || $xapiVerb == ilCmiXapiVerbList::PASSED) && $this->isLpModeInterestedInResultStatus($newResultStatus, false)) {
136  // it is possible to check against authToken usrId!
137  $cmixUser = $this->getCmixUser($xapiStatement);
138  // avoid multiple satisfied
139  if (!$cmixUser->getSatisfied()) {
140  $cmixUser->setSatisfied(true);
141  $cmixUser->save();
142  $this->sendSatisfiedStatement($cmixUser);
143  }
144  }
145  }
146  }
147  // result progress (i think only cmi5 relevant)
148  if ($this->hasResultProgressRelevantXapiVerb($xapiVerb)) {
149  $userResult = $this->getUserResult($usrId);
150  $progressedScore = $this->getProgressedScore($xapiStatement);
151  if ($progressedScore !== null && $progressedScore > 0) {
152  $userResult->setScore((float) ($progressedScore / 100));
153  $userResult->save();
154  }
155  }
156  }
157  }
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 87 of file class.ilXapiStatementEvaluation.php.

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

Referenced by evaluateReport(), and evaluateStatement().

88  {
89  $cmixUser = null;
90  if ($this->object->getContentType() == ilObjCmiXapi::CONT_TYPE_CMI5) {
92  $this->object->getId(),
93  $xapiStatement->actor->account->name
94  );
95  } else {
97  $this->object->getId(),
98  str_replace('mailto:', '', $xapiStatement->actor->mbox)
99  );
100  }
101  return $cmixUser;
102  }
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 236 of file class.ilXapiStatementEvaluation.php.

Referenced by evaluateStatement().

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

◆ getResultProgressForXapiVerb()

ilXapiStatementEvaluation::getResultProgressForXapiVerb ( string  $xapiVerb)
protected

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

205  {
206  return $this->resultProgressByXapiVerbMap[$xapiVerb];
207  }

◆ getResultStatusForXapiVerb()

ilXapiStatementEvaluation::getResultStatusForXapiVerb ( string  $xapiVerb)
protected

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

Referenced by evaluateStatement().

194  : string
195  {
196  return $this->resultStatusByXapiVerbMap[$xapiVerb];
197  }
+ Here is the caller graph for this function:

◆ getUserResult()

ilXapiStatementEvaluation::getUserResult ( int  $usrId)
protected

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

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

Referenced by evaluateStatement().

253  {
254  try {
255  $result = ilCmiXapiResult::getInstanceByObjIdAndUsrId($this->object->getId(), $usrId);
256  } catch (ilCmiXapiException $e) {
258  $result->setObjId($this->object->getId());
259  $result->setUsrId($usrId);
260  }
261 
262  return $result;
263  }
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 231 of file class.ilXapiStatementEvaluation.php.

Referenced by evaluateStatement().

232  {
233  return $xapiStatement->result->score->scaled;
234  }
+ Here is the caller graph for this function:

◆ getXapiVerb()

ilXapiStatementEvaluation::getXapiVerb ( object  $xapiStatement)
protected

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

Referenced by evaluateStatement().

189  : string
190  {
191  return $xapiStatement->verb->id;
192  }
+ Here is the caller graph for this function:

◆ hasResultProgressRelevantXapiVerb()

ilXapiStatementEvaluation::hasResultProgressRelevantXapiVerb ( string  $xapiVerb)
protected

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

Referenced by evaluateStatement().

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

◆ hasResultStatusRelevantXapiVerb()

ilXapiStatementEvaluation::hasResultStatusRelevantXapiVerb ( string  $xapiVerb)
protected

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

Referenced by evaluateStatement().

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

◆ hasXapiScore()

ilXapiStatementEvaluation::hasXapiScore ( object  $xapiStatement)
protected

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

Referenced by evaluateStatement().

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

◆ isLpModeInterestedInResultStatus()

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

Definition at line 285 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().

285  : ?bool
286  {
287  if ($this->lpMode == ilLPObjSettings::LP_MODE_DEACTIVATED) {
288  return $deactivated;
289  }
290 
291  switch ($resultStatus) {
292  case 'failed':
293 
294  return in_array($this->lpMode, [
298  ]);
299 
300  case 'passed':
301 
302  return in_array($this->lpMode, [
307  ]);
308 
309  case 'completed':
310 
311  return in_array($this->lpMode, [
316  ]);
317  }
318 
319  return false;
320  }
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 265 of file class.ilXapiStatementEvaluation.php.

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

Referenced by evaluateStatement().

265  : bool
266  {
267  if (!$this->isLpModeInterestedInResultStatus($newResultStatus)) {
268  $this->log->debug("isLpModeInterestedInResultStatus: false");
269  return false;
270  }
271 
272  if (!$this->doesNewResultStatusDominateOldOne($oldResultStatus, $newResultStatus)) {
273  $this->log->debug("doesNewResultStatusDominateOldOne: false");
274  return false;
275  }
276 
277  if ($this->needsAvoidFailedEvaluation($oldResultStatus, $newResultStatus)) {
278  $this->log->debug("needsAvoidFailedEvaluation: false");
279  return false;
280  }
281 
282  return true;
283  }
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 179 of file class.ilXapiStatementEvaluation.php.

Referenced by evaluateStatement().

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

◆ isValidXapiStatement()

ilXapiStatementEvaluation::isValidXapiStatement ( object  $xapiStatement)
protected

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

Referenced by evaluateStatement().

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

◆ needsAvoidFailedEvaluation()

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

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

References ILIAS\Repository\object().

Referenced by isResultStatusToBeReplaced().

339  : bool
340  {
341  if (!$this->object->isKeepLpStatusEnabled()) {
342  return false;
343  }
344 
345  if ($newResultStatus != 'failed') {
346  return false;
347  }
348 
349  return $oldResultStatus == 'completed' || $oldResultStatus == 'passed';
350  }
+ 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 352 of file class.ilXapiStatementEvaluation.php.

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

Referenced by evaluateStatement().

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