ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilLTIAppEventListener Class Reference

Class ilLTIAppEventListener. 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. "components/ILIAS/Forum" or "components/ILIAS/User"
string$a_eventevent e.g. "createUser", "updateUser", "deleteUser", ...
array<string,mixed>$a_parameter parameter 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

Class ilLTIAppEventListener.

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

Constructor & Destructor Documentation

◆ __construct()

ilLTIAppEventListener::__construct ( )
protected

ilLTIAppEventListener constructor.

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

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

42  {
43  global $DIC;
44 
45  $this->logger = ilLoggerFactory::getLogger('ltis');
46  $this->connector = new ilLTIDataConnector();
47  }
static getLogger(string $a_component_id)
Get component logger.
global $DIC
Definition: shib_login.php:26
+ 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 96 of file class.ilLTIAppEventListener.php.

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

96  : void
97  {
98  $this->logger->debug('Starting cron update for lti outcome service');
99 
100  $resources = $this->connector->lookupResourcesForAllUsersSinceDate($since);
101  foreach ($resources as $consumer_ext_account => $user_resources) {
102  list($consumer, $ext_account) = explode('__', $consumer_ext_account, 2);
103 
104  $login = ilObjUser::_checkExternalAuthAccount('lti_' . $consumer, $ext_account);
105  if (!$login) {
106  $this->logger->info('No user found for lti_' . $consumer . ' -> ' . $ext_account);
107  continue;
108  }
109  $usr_id = ilObjUser::_lookupId($login);
110  foreach ($user_resources as $resource_info) {
111  $this->logger->debug('Found resource: ' . $resource_info);
112  list($resource_id, $resource_ref_id) = explode('__', $resource_info);
113 
114  // lookup lp status
115  $status = ilLPStatus::_lookupStatus(
116  ilObject::_lookupObjId((int) $resource_ref_id),
117  $usr_id
118  );
119  $percentage = ilLPStatus::_lookupPercentage(
120  ilObject::_lookupObjId((int) $resource_ref_id),
121  $usr_id
122  );
123  $this->tryOutcomeService((int) $resource_id, $ext_account, $status, $percentage);
124  }
125  }
126  }
$resources
Definition: ltiservices.php:65
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 49 of file class.ilLTIAppEventListener.php.

50  {
51  if (!self::$instance instanceof \ilLTIAppEventListener) {
52  self::$instance = new self();
53  }
54  return self::$instance;
55  }
Class ilLTIAppEventListener.

◆ handleCronUpdate()

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

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

Referenced by ilLTICronOutcomeService\run().

198  : bool
199  {
200  $listener = self::getInstance();
201  $listener->doCronUpdate($since);
202  return true;
203  }
+ 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. "components/ILIAS/Forum" or "components/ILIAS/User"
string$a_eventevent e.g. "createUser", "updateUser", "deleteUser", ...
array<string,mixed>$a_parameter parameter array (assoc), array("name" => ..., "phone_office" => ...)

Implements ilAppEventListener.

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

References ilLoggerFactory\getLogger().

175  : void
176  {
178  $logger->debug('Handling event: ' . $a_event . ' from ' . $a_component);
179 
180  if ($a_component == 'components/ILIAS/Tracking') {
181  if ($a_event == 'updateStatus') {
182  $listener = self::getInstance();
183  $listener->handleUpdateStatus(
184  $a_parameter['obj_id'],
185  $a_parameter['usr_id'],
186  $a_parameter['status'],
187  $a_parameter['percentage']
188  );
189  }
190  }
191  }
static getLogger(string $a_component_id)
Get component logger.
debug(string $message, array $context=[])
+ 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 206 of file class.ilLTIAppEventListener.php.

References $DIC, $ref_id, $resources, ilObject\_getAllReferences(), ilObjUser\_lookupAuthMode(), ilObjUser\_lookupExternalAccount(), ilObjectLP\getInstance(), ilLoggerFactory\getLogger(), and ilLPObjSettings\LP_MODE_DEACTIVATED.

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

206  : void
207  {
208  global $DIC;
209  $score = 0;
211 
212  $auth_mode = ilObjUser::_lookupAuthMode($a_usr_id);
213  if (strpos($auth_mode, 'lti_') === false) {
214  $logger->debug('Ignoring outcome for non-LTI-user.');
215  return;
216  }
217  //check if LearningPress enabled
218  $olp = ilObjectLP::getInstance($a_obj_id);
219  if (ilLPObjSettings::LP_MODE_DEACTIVATED != $olp->getCurrentMode()) {
220  $logger->debug('Ignoring outcome if LP is activated.');
221  return;
222  }
223 
224  if ($a_percentage && $a_percentage > 0) {
225  $score = round($a_percentage / 100, 4);
226  }
227 
229  $ext_account = ilObjUser::_lookupExternalAccount($a_usr_id);
230  list($lti, $consumer) = explode('_', $auth_mode);
231 
232  // iterate through all references
233  $refs = ilObject::_getAllReferences($a_obj_id);
234  foreach ((array) $refs as $ref_id) {
236  $ref_id,
237  $ext_account,
238  (int) $consumer
239  );
240 
241  $logger->debug('Resources for update: ' . dump($resources));
242 
243  foreach ($resources as $resource) {
244  // $this->tryOutcomeService($resource, $ext_account, $a_status, $a_percentage);
245  $resource_link = ResourceLink::fromRecordId($resource, $connector);
246  if ($resource_link->hasOutcomesService()) {
247  $user = UserResult::fromResourceLink($resource_link, $ext_account);
248  $logger->debug('Sending score: ' . (string) $score);
249  $outcome = new Outcome((string) $score);
250 
251  $resource_link->doOutcomesService(
252  ServiceAction::Write,
253  $outcome,
254  $user
255  );
256  }
257  }
258  }
259  }
$resources
Definition: ltiservices.php:65
static getLogger(string $a_component_id)
Get component logger.
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:65
global $DIC
Definition: shib_login.php:26
lookupResourcesForUserObjectRelation(int $a_ref_id, string $a_lti_user, int $a_ext_consumer, ?ilDateTime $since=null)
Lookup resources for user object relation.
debug(string $message, array $context=[])
static getInstance(int $obj_id)
+ 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 61 of file class.ilLTIAppEventListener.php.

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

61  : void
62  {
63  $this->logger->debug('Handle update status');
64  $auth_mode = ilObjUser::_lookupAuthMode($a_usr_id);
65  if (!$this->isLTIAuthMode($auth_mode)) {
66  $this->logger->debug('Ignoring update for non-LTI-user.');
67  return;
68  }
69  $ext_account = ilObjUser::_lookupExternalAccount($a_usr_id);
70  list($lti, $consumer) = explode('_', $auth_mode);
71 
72  // iterate through all references
73  $refs = ilObject::_getAllReferences($a_obj_id);
74  $this->logger->debug('Refs for : ' . $a_obj_id . ': ' . count($refs));
75  foreach ((array) $refs as $ref_id) {
76  $resources = $this->connector->lookupResourcesForUserObjectRelation(
77  $ref_id,
78  $ext_account,
79  (int) $consumer
80  );
81 
82  $this->logger->debug('Resources for update:');
83  $this->logger->dump($resources, ilLogLevel::DEBUG);
84 
85  foreach ($resources as $resource) {
86  $this->tryOutcomeService((int) $resource, $ext_account, $a_status, $a_percentage);
87  }
88  }
89  }
$resources
Definition: ltiservices.php:65
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:65
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 128 of file class.ilLTIAppEventListener.php.

Referenced by handleUpdateStatus().

128  : bool
129  {
130  return strpos($auth_mode, 'lti_') === 0;
131  }
+ 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 137 of file class.ilLTIAppEventListener.php.

References 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().

137  : void
138  {
139  $resource_link = ResourceLink::fromRecordId($resource, $this->connector);
140  if (!$resource_link->hasOutcomesService()) {
141  $this->logger->debug('No outcome service available for resource id: ' . $resource);
142  return;
143  }
144  $this->logger->debug('Trying outcome service with status ' . $a_status . ' and percentage ' . $a_percentage);
145  $user = UserResult::fromResourceLink($resource_link, $ext_account);
146 
147  if ($a_status == ilLPStatus::LP_STATUS_COMPLETED_NUM) {
148  $score = 1;
149  } elseif (
150  $a_status == ilLPStatus::LP_STATUS_FAILED_NUM ||
152  ) {
153  $score = 0;
154  } elseif (!$a_percentage) {
155  $score = 0;
156  } else {
157  $score = (int) round($a_percentage / 100);
158  }
159 
160  $this->logger->debug('Sending score: ' . (string) $score);
161 
162  $outcome = new Outcome((string) $score);
163 
164  $resource_link->doOutcomesService(
165  ServiceAction::Write,
166  $outcome,
167  $user
168  );
169  }
const LP_STATUS_COMPLETED_NUM
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

ilLTIDataConnector ilLTIAppEventListener::$connector = null
private

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

◆ $instance

ilLTIAppEventListener ilLTIAppEventListener::$instance = null
staticprivate

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

◆ $logger

ilLogger ilLTIAppEventListener::$logger = null
private

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


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