19declare(strict_types=1);
64 $this->lpMode = $objLP->getCurrentMode();
71 # "handle statement:\n".json_encode($xapiStatement, JSON_PRETTY_PRINT)
75 $xapiStatement = json_decode(json_encode($xapiStatement));
78 if ($cmixUser !=
null) {
81 $this->log->debug(
'update lp for object (' . $this->
object->getId() .
')');
93 if (isset($xapiStatement->actor->account->name)) {
96 $xapiStatement->actor->account->name
102 str_replace(
'mailto:',
'', $xapiStatement->actor->mbox)
121 $oldResultStatus = $userResult->getStatus();
126 $this->log->debug(
"isResultStatusToBeReplaced: true");
127 $userResult->setStatus($newResultStatus);
132 $this->log->debug(
"Score: " . $xapiScore);
133 $userResult->setScore((
float) $xapiScore);
142 if ($cmixUser !=
null) {
143 $cmixUser->setSatisfied(
true);
154 if ($progressedScore !==
null && $progressedScore > 0) {
155 $userResult->setScore((
float) ($progressedScore / 100));
164 if (!isset($xapiStatement->actor)) {
168 if (!isset($xapiStatement->verb) || !isset($xapiStatement->verb->id)) {
172 if (!isset($xapiStatement->object) || !isset($xapiStatement->object->id)) {
184 if ($xapiStatement->object->id != $this->object->getActivityId()) {
185 $this->log->debug($xapiStatement->object->id .
" != " . $this->object->getActivityId());
194 return $xapiStatement->verb->id;
199 return $this->resultStatusByXapiVerbMap[$xapiVerb];
204 return isset($this->resultStatusByXapiVerbMap[$xapiVerb]);
209 return $this->resultProgressByXapiVerbMap[$xapiVerb];
214 return isset($this->resultProgressByXapiVerbMap[$xapiVerb]);
219 if (!isset($xapiStatement->result)) {
223 if (!isset($xapiStatement->result->score)) {
227 if (!isset($xapiStatement->result->score->scaled)) {
236 return $xapiStatement->result->score->scaled;
241 if (!isset($xapiStatement->result)) {
245 if (!isset($xapiStatement->result->extensions)) {
249 if (!isset($xapiStatement->result->extensions->{
'https://w3id.org/xapi/cmi5/result/extensions/progress'})) {
252 return (
float) $xapiStatement->result->extensions->{
'https://w3id.org/xapi/cmi5/result/extensions/progress'};
261 $result->setObjId($this->
object->getId());
262 $result->setUsrId($usrId);
270 if (!$this->isLpModeInterestedInResultStatus($newResultStatus)) {
271 $this->log->debug(
"isLpModeInterestedInResultStatus: false");
275 if (!$this->doesNewResultStatusDominateOldOne($oldResultStatus, $newResultStatus)) {
276 $this->log->debug(
"doesNewResultStatusDominateOldOne: false");
280 if ($this->needsAvoidFailedEvaluation($oldResultStatus, $newResultStatus)) {
281 $this->log->debug(
"needsAvoidFailedEvaluation: false");
294 switch ($resultStatus) {
297 return in_array($this->lpMode, [
305 return in_array($this->lpMode, [
314 return in_array($this->lpMode, [
327 if ($oldResultStatus ==
'') {
331 if (in_array($newResultStatus, [
'passed',
'failed'])) {
335 if (!in_array($oldResultStatus, [
'passed',
'failed'])) {
344 if (!$this->
object->isKeepLpStatusEnabled()) {
348 if ($newResultStatus !=
'failed') {
352 return $oldResultStatus ==
'completed' || $oldResultStatus ==
'passed';
360 $lrsType = $this->
object->getLrsType();
361 $defaultLrs = $lrsType->getLrsEndpoint();
362 $defaultBasicAuth = $lrsType->getBasicAuth();
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'
371 $satisfiedStatement = $this->
object->getSatisfiedStatement($cmixUser);
372 $satisfiedStatementParams = [
'statementId' => $satisfiedStatement[
'id']];
373 $defaultStatementsUrl = $defaultLrs .
"/statements";
377 $ch = curl_init($defaultSatisfiedStatementUrl);
378 curl_setopt_array($ch, [
379 CURLOPT_CUSTOMREQUEST =>
"PUT",
380 CURLOPT_HTTPHEADER => $defaultHeaders,
381 CURLOPT_POSTFIELDS => json_encode($satisfiedStatement),
382 CURLOPT_RETURNTRANSFER =>
true,
383 CURLOPT_CONNECTTIMEOUT => 10,
384 CURLOPT_SSL_VERIFYPEER =>
true,
387 $responseBody = curl_exec($ch);
388 $statusCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
390 if ($responseBody ===
false) {
391 $error = curl_error($ch);
392 $this->log->error(
'cURL error while sending satisfied statement: ' . $error);
396 [
'status' => $statusCode,
'body' => $responseBody],
400 }
catch (Exception
$e) {
401 $this->log->error(
'checkResponse failed: ' .
$e->getMessage());
static buildQuery(array $params, $encoding=PHP_QUERY_RFC3986)
static checkResponse(array $response, &$body, array $allowedStatus=[200, 204])
static getEmptyInstance()
static getInstanceByObjIdAndUsrId(int $objId, int $usrId)
static getInstanceByObjectIdAndUsrIdent(int $objId, string $usrIdent)
const LP_MODE_CMIX_COMPLETED_OR_PASSED
const LP_MODE_CMIX_COMPL_WITH_FAILED
const LP_MODE_CMIX_PASSED
const LP_MODE_CMIX_COMPL_OR_PASSED_WITH_FAILED
const LP_MODE_DEACTIVATED
const LP_MODE_CMIX_COMPLETED
const LP_MODE_CMIX_PASSED_WITH_FAILED
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
Component logger with individual log levels by component id.
static getInstance(int $obj_id)
Class ilObject Basic functions for all objects.
sendSatisfiedStatement(ilCmiXapiUser $cmixUser)
hasResultStatusRelevantXapiVerb(string $xapiVerb)
hasResultProgressRelevantXapiVerb(string $xapiVerb)
getProgressedScore(object $xapiStatement)
getCmixUser(object $xapiStatement)
isValidObject(object $xapiStatement)
hasXapiScore(object $xapiStatement)
isLpModeInterestedInResultStatus(string $resultStatus, ?bool $deactivated=true)
getResultProgressForXapiVerb(string $xapiVerb)
__construct(ilLogger $log, ilObject $object)
ilXapiStatementEvaluation constructor.
isResultStatusToBeReplaced(string $oldResultStatus, string $newResultStatus)
getXapiVerb(object $xapiStatement)
getResultStatusForXapiVerb(string $xapiVerb)
getXapiScore(object $xapiStatement)
evaluateReport(ilCmiXapiStatementsReport $report)
isValidXapiStatement(object $xapiStatement)
evaluateStatement(object $xapiStatement, int $usrId)
doesNewResultStatusDominateOldOne(string $oldResultStatus, string $newResultStatus)
array $resultStatusByXapiVerbMap
http://adlnet.gov/expapi/verbs/satisfied: should never be sent by AU https://github....
array $resultProgressByXapiVerbMap
needsAvoidFailedEvaluation(string $oldResultStatus, string $newResultStatus)
getUserResult(int $usrId)