ILIAS  release_8 Revision v8.24
ilCertificateAppEventListener Class Reference
+ Inheritance diagram for ilCertificateAppEventListener:
+ Collaboration diagram for ilCertificateAppEventListener:

Public Member Functions

 __construct (ilDBInterface $db, ilObjectDataCache $objectDataCache, ilLogger $logger)
 
 withComponent (string $component)
 
 withEvent (string $event)
 
 withParameters (array $parameters)
 
 handle ()
 

Static Public Member Functions

static handleEvent (string $a_component, string $a_event, array $a_parameter)
 
static handleEvent (string $a_component, string $a_event, array $a_parameter)
 Handle an event in a listener. More...
 

Protected Member Functions

 isLearningAchievementEvent ()
 
 isUserDeletedEvent ()
 
 isCompletedStudyProgramme ()
 

Protected Attributes

ilDBInterface $db
 
string $component = ''
 
string $event = ''
 
array $parameters = []
 

Private Member Functions

 handleLPUpdate ()
 
 handleDeletedUser ()
 
 processEntry (string $type, int $objectId, int $userId, ilCertificateTemplate $template, ilSetting $settings)
 
 handleCompletedStudyProgramme ()
 

Private Attributes

ilObjectDataCache $objectDataCache
 
ilLogger $logger
 
ilCertificateQueueRepository $certificateQueueRepository
 
ilCertificateTypeClassMap $certificateClassMap
 
ilCertificateTemplateRepository $templateRepository
 
ilUserCertificateRepository $userCertificateRepository
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilCertificateAppEventListener::__construct ( ilDBInterface  $db,
ilObjectDataCache  $objectDataCache,
ilLogger  $logger 
)

Definition at line 42 of file class.ilCertificateAppEventListener.php.

References $db, $logger, $objectDataCache, and ILIAS\Repository\logger().

+ Here is the call graph for this function:

Member Function Documentation

◆ handle()

ilCertificateAppEventListener::handle ( )
Exceptions
IOException

Definition at line 110 of file class.ilCertificateAppEventListener.php.

110 : void
111 {
112 try {
113 if ($this->isLearningAchievementEvent()) {
114 $this->handleLPUpdate();
115 } elseif ($this->isUserDeletedEvent()) {
116 $this->handleDeletedUser();
117 } elseif ($this->isCompletedStudyProgramme()) {
119 }
120 } catch (ilException $e) {
121 $this->logger->error($e->getMessage());
122 }
123 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References Vendor\Package\$e, handleCompletedStudyProgramme(), handleDeletedUser(), handleLPUpdate(), isCompletedStudyProgramme(), isLearningAchievementEvent(), isUserDeletedEvent(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

◆ handleCompletedStudyProgramme()

ilCertificateAppEventListener::handleCompletedStudyProgramme ( )
private

Definition at line 328 of file class.ilCertificateAppEventListener.php.

328 : void
329 {
330 $settings = new ilSetting('certificate');
331 $objectId = $this->parameters['prg_id'] ?? 0;
332 $userId = $this->parameters['usr_id'] ?? 0;
333 try {
334 $template = $this->templateRepository->fetchCurrentlyActiveCertificate($objectId);
335 if (true === $template->isCurrentlyActive()) {
336 $entry = new ilCertificateQueueEntry(
337 $objectId,
338 $userId,
339 ilStudyProgrammePlaceholderValues::class,
341 $template->getId(),
342 time()
343 );
344 $mode = $settings->get('persistent_certificate_mode', '');
345 if ($mode === 'persistent_certificate_mode_instant') {
346 $cronjob = new ilCertificateCron();
347 $cronjob->init();
348 $cronjob->processEntry(0, $entry, []);
349 return;
350 }
351 $this->certificateQueueRepository->addToQueue($entry);
352 }
353 } catch (ilException $exception) {
354 $this->logger->warning($exception->getMessage());
355 }
356 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200

References ILIAS\LTI\ToolProvider\$settings, ilCertificateTemplate\getId(), ilCronConstants\IN_PROGRESS, ilCertificateTemplate\isCurrentlyActive(), and ILIAS\Repository\logger().

Referenced by handle().

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

◆ handleDeletedUser()

ilCertificateAppEventListener::handleDeletedUser ( )
private
Exceptions
IOException

Definition at line 274 of file class.ilCertificateAppEventListener.php.

274 : void
275 {
276 $portfolioFileService = new ilPortfolioCertificateFileService();
277
278 if (false === array_key_exists('usr_id', $this->parameters)) {
279 $this->logger->error('User ID is not added to the event. Abort.');
280 return;
281 }
282
283 $this->logger->debug('User has been deleted. Try to delete user certificates');
284
285 $userId = $this->parameters['usr_id'];
286
287 $this->userCertificateRepository->deleteUserCertificates((int) $userId);
288
289 $this->certificateQueueRepository->removeFromQueueByUserId((int) $userId);
290
291 $portfolioFileService->deleteUserDirectory($userId);
292
293 $this->logger->debug(sprintf(
294 'All relevant data sources for the user certificates for user (usr_id: "%s" deleted)',
295 $userId
296 ));
297 }

References ILIAS\Repository\logger().

Referenced by handle().

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

◆ handleEvent()

static ilCertificateAppEventListener::handleEvent ( string  $a_component,
string  $a_event,
array  $a_parameter 
)
static
Parameters
string$a_component
string$a_event
array$a_parameter
Exceptions
IOException

Implements ilAppEventListener.

Definition at line 131 of file class.ilCertificateAppEventListener.php.

131 : void
132 {
133 global $DIC;
134
135 $listener = new self(
136 $DIC->database(),
137 $DIC['ilObjDataCache'],
138 $DIC->logger()->cert()
139 );
140
141 $listener
142 ->withComponent($a_component)
143 ->withEvent($a_event)
144 ->withParameters($a_parameter)
145 ->handle();
146 }
global $DIC
Definition: feed.php:28

References $DIC.

◆ handleLPUpdate()

ilCertificateAppEventListener::handleLPUpdate ( )
private

Definition at line 148 of file class.ilCertificateAppEventListener.php.

148 : void
149 {
150 $status = (int) ($this->parameters['status'] ?? ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM);
151
152 $settings = new ilSetting('certificate');
153
154 if ($status === ilLPStatus::LP_STATUS_COMPLETED_NUM) {
155 $objectId = (int) ($this->parameters['obj_id'] ?? 0);
156 $userId = (int) ($this->parameters['usr_id'] ?? 0);
157
158 $type = $this->objectDataCache->lookupType($objectId);
159
160 $this->logger->debug(sprintf(
161 "Certificate evaluation triggered, received 'completed' learning progress for: usr_id: %s/obj_id: %s/type: %s",
162 $userId,
163 $objectId,
164 $type
165 ));
166
167 if ($this->certificateClassMap->typeExistsInMap($type)) {
168 try {
169 $template = $this->templateRepository->fetchCurrentlyActiveCertificate($objectId);
170
171 if (true === $template->isCurrentlyActive()) {
172 $this->logger->debug(sprintf(
173 "Trigger persisting certificate achievement for: usr_id: %s/obj_id: %s/type: %s/template_id: %s",
174 $userId,
175 $objectId,
176 $type,
177 $template->getId()
178 ));
179 $this->processEntry($type, $objectId, $userId, $template, $settings);
180 } else {
181 $this->logger->debug(sprintf(
182 "Did not trigger certificate achievement for inactive template: usr_id: %s/obj_id: %s/type: %s/template_id: %s",
183 $userId,
184 $objectId,
185 $type,
186 $template->getId()
187 ));
188 }
189 } catch (ilException $exception) {
190 $this->logger->debug(sprintf(
191 "Did not find an active certificate template for case: usr_id: %s/obj_id: %s/type: %s",
192 $userId,
193 $objectId,
194 $type
195 ));
196 }
197 } else {
198 $this->logger->debug(
199 "Object type ($type) is not of interest, skipping certificate evaluation for this object"
200 );
201 }
202
203 if ($type === 'crs') {
204 $this->logger->debug(
205 'Skipping handling for course, because courses cannot be certificate trigger ' .
206 '(with globally disabled learning progress) for other certificate enabled objects'
207 );
208 return;
209 }
210
211 $this->logger->debug(
212 'Triggering certificate evaluation of possible depending course objects ...'
213 );
214
215 $progressEvaluation = new ilCertificateCourseLearningProgressEvaluation(
217 $this->templateRepository
218 )
219 );
220 foreach (ilObject::_getAllReferences($objectId) as $refId) {
221 $templatesOfCompletedCourses = $progressEvaluation->evaluate($refId, $userId);
222 if (0 === count($templatesOfCompletedCourses)) {
223 $this->logger->debug(sprintf(
224 "No dependent course certificate template configuration found for child object: usr_id: %s/obj_id: %s/ref_id: %s/type: %s",
225 $userId,
226 $objectId,
227 $refId,
228 $type
229 ));
230 continue;
231 }
232
233 foreach ($templatesOfCompletedCourses as $courseTemplate) {
234 // We do not check if we support the type anymore, because the type 'crs' is always supported
235 try {
236 $courseObjectId = $courseTemplate->getObjId();
237
238 if (true === $courseTemplate->isCurrentlyActive()) {
239 $type = $this->objectDataCache->lookupType($courseObjectId);
240
241 $this->logger->debug(sprintf(
242 "Trigger persisting certificate achievement for: usr_id: %s/obj_id: %s/type: %s/template_id: %s",
243 $userId,
244 $courseObjectId,
245 'crs',
246 $courseTemplate->getId()
247 ));
248 $this->processEntry($type, $courseObjectId, $userId, $courseTemplate, $settings);
249 } else {
250 $this->logger->debug(sprintf(
251 "Did not trigger certificate achievement for inactive template: usr_id: %s/obj_id: %s/type: %s/template_id: %s",
252 $userId,
253 $objectId,
254 $type,
255 $courseTemplate->getId()
256 ));
257 }
258 } catch (ilException $exception) {
259 $this->logger->warning($exception->getMessage());
260 continue;
261 }
262 }
263 }
264
265 $this->logger->debug(
266 'Finished certificate evaluation'
267 );
268 }
269 }
A certicate template repository which caches results of query commands List of cached results (other ...
processEntry(string $type, int $objectId, int $userId, ilCertificateTemplate $template, ilSetting $settings)
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
static _getAllReferences(int $id)
get all reference ids for object ID
$type
$refId
Definition: xapitoken.php:58

References $refId, ILIAS\LTI\ToolProvider\$settings, $type, ilObject\_getAllReferences(), ILIAS\Repository\int(), ILIAS\Repository\logger(), ilLPStatus\LP_STATUS_COMPLETED_NUM, ilLPStatus\LP_STATUS_NOT_ATTEMPTED_NUM, and processEntry().

Referenced by handle().

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

◆ isCompletedStudyProgramme()

ilCertificateAppEventListener::isCompletedStudyProgramme ( )
protected

Definition at line 99 of file class.ilCertificateAppEventListener.php.

99 : bool
100 {
101 return (
102 'Modules/StudyProgramme' === $this->component &&
103 'userSuccessful' === $this->event
104 );
105 }

References ILIAS\Repository\event().

Referenced by handle().

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

◆ isLearningAchievementEvent()

ilCertificateAppEventListener::isLearningAchievementEvent ( )
protected

Definition at line 83 of file class.ilCertificateAppEventListener.php.

83 : bool
84 {
85 return (
86 'Services/Tracking' === $this->component &&
87 'updateStatus' === $this->event
88 );
89 }

References ILIAS\Repository\event().

Referenced by handle().

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

◆ isUserDeletedEvent()

ilCertificateAppEventListener::isUserDeletedEvent ( )
protected

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

91 : bool
92 {
93 return (
94 'Services/User' === $this->component &&
95 'deleteUser' === $this->event
96 );
97 }

References ILIAS\Repository\event().

Referenced by handle().

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

◆ processEntry()

ilCertificateAppEventListener::processEntry ( string  $type,
int  $objectId,
int  $userId,
ilCertificateTemplate  $template,
ilSetting  $settings 
)
private

Definition at line 299 of file class.ilCertificateAppEventListener.php.

305 : void {
306 $className = $this->certificateClassMap->getPlaceHolderClassNameByType($type);
307
308 $entry = new ilCertificateQueueEntry(
309 $objectId,
310 $userId,
311 $className,
313 $template->getId(),
314 time()
315 );
316
317 $mode = $settings->get('persistent_certificate_mode', 'persistent_certificate_mode_cron');
318 if ($mode === 'persistent_certificate_mode_instant') {
319 $cronjob = new ilCertificateCron();
320 $cronjob->init();
321 $cronjob->processEntry(0, $entry, []);
322 return;
323 }
324
325 $this->certificateQueueRepository->addToQueue($entry);
326 }

Referenced by handleLPUpdate().

+ Here is the caller graph for this function:

◆ withComponent()

ilCertificateAppEventListener::withComponent ( string  $component)

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

56 : self
57 {
58 $clone = clone $this;
59
60 $clone->component = $component;
61
62 return $clone;
63 }

References $component.

◆ withEvent()

ilCertificateAppEventListener::withEvent ( string  $event)

Definition at line 65 of file class.ilCertificateAppEventListener.php.

65 : self
66 {
67 $clone = clone $this;
68
69 $clone->event = $event;
70
71 return $clone;
72 }

References $event.

◆ withParameters()

ilCertificateAppEventListener::withParameters ( array  $parameters)

Definition at line 74 of file class.ilCertificateAppEventListener.php.

74 : self
75 {
76 $clone = clone $this;
77
78 $clone->parameters = $parameters;
79
80 return $clone;
81 }

References $parameters.

Field Documentation

◆ $certificateClassMap

ilCertificateTypeClassMap ilCertificateAppEventListener::$certificateClassMap
private

Definition at line 38 of file class.ilCertificateAppEventListener.php.

◆ $certificateQueueRepository

ilCertificateQueueRepository ilCertificateAppEventListener::$certificateQueueRepository
private

Definition at line 37 of file class.ilCertificateAppEventListener.php.

◆ $component

string ilCertificateAppEventListener::$component = ''
protected

Definition at line 34 of file class.ilCertificateAppEventListener.php.

Referenced by withComponent().

◆ $db

ilDBInterface ilCertificateAppEventListener::$db
protected

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

Referenced by __construct().

◆ $event

string ilCertificateAppEventListener::$event = ''
protected

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

Referenced by withEvent().

◆ $logger

ilLogger ilCertificateAppEventListener::$logger
private

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

Referenced by __construct().

◆ $objectDataCache

ilObjectDataCache ilCertificateAppEventListener::$objectDataCache
private

Definition at line 32 of file class.ilCertificateAppEventListener.php.

Referenced by __construct().

◆ $parameters

array ilCertificateAppEventListener::$parameters = []
protected

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

Referenced by withParameters().

◆ $templateRepository

ilCertificateTemplateRepository ilCertificateAppEventListener::$templateRepository
private

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

◆ $userCertificateRepository

ilUserCertificateRepository ilCertificateAppEventListener::$userCertificateRepository
private

Definition at line 40 of file class.ilCertificateAppEventListener.php.


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