ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLPStatusLtiOutcome.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 
14 {
15  private static $userResultCache = array();
16 
22  private function getLtiUserResult($objId, $usrId)
23  {
24  if (!isset(self::$userResultCache[$objId])) {
25  self::$userResultCache[$objId] = array();
26  }
27 
28  if (!isset(self::$userResultCache[$objId][$usrId])) {
29  $ltiUserResult = ilLTIConsumerResult::getByKeys($objId, $usrId);
30  self::$userResultCache[$objId][$usrId] = $ltiUserResult;
31  }
32 
33  return self::$userResultCache[$objId][$usrId];
34  }
35 
36  private function ensureObject($objId, $object) : ilObjLTIConsumer
37  {
38  if (!($object instanceof ilObjLTIConsumer)) {
40  }
41 
42  return $object;
43  }
44 
45  public function determineStatus($a_obj_id, $a_usr_id, $a_obj = null)
46  {
47  $ltiResult = $this->getLtiUserResult($a_obj_id, $a_usr_id);
48 
49  if ($ltiResult instanceof ilLTIConsumerResult) {
50  $object = $this->ensureObject($a_obj_id, $a_obj);
51  $ltiMasteryScore = $object->getMasteryScore();
52 
53  if ($ltiResult->getResult() >= $ltiMasteryScore) {
54  return self::LP_STATUS_COMPLETED_NUM;
55  }
56 
57  return self::LP_STATUS_IN_PROGRESS_NUM;
58  }
59 
60  return self::LP_STATUS_NOT_ATTEMPTED_NUM;
61  }
62 
63  public function determinePercentage($a_obj_id, $a_usr_id, $a_obj = null)
64  {
65  $ltiResult = $this->getLtiUserResult($a_obj_id, $a_usr_id);
66 
67  if ($ltiResult instanceof ilLTIConsumerResult) {
68  return $ltiResult->getResult() * 100;
69  }
70 
71  return 0;
72  }
73 }
Class ilLPStatusLtiOutcome.
static getByKeys($a_obj_id, $a_usr_id, $a_create=false)
Get a result by object and user key.
$objId
Definition: xapitoken.php:41
determineStatus($a_obj_id, $a_usr_id, $a_obj=null)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
determinePercentage($a_obj_id, $a_usr_id, $a_obj=null)