ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilLTIAppEventListener Class Reference

Class ilLTIAppEventListener. More...

+ Inheritance diagram for ilLTIAppEventListener:
+ Collaboration diagram for ilLTIAppEventListener:

Static Public Member Functions

static handleEvent ($a_component, $a_event, $a_parameter)
 Handle an event in a listener.
Parameters
string$a_componentcomponent, e.g. "Modules/Forum" or "Services/User"
string$a_eventevent e.g. "createUser", "updateUser", "deleteUser", ...
array$a_parameterparameter array (assoc), array("name" => ..., "phone_office" => ...)
More...
 
static handleCronUpdate (ilDateTime $since)
 

Protected Member Functions

 __construct ()
 ilLTIAppEventListener constructor. More...
 
 handleUpdateStatus ($a_obj_id, $a_usr_id, $a_status, $a_percentage)
 Handle update status. More...
 
 doCronUpdate (ilDateTime $since)
 
 isLTIAuthMode ($auth_mode)
 
 tryOutcomeService ($resource, $ext_account, $a_status, $a_percentage)
 try outcome service More...
 

Static Protected Member Functions

static getInstance ()
 

Private Attributes

 $logger = null
 
 $connector = null
 

Static Private Attributes

static $instance = null
 

Detailed Description

Class ilLTIAppEventListener.

Definition at line 7 of file class.ilLTIAppEventListener.php.

Constructor & Destructor Documentation

◆ __construct()

ilLTIAppEventListener::__construct ( )
protected

ilLTIAppEventListener constructor.

Definition at line 28 of file class.ilLTIAppEventListener.php.

References $DIC.

29  {
30  global $DIC;
31 
32  $this->logger = $DIC->logger()->lti();
33  $this->connector = new ilLTIDataConnector();
34  }
global $DIC
Definition: saml.php:7
Class to represent an LTI Data Connector for ILIAS.

Member Function Documentation

◆ doCronUpdate()

ilLTIAppEventListener::doCronUpdate ( ilDateTime  $since)
protected
Parameters
ilDateTime$since
Exceptions
ilDateTimeException

Definition at line 81 of file class.ilLTIAppEventListener.php.

References $consumer, ilObjUser\_checkExternalAuthAccount(), ilObjUser\_lookupId(), ilObject\_lookupObjId(), ilLPStatus\_lookupPercentage(), ilLPStatus\_lookupStatus(), and tryOutcomeService().

82  {
83  $this->logger->debug('Starting cron update for lti outcome service');
84 
85  $resources = $this->connector->lookupResourcesForAllUsersSinceDate($since);
86  foreach ($resources as $consumer_ext_account => $user_resources) {
87  list($consumer, $ext_account) = explode('__', $consumer_ext_account, 2);
88 
89  $login = ilObjUser::_checkExternalAuthAccount('lti_' . $consumer, $ext_account);
90  if (!$login) {
91  $this->logger->info('No user found for lti_' . $consumer . ' -> ' . $ext_account);
92  continue;
93  }
94  $usr_id = ilObjUser::_lookupId($login);
95  foreach ($user_resources as $resource_info) {
96  $this->logger->debug('Found resource: ' . $resource_info);
97  list($resource_id, $resource_ref_id) = explode('__', $resource_info);
98 
99  // lookup lp status
100  $status = ilLPStatus::_lookupStatus(
101  ilObject::_lookupObjId($resource_ref_id),
102  $usr_id
103  );
104  $percentage = ilLPStatus::_lookupPercentage(
105  ilObject::_lookupObjId($resource_ref_id),
106  $usr_id
107  );
108  $this->tryOutcomeService($resource_id, $ext_account, $status, $percentage);
109  }
110  }
111  }
static _lookupPercentage($a_obj_id, $a_user_id)
Lookup percentage.
static _lookupId($a_user_str)
Lookup id by login.
static _lookupObjId($a_id)
tryOutcomeService($resource, $ext_account, $a_status, $a_percentage)
try outcome service
$consumer
Definition: demo.php:30
static _checkExternalAuthAccount($a_auth, $a_account, $tryFallback=true)
check whether external account and authentication method matches with a user
static _lookupStatus($a_obj_id, $a_user_id, $a_create=true)
Lookup status.
+ Here is the call graph for this function:

◆ getInstance()

static ilLTIAppEventListener::getInstance ( )
staticprotected
Returns

Definition at line 39 of file class.ilLTIAppEventListener.php.

40  {
41  if (!self::$instance instanceof \ilLTIAppEventListener) {
42  self::$instance = new self();
43  }
44  return self::$instance;
45  }
Class ilLTIAppEventListener.

◆ handleCronUpdate()

static ilLTIAppEventListener::handleCronUpdate ( ilDateTime  $since)
static
Parameters
ilDateTime$since
Returns
bool
Exceptions
ilDateTimeException

Definition at line 187 of file class.ilLTIAppEventListener.php.

Referenced by ilLTICronOutcomeService\run().

188  {
189  $listener = self::getInstance();
190  $listener->doCronUpdate($since);
191  return true;
192  }
+ Here is the caller graph for this function:

◆ handleEvent()

static ilLTIAppEventListener::handleEvent (   $a_component,
  $a_event,
  $a_parameter 
)
static

Handle an event in a listener.

Parameters
string$a_componentcomponent, e.g. "Modules/Forum" or "Services/User"
string$a_eventevent e.g. "createUser", "updateUser", "deleteUser", ...
array$a_parameterparameter array (assoc), array("name" => ..., "phone_office" => ...)

Implements ilAppEventListener.

Definition at line 161 of file class.ilLTIAppEventListener.php.

References $DIC, and $logger.

162  {
163  global $DIC;
164 
165  $logger = $DIC->logger()->lti()->debug('Handling event: ' . $a_event . ' from ' . $a_component);
166 
167  switch ($a_component) {
168  case 'Services/Tracking':
169  if ($a_event == 'updateStatus') {
170  $listener = self::getInstance();
171  $listener->handleUpdateStatus(
172  $a_parameter['obj_id'],
173  $a_parameter['usr_id'],
174  $a_parameter['status'],
175  $a_parameter['percentage']
176  );
177  }
178  break;
179  }
180  }
global $DIC
Definition: saml.php:7

◆ handleUpdateStatus()

ilLTIAppEventListener::handleUpdateStatus (   $a_obj_id,
  $a_usr_id,
  $a_status,
  $a_percentage 
)
protected

Handle update status.

Definition at line 51 of file class.ilLTIAppEventListener.php.

References $consumer, ilObject\_getAllReferences(), ilObjUser\_lookupAuthMode(), ilObjUser\_lookupExternalAccount(), array, isLTIAuthMode(), and tryOutcomeService().

52  {
53  $this->logger->debug('Handle update status');
54  $auth_mode = ilObjUser::_lookupAuthMode($a_usr_id);
55  if (!$this->isLTIAuthMode($auth_mode)) {
56  $this->logger->debug('Ignoring update for non-LTI-user.');
57  return false;
58  }
59  $ext_account = ilObjUser::_lookupExternalAccount($a_usr_id);
60  list($lti, $consumer) = explode('_', $auth_mode);
61 
62  // iterate through all references
63  $refs = ilObject::_getAllReferences($a_obj_id);
64  foreach ((array) $refs as $ref_id) {
65  $resources = $this->connector->lookupResourcesForUserObjectRelation(
66  $ref_id,
67  $ext_account,
68  $consumer
69  );
70  foreach ($resources as $resource) {
71  $this->tryOutcomeService($resource, $ext_account, $a_status, $a_percentage);
72  }
73  }
74  }
static _lookupExternalAccount($a_user_id)
lookup external account for login and authmethod
static _getAllReferences($a_id)
get all reference ids of object
tryOutcomeService($resource, $ext_account, $a_status, $a_percentage)
try outcome service
$consumer
Definition: demo.php:30
Create styles array
The data for the language used.
static _lookupAuthMode($a_usr_id)
lookup auth mode
+ Here is the call graph for this function:

◆ isLTIAuthMode()

ilLTIAppEventListener::isLTIAuthMode (   $auth_mode)
protected
Parameters
$a_usr_id
Returns
bool

Definition at line 117 of file class.ilLTIAppEventListener.php.

Referenced by handleUpdateStatus().

118  {
119  return strpos($auth_mode, 'lti_') === 0;
120  }
+ Here is the caller graph for this function:

◆ tryOutcomeService()

ilLTIAppEventListener::tryOutcomeService (   $resource,
  $ext_account,
  $a_status,
  $a_percentage 
)
protected

try outcome service

Definition at line 126 of file class.ilLTIAppEventListener.php.

References IMSGlobal\LTI\ToolProvider\ResourceLink\fromRecordId(), IMSGlobal\LTI\ToolProvider\User\fromResourceLink(), ilLPStatus\LP_STATUS_COMPLETED_NUM, ilLPStatus\LP_STATUS_FAILED_NUM, and ilLPStatus\LP_STATUS_NOT_ATTEMPTED_NUM.

Referenced by doCronUpdate(), and handleUpdateStatus().

127  {
128  $resource_link = \IMSGlobal\LTI\ToolProvider\ResourceLink::fromRecordId($resource, $this->connector);
129  if (!$resource_link->hasOutcomesService()) {
130  $this->logger->debug('No outcome service available for resource id: ' . $resource);
131  return false;
132  }
133  $user = \IMSGlobal\LTI\ToolProvider\User::fromResourceLink($resource_link, $ext_account);
134 
135  if ($a_status == ilLPStatus::LP_STATUS_COMPLETED_NUM) {
136  $score = 1;
137  } elseif (
138  $a_status == ilLPStatus::LP_STATUS_FAILED_NUM ||
140  ) {
141  $score = 0;
142  } elseif (!$a_percentage) {
143  $score = 0;
144  } else {
145  $score = (int) $a_percentage / 100;
146  }
147 
148  $outcome = new \IMSGlobal\LTI\ToolProvider\Outcome($score);
149 
150  $resource_link->doOutcomesService(
151  \IMSGlobal\LTI\ToolProvider\ResourceLink::EXT_WRITE,
152  $outcome,
153  $user
154  );
155  }
const LP_STATUS_COMPLETED_NUM
static fromResourceLink($resourceLink, $ltiUserId)
Class constructor from resource link.
Definition: User.php:413
const LP_STATUS_NOT_ATTEMPTED_NUM
const LP_STATUS_FAILED_NUM
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $connector

ilLTIAppEventListener::$connector = null
private

Definition at line 22 of file class.ilLTIAppEventListener.php.

◆ $instance

ilLTIAppEventListener::$instance = null
staticprivate

Definition at line 12 of file class.ilLTIAppEventListener.php.

◆ $logger

ilLTIAppEventListener::$logger = null
private

Definition at line 17 of file class.ilLTIAppEventListener.php.

Referenced by handleEvent().


The documentation for this class was generated from the following file: