ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLPStatusLtiOutcome.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=0);
4 
5 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
6 
14 {
15  private static array $userResultCache = array();
16 
17  private function getLtiUserResult(
18  int $objId,
19  int $usrId
21  if (!isset(self::$userResultCache[$objId])) {
22  self::$userResultCache[$objId] = array();
23  }
24 
25  if (!isset(self::$userResultCache[$objId][$usrId])) {
26  $ltiUserResult = ilLTIConsumerResult::getByKeys($objId, $usrId);
27  self::$userResultCache[$objId][$usrId] = $ltiUserResult;
28  }
29  return self::$userResultCache[$objId][$usrId];
30  }
31 
32  private function ensureObject(int $objId, $object): ilObjLTIConsumer
33  {
34  if (!($object instanceof ilObjLTIConsumer)) {
35  $object = ilObjectFactory::getInstanceByObjId($objId);
36  }
37  return $object;
38  }
39 
40  public function determineStatus(
41  int $a_obj_id,
42  int $a_usr_id,
43  object $a_obj = null
44  ): int {
45  $ltiResult = $this->getLtiUserResult($a_obj_id, $a_usr_id);
46 
47  if ($ltiResult instanceof ilLTIConsumerResult) {
48  $object = $this->ensureObject($a_obj_id, $a_obj);
49  $ltiMasteryScore = $object->getMasteryScore();
50 
51  if ($ltiResult->getResult() >= $ltiMasteryScore) {
52  return self::LP_STATUS_COMPLETED_NUM;
53  }
54 
55  return self::LP_STATUS_IN_PROGRESS_NUM;
56  }
57 
58  return self::LP_STATUS_NOT_ATTEMPTED_NUM;
59  }
60 
61  public function determinePercentage(
62  int $a_obj_id,
63  int $a_usr_id,
64  ?object $a_obj = null
65  ): int {
66  $ltiResult = $this->getLtiUserResult($a_obj_id, $a_usr_id);
67 
68  if ($ltiResult instanceof ilLTIConsumerResult) {
69  return $ltiResult->getResult() * 100;
70  }
71 
72  return 0;
73  }
74 }
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)
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