ILIAS  release_8 Revision v8.23
ilLTIAppEventListener Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

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

Static Public Member Functions

static handleEvent (string $a_component, string $a_event, array $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 (int $a_obj_id, int $a_usr_id, ?float $a_percentage)
 

Protected Member Functions

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

Static Protected Member Functions

static getInstance ()
 

Private Attributes

ilLogger $logger = null
 
ilLTIDataConnector $connector = null
 

Static Private Attributes

static ilLTIAppEventListener $instance = null
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilLTIAppEventListener

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

Constructor & Destructor Documentation

◆ __construct()

ilLTIAppEventListener::__construct ( )
protected

ilLTIAppEventListener constructor.

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

References $DIC, ilLoggerFactory\getLogger(), and ILIAS\Repository\logger().

37  {
38  global $DIC;
39 
40  $this->logger = ilLoggerFactory::getLogger('ltis');
41  $this->connector = new ilLTIDataConnector();
42  }
static getLogger(string $a_component_id)
Get component logger.
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ doCronUpdate()

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

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

References $resources, ilObjUser\_checkExternalAuthAccount(), ilObjUser\_lookupId(), ilObject\_lookupObjId(), ilLPStatus\_lookupPercentage(), ilLPStatus\_lookupStatus(), ILIAS\Repository\logger(), and tryOutcomeService().

91  : void
92  {
93  $this->logger->debug('Starting cron update for lti outcome service');
94 
95  $resources = $this->connector->lookupResourcesForAllUsersSinceDate($since);
96  foreach ($resources as $consumer_ext_account => $user_resources) {
97  list($consumer, $ext_account) = explode('__', $consumer_ext_account, 2);
98 
99  $login = ilObjUser::_checkExternalAuthAccount('lti_' . $consumer, $ext_account);
100  if (!$login) {
101  $this->logger->info('No user found for lti_' . $consumer . ' -> ' . $ext_account);
102  continue;
103  }
104  $usr_id = ilObjUser::_lookupId($login);
105  foreach ($user_resources as $resource_info) {
106  $this->logger->debug('Found resource: ' . $resource_info);
107  list($resource_id, $resource_ref_id) = explode('__', $resource_info);
108 
109  // lookup lp status
110  $status = ilLPStatus::_lookupStatus(
111  ilObject::_lookupObjId((int) $resource_ref_id),
112  $usr_id
113  );
114  $percentage = ilLPStatus::_lookupPercentage(
115  ilObject::_lookupObjId((int) $resource_ref_id),
116  $usr_id
117  );
118  $this->tryOutcomeService((int) $resource_id, $ext_account, $status, $percentage);
119  }
120  }
121  }
$resources
Definition: ltiservices.php:68
static _lookupPercentage(int $a_obj_id, int $a_user_id)
Lookup percentage.
static _lookupId($a_user_str)
static _checkExternalAuthAccount(string $a_auth, string $a_account, bool $tryFallback=true)
check whether external account and authentication method matches with a user
static _lookupObjId(int $ref_id)
tryOutcomeService(int $resource, string $ext_account, int $a_status, int $a_percentage)
try outcome service
static _lookupStatus(int $a_obj_id, int $a_user_id, bool $a_create=true)
Lookup status.
+ Here is the call graph for this function:

◆ getInstance()

static ilLTIAppEventListener::getInstance ( )
staticprotected

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

45  {
46  if (!self::$instance instanceof \ilLTIAppEventListener) {
47  self::$instance = new self();
48  }
49  return self::$instance;
50  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ handleCronUpdate()

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

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

Referenced by ilLTICronOutcomeService\run().

193  : bool
194  {
195  $listener = self::getInstance();
196  $listener->doCronUpdate($since);
197  return true;
198  }
+ Here is the caller graph for this function:

◆ handleEvent()

static ilLTIAppEventListener::handleEvent ( string  $a_component,
string  $a_event,
array  $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 170 of file class.ilLTIAppEventListener.php.

References ilLoggerFactory\getLogger().

170  : void
171  {
173  $logger->debug('Handling event: ' . $a_event . ' from ' . $a_component);
174 
175  if ($a_component == '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  }
186  }
static getLogger(string $a_component_id)
Get component logger.
debug(string $a_message, array $a_context=array())
+ Here is the call graph for this function:

◆ handleOutcomeWithoutLP()

static ilLTIAppEventListener::handleOutcomeWithoutLP ( int  $a_obj_id,
int  $a_usr_id,
?float  $a_percentage 
)
static

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

References $DIC, $ref_id, $resources, ilObject\_getAllReferences(), ilObjUser\_lookupAuthMode(), ilObjUser\_lookupExternalAccount(), ILIAS\LTI\ToolProvider\ResourceLink\fromRecordId(), ILIAS\LTI\ToolProvider\UserResult\fromResourceLink(), ilObjectLP\getInstance(), ilLoggerFactory\getLogger(), and ilLPObjSettings\LP_MODE_DEACTIVATED.

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

201  : void
202  {
203  global $DIC;
204  $score = 0;
206 
207  $auth_mode = ilObjUser::_lookupAuthMode($a_usr_id);
208  if (strpos($auth_mode, 'lti_') === false) {
209  $logger->debug('Ignoring outcome for non-LTI-user.');
210  return;
211  }
212  //check if LearningPress enabled
213  $olp = ilObjectLP::getInstance($a_obj_id);
214  if (ilLPObjSettings::LP_MODE_DEACTIVATED != $olp->getCurrentMode()) {
215  $logger->debug('Ignoring outcome if LP is activated.');
216  return;
217  }
218 
219  if ($a_percentage && $a_percentage > 0) {
220  $score = round($a_percentage / 100, 4);
221  }
222 
224  $ext_account = ilObjUser::_lookupExternalAccount($a_usr_id);
225  list($lti, $consumer) = explode('_', $auth_mode);
226 
227  // iterate through all references
228  $refs = ilObject::_getAllReferences($a_obj_id);
229  foreach ((array) $refs as $ref_id) {
231  $ref_id,
232  $ext_account,
233  (int) $consumer
234  );
235 
236  $logger->debug('Resources for update: ' . dump($resources));
237 
238  foreach ($resources as $resource) {
239  // $this->tryOutcomeService($resource, $ext_account, $a_status, $a_percentage);
241  if ($resource_link->hasOutcomesService()) {
242  $user = \ILIAS\LTI\ToolProvider\UserResult::fromResourceLink($resource_link, $ext_account);
243  $logger->debug('Sending score: ' . (string) $score);
244  $outcome = new \ILIAS\LTI\ToolProvider\Outcome((string) $score);
245 
246  $resource_link->doOutcomesService(
247  \ILIAS\LTI\ToolProvider\ResourceLink::EXT_WRITE,
248  $outcome,
249  $user
250  );
251  }
252  }
253  }
254  }
$resources
Definition: ltiservices.php:68
static getLogger(string $a_component_id)
Get component logger.
lookupResourcesForUserObjectRelation(int $a_ref_id, string $a_lti_user, int $a_ext_consumer, ilDateTime $since=null)
Lookup resources for user object relation.
Class ChatMainBarProvider .
static _getAllReferences(int $id)
get all reference ids for object ID
debug(string $a_message, array $a_context=array())
static _lookupExternalAccount(int $a_user_id)
static _lookupAuthMode(int $a_usr_id)
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(int $obj_id)
static fromResourceLink(ResourceLink $resourceLink, string $ltiUserId)
Class constructor from resource link.
Definition: UserResult.php:265
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleUpdateStatus()

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

Handle update status.

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

References $ref_id, $resources, ilObject\_getAllReferences(), ilObjUser\_lookupAuthMode(), ilObjUser\_lookupExternalAccount(), ilLogLevel\DEBUG, isLTIAuthMode(), ILIAS\Repository\logger(), and tryOutcomeService().

56  : void
57  {
58  $this->logger->debug('Handle update status');
59  $auth_mode = ilObjUser::_lookupAuthMode($a_usr_id);
60  if (!$this->isLTIAuthMode($auth_mode)) {
61  $this->logger->debug('Ignoring update for non-LTI-user.');
62  return;
63  }
64  $ext_account = ilObjUser::_lookupExternalAccount($a_usr_id);
65  list($lti, $consumer) = explode('_', $auth_mode);
66 
67  // iterate through all references
68  $refs = ilObject::_getAllReferences($a_obj_id);
69  $this->logger->debug('Refs for : ' . $a_obj_id . ': ' . count($refs));
70  foreach ((array) $refs as $ref_id) {
71  $resources = $this->connector->lookupResourcesForUserObjectRelation(
72  $ref_id,
73  $ext_account,
74  (int) $consumer
75  );
76 
77  $this->logger->debug('Resources for update:');
78  $this->logger->dump($resources, ilLogLevel::DEBUG);
79 
80  foreach ($resources as $resource) {
81  $this->tryOutcomeService((int) $resource, $ext_account, $a_status, $a_percentage);
82  }
83  }
84  }
$resources
Definition: ltiservices.php:68
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupExternalAccount(int $a_user_id)
static _lookupAuthMode(int $a_usr_id)
$ref_id
Definition: ltiauth.php:67
tryOutcomeService(int $resource, string $ext_account, int $a_status, int $a_percentage)
try outcome service
+ Here is the call graph for this function:

◆ isLTIAuthMode()

ilLTIAppEventListener::isLTIAuthMode ( string  $auth_mode)
protected

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

Referenced by handleUpdateStatus().

123  : bool
124  {
125  return strpos($auth_mode, 'lti_') === 0;
126  }
+ Here is the caller graph for this function:

◆ tryOutcomeService()

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

try outcome service

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

References ILIAS\LTI\ToolProvider\ResourceLink\fromRecordId(), ILIAS\LTI\ToolProvider\UserResult\fromResourceLink(), ILIAS\Repository\int(), ILIAS\Repository\logger(), ilLPStatus\LP_STATUS_COMPLETED_NUM, ilLPStatus\LP_STATUS_FAILED_NUM, and ilLPStatus\LP_STATUS_NOT_ATTEMPTED_NUM.

Referenced by doCronUpdate(), and handleUpdateStatus().

132  : void
133  {
134  $resource_link = \ILIAS\LTI\ToolProvider\ResourceLink::fromRecordId($resource, $this->connector);
135  if (!$resource_link->hasOutcomesService()) {
136  $this->logger->debug('No outcome service available for resource id: ' . $resource);
137  return;
138  }
139  $this->logger->debug('Trying outcome service with status ' . $a_status . ' and percentage ' . $a_percentage);
140  $user = \ILIAS\LTI\ToolProvider\UserResult::fromResourceLink($resource_link, $ext_account);
141 
142  if ($a_status == ilLPStatus::LP_STATUS_COMPLETED_NUM) {
143  $score = 1;
144  } elseif (
145  $a_status == ilLPStatus::LP_STATUS_FAILED_NUM ||
147  ) {
148  $score = 0;
149  } elseif (!$a_percentage) {
150  $score = 0;
151  } else {
152  $score = (int) round($a_percentage / 100);
153  }
154 
155  $this->logger->debug('Sending score: ' . (string) $score);
156 
157  $outcome = new \ILIAS\LTI\ToolProvider\Outcome((string) $score);
158 
159  $resource_link->doOutcomesService(
160  \ILIAS\LTI\ToolProvider\ResourceLink::EXT_WRITE,
161  $outcome,
162  $user
163  );
164  }
const LP_STATUS_COMPLETED_NUM
Class ChatMainBarProvider .
const LP_STATUS_NOT_ATTEMPTED_NUM
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const LP_STATUS_FAILED_NUM
static fromResourceLink(ResourceLink $resourceLink, string $ltiUserId)
Class constructor from resource link.
Definition: UserResult.php:265
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $connector

ilLTIDataConnector ilLTIAppEventListener::$connector = null
private

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

◆ $instance

ilLTIAppEventListener ilLTIAppEventListener::$instance = null
staticprivate

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

◆ $logger

ilLogger ilLTIAppEventListener::$logger = null
private

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


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