ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilLPStatusLtiOutcome.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=0);
20 
28 {
29  private static array $userResultCache = array();
30 
31  private function getLtiUserResult(
32  int $objId,
33  int $usrId
35  if (!isset(self::$userResultCache[$objId])) {
36  self::$userResultCache[$objId] = array();
37  }
38 
39  if (!isset(self::$userResultCache[$objId][$usrId])) {
40  $ltiUserResult = ilLTIConsumerResult::getByKeys($objId, $usrId);
41  self::$userResultCache[$objId][$usrId] = $ltiUserResult;
42  }
43  return self::$userResultCache[$objId][$usrId];
44  }
45 
46  private function ensureObject(int $objId, $object): ilObjLTIConsumer
47  {
48  if (!($object instanceof ilObjLTIConsumer)) {
49  $object = ilObjectFactory::getInstanceByObjId($objId);
50  }
51  return $object;
52  }
53 
54  public function determineStatus(
55  int $a_obj_id,
56  int $a_usr_id,
57  ?object $a_obj = null
58  ): int {
59  $ltiResult = $this->getLtiUserResult($a_obj_id, $a_usr_id);
60 
61  if ($ltiResult instanceof ilLTIConsumerResult) {
62  $object = $this->ensureObject($a_obj_id, $a_obj);
63  $ltiMasteryScore = $object->getMasteryScore();
64 
65  if ($ltiResult->getResult() >= $ltiMasteryScore) {
66  return self::LP_STATUS_COMPLETED_NUM;
67  }
68 
69  return self::LP_STATUS_IN_PROGRESS_NUM;
70  }
71 
72  return self::LP_STATUS_NOT_ATTEMPTED_NUM;
73  }
74 
75  public function determinePercentage(
76  int $a_obj_id,
77  int $a_usr_id,
78  ?object $a_obj = null
79  ): int {
80  $ltiResult = $this->getLtiUserResult($a_obj_id, $a_usr_id);
81 
82  if ($ltiResult instanceof ilLTIConsumerResult) {
83  return (int) $ltiResult->getResult() * 100;
84  }
85 
86  return 0;
87  }
88 }
Class ilLPStatusLtiOutcome.
determinePercentage(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
ensureObject(int $objId, $object)
$objId
Definition: xapitoken.php:57
getLtiUserResult(int $objId, int $usrId)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
determineStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
static getByKeys(int $a_obj_id, int $a_usr_id, ?bool $a_create=false)
Get a result by object and user key.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id