ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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)
 
static handleOutcomeWithoutLP ($a_obj_id, $a_usr_id, $a_percentage)
 
static handleEvent ($a_component, $a_event, $a_parameter)
 Handle an event in a listener. More...
 

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.

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

References $DIC.

Member Function Documentation

◆ doCronUpdate()

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

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

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

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

+ Here is the call graph for this function:

◆ getInstance()

static ilLTIAppEventListener::getInstance ( )
staticprotected
Returns
\ilLTIAppEventListener

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.

References $instance.

Referenced by handleCronUpdate(), and handleEvent().

+ Here is the caller graph for this function:

◆ handleCronUpdate()

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

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

195 {
196 $listener = self::getInstance();
197 $listener->doCronUpdate($since);
198 return true;
199 }

References getInstance().

Referenced by ilLTICronOutcomeService\run().

+ Here is the call graph for this function:
+ 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 168 of file class.ilLTIAppEventListener.php.

169 {
170 global $DIC;
171
172 $logger = $DIC->logger()->lti()->debug('Handling event: ' . $a_event . ' from ' . $a_component);
173
174 switch ($a_component) {
175 case 'Services/Tracking':
176 if ($a_event == 'updateStatus') {
177 $listener = self::getInstance();
178 $listener->handleUpdateStatus(
179 $a_parameter['obj_id'],
180 $a_parameter['usr_id'],
181 $a_parameter['status'],
182 $a_parameter['percentage']
183 );
184 }
185 break;
186 }
187 }

References $DIC, $logger, and getInstance().

+ Here is the call graph for this function:

◆ handleOutcomeWithoutLP()

static ilLTIAppEventListener::handleOutcomeWithoutLP (   $a_obj_id,
  $a_usr_id,
  $a_percentage 
)
static

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

203 {
204 global $DIC;
205 $score = 0;
206
207 $auth_mode = ilObjUser::_lookupAuthMode($a_usr_id);
208 if (strpos($auth_mode, 'lti_') === false) {
209 $DIC->logger()->lti()->debug('Ignoring outcome for non-LTI-user.');
210 return false;
211 }
212 //check if LearningPress enabled
213 $olp = ilObjectLP::getInstance($a_obj_id);
214 if (ilLPObjSettings::LP_MODE_DEACTIVATED != $olp->getCurrentMode())
215 {
216 $DIC->logger()->lti()->debug('Ignoring outcome if LP is activated.');
217 return false;
218 }
219
220 if ($a_percentage && $a_percentage > 0) {
221 $score = round($a_percentage/100, 4);
222 }
223
225 $ext_account = ilObjUser::_lookupExternalAccount($a_usr_id);
226 list($lti, $consumer) = explode('_', $auth_mode);
227
228 // iterate through all references
229 $refs = ilObject::_getAllReferences($a_obj_id);
230 foreach ((array) $refs as $ref_id) {
231 $resources = $connector->lookupResourcesForUserObjectRelation(
232 $ref_id,
233 $ext_account,
234 $consumer
235 );
236
237 $DIC->logger()->lti()->debug('Resources for update: '.$resources);
238
239 foreach ($resources as $resource) {
240 // $this->tryOutcomeService($resource, $ext_account, $a_status, $a_percentage);
241 $resource_link = \IMSGlobal\LTI\ToolProvider\ResourceLink::fromRecordId($resource, $connector);
242 if ($resource_link->hasOutcomesService()) {
243 $user = \IMSGlobal\LTI\ToolProvider\User::fromResourceLink($resource_link, $ext_account);
244 $DIC->logger()->lti()->debug('Sending score: ' . (string) $score);
245 $outcome = new \IMSGlobal\LTI\ToolProvider\Outcome($score);
246
247 $resource_link->doOutcomesService(
248 \IMSGlobal\LTI\ToolProvider\ResourceLink::EXT_WRITE,
249 $outcome,
250 $user
251 );
252 }
253 }
254 }
255 }
static _lookupExternalAccount($a_user_id)
lookup external account for login and authmethod
static _lookupAuthMode($a_usr_id)
lookup auth mode
static getInstance($a_obj_id)
static _getAllReferences($a_id)
get all reference ids of object

References $connector, $DIC, ilObject\_getAllReferences(), ilObjUser\_lookupAuthMode(), ilObjUser\_lookupExternalAccount(), ilObjectLP\getInstance(), and ilLPObjSettings\LP_MODE_DEACTIVATED.

Referenced by ilSCORM2004StoreData\persistCMIData(), and ilObjSCORMTracking\storeJsApiCmi().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

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
71 $this->logger->debug('Resources for update:');
72 $this->logger->dump($resources, ilLogLevel::DEBUG);
73
74 foreach ($resources as $resource) {
75 $this->tryOutcomeService($resource, $ext_account, $a_status, $a_percentage);
76 }
77 }
78 }

References ilObject\_getAllReferences(), ilObjUser\_lookupAuthMode(), ilObjUser\_lookupExternalAccount(), ilLogLevel\DEBUG, isLTIAuthMode(), and tryOutcomeService().

+ Here is the call graph for this function:

◆ isLTIAuthMode()

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

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

122 {
123 return strpos($auth_mode, 'lti_') === 0;
124 }

Referenced by handleUpdateStatus().

+ 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 130 of file class.ilLTIAppEventListener.php.

131 {
132 $resource_link = \IMSGlobal\LTI\ToolProvider\ResourceLink::fromRecordId($resource, $this->connector);
133 if (!$resource_link->hasOutcomesService()) {
134 $this->logger->debug('No outcome service available for resource id: ' . $resource);
135 return false;
136 }
137 $this->logger->debug('Trying outcome service with status ' . $a_status . ' and percentage ' . $a_percentage);
138 $user = \IMSGlobal\LTI\ToolProvider\User::fromResourceLink($resource_link, $ext_account);
139
140 if ($a_status == ilLPStatus::LP_STATUS_COMPLETED_NUM) {
141 $score = 1;
142 } elseif (
145 ) {
146 $score = 0;
147 } elseif (!$a_percentage) {
148 $score = 0;
149 } else {
150 $score = (int) $a_percentage / 100;
151 }
152
153 $this->logger->debug('Sending score: ' . (string) $score);
154
155 $outcome = new \IMSGlobal\LTI\ToolProvider\Outcome($score);
156
157 $resource_link->doOutcomesService(
158 \IMSGlobal\LTI\ToolProvider\ResourceLink::EXT_WRITE,
159 $outcome,
160 $user
161 );
162 }
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
const LP_STATUS_FAILED_NUM

References ilLPStatus\LP_STATUS_COMPLETED_NUM, ilLPStatus\LP_STATUS_FAILED_NUM, and ilLPStatus\LP_STATUS_NOT_ATTEMPTED_NUM.

Referenced by doCronUpdate(), and handleUpdateStatus().

+ Here is the caller graph for this function:

Field Documentation

◆ $connector

ilLTIAppEventListener::$connector = null
private

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

Referenced by handleOutcomeWithoutLP().

◆ $instance

ilLTIAppEventListener::$instance = null
staticprivate

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

Referenced by getInstance().

◆ $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: