ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilLPStatusLtiOutcome.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
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  global $DIC;
60  $logger = $DIC->logger()->root();
61  $ltiResult = $this->getLtiUserResult($a_obj_id, $a_usr_id);
62 
63  if ($ltiResult instanceof ilLTIConsumerResult) {
64  $object = $this->ensureObject($a_obj_id, $a_obj);
65  $ltiMasteryScore = $object->getMasteryScore();
66 
67  $logger->info("Getting LTI result for user $a_usr_id: " . $ltiResult->getResult());
68 
69  if ($ltiResult->getResult() === 0) {
70  return self::LP_STATUS_FAILED_NUM;
71  } elseif (is_null($ltiResult->getResult())) {
72  return self::LP_STATUS_NOT_ATTEMPTED_NUM;
73  } elseif ($ltiResult->getResult() >= $ltiMasteryScore) {
74  return self::LP_STATUS_COMPLETED_NUM;
75  } else {
76  return self::LP_STATUS_FAILED_NUM;
77  }
78  } else {
79  $logger->info("No LTI result for user $a_usr_id");
80  }
81 
82  return self::LP_STATUS_NOT_ATTEMPTED_NUM;
83  }
84 
85  public function determinePercentage(
86  int $a_obj_id,
87  int $a_usr_id,
88  ?object $a_obj = null
89  ): int {
90  $ltiResult = $this->getLtiUserResult($a_obj_id, $a_usr_id);
91 
92  if ($ltiResult instanceof ilLTIConsumerResult) {
93  return (int) $ltiResult->getResult() * 100;
94  }
95 
96  return 0;
97  }
98 }
Class ilLPStatusLtiOutcome.
determinePercentage(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
ensureObject(int $objId, $object)
$objId
Definition: xapitoken.php:55
getLtiUserResult(int $objId, int $usrId)
global $DIC
Definition: shib_login.php:25
static getByKeys(int $a_obj_id, int $a_usr_id, ?bool $a_create=false)
Get a result by object and user key.
determineStatus(int $a_obj_id, int $a_usr_id, object $a_obj=null)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id