ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilCertificateAppEventListener Class Reference
+ Inheritance diagram for ilCertificateAppEventListener:
+ Collaboration diagram for ilCertificateAppEventListener:

Public Member Functions

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

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

Protected Member Functions

 isLearningAchievementEvent ()
 
 isMigratingCertificateEvent ()
 
 isUserDeletedEvent ()
 

Protected Attributes

 $db
 
 $component = ''
 
 $event = ''
 
 $parameters = []
 

Private Member Functions

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

Private Attributes

 $objectDataCache
 
 $logger
 
 $certificateQueueRepository
 
 $certificateClassMap
 
 $templateRepository
 
 $userCertificateRepository
 
 $migrationRepository
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

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

ilCertificateAppEventListener constructor.

Parameters
\ilDBInterface$db
\ilObjectDataCache$objectDataCache
\ilLogger$logger

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

References $db, $logger, and $objectDataCache.

67  {
68  $this->db = $db;
69  $this->objectDataCache = $objectDataCache;
70  $this->logger = $logger;
71  $this->certificateQueueRepository = new \ilCertificateQueueRepository($this->db, $this->logger);
72  $this->certificateClassMap = new \ilCertificateTypeClassMap();
73  $this->templateRepository = new \ilCertificateTemplateRepository($this->db, $this->logger);
74  $this->userCertificateRepository = new \ilUserCertificateRepository($this->db, $this->logger);
75  $this->migrationRepository = new ilCertificateMigrationRepository($this->db, $this->logger);
76  }

Member Function Documentation

◆ handle()

ilCertificateAppEventListener::handle ( )

◆ handleDeletedUser()

ilCertificateAppEventListener::handleDeletedUser ( )
private
Exceptions

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

Referenced by handle().

415  {
416  $portfolioFileService = new ilPortfolioCertificateFileService();
417 
418  if (false === array_key_exists('usr_id', $this->parameters)) {
419  $this->logger->error('User ID is not added to the event. Abort.');
420  return;
421  }
422 
423  $this->logger->info('User has been deleted. Try to delete user certificates');
424 
425  $userId = $this->parameters['usr_id'];
426 
427  $this->userCertificateRepository->deleteUserCertificates((int) $userId);
428 
429  $this->certificateQueueRepository->removeFromQueueByUserId((int) $userId);
430 
431  $this->migrationRepository->deleteFromMigrationJob((int) $userId);
432 
433  $portfolioFileService->deleteUserDirectory($userId);
434 
435  $this->logger->info(sprintf('All relevant data sources for the user certificates for user(user_id: "%s" deleted)', $userId));
436  }
+ Here is the caller graph for this function:

◆ handleEvent()

static ilCertificateAppEventListener::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 171 of file class.ilCertificateAppEventListener.php.

References $DIC.

172  {
173  global $DIC;
174 
175  $listener = new static(
176  $DIC->database(),
177  $DIC['ilObjDataCache'],
178  $DIC->logger()->cert()
179  );
180 
181  $listener
182  ->withComponent($a_component)
183  ->withEvent($a_event)
184  ->withParameters($a_parameter)
185  ->handle();
186  }
global $DIC
Definition: saml.php:7

◆ handleLPUpdate()

ilCertificateAppEventListener::handleLPUpdate ( )
private
Exceptions

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

References $template, $templateRepository, $type, ilObject\_getAllReferences(), ilLPStatus\LP_STATUS_COMPLETED_NUM, and processEntry().

Referenced by handle().

192  {
193  $status = $this->parameters['status'] ?? \ilLpStatus::LP_STATUS_NOT_ATTEMPTED_NUM;
194 
195  $settings = new ilSetting('certificate');
196 
197  if ($status == \ilLPStatus::LP_STATUS_COMPLETED_NUM) {
198  $objectId = $this->parameters['obj_id'] ?? 0;
199  $userId = $this->parameters['usr_id'] ?? 0;
200 
201  $type = $this->objectDataCache->lookupType($objectId);
202 
203  $this->logger->info(sprintf(
204  "Certificate evaluation triggered, received 'completed' learning progress for: usr_id: %s/obj_id: %s/type: %s",
205  $userId,
206  $objectId,
207  $type
208  ));
209 
210  if ($this->certificateClassMap->typeExistsInMap($type)) {
211  try {
212  $template = $this->templateRepository->fetchCurrentlyActiveCertificate($objectId);
213 
214  if (true === $template->isCurrentlyActive()) {
215  $this->logger->info(sprintf(
216  "Trigger persisting certificate achievement for: usr_id: %s/obj_id: %s/type: %s/template_id: %s",
217  $userId,
218  $objectId,
219  $type,
220  $template->getId()
221  ));
222  $this->processEntry($type, $objectId, $userId, $template, $settings);
223  } else {
224  $this->logger->info(sprintf(
225  "Did not trigger certificate achievement for inactive template: usr_id: %s/obj_id: %s/type: %s/template_id: %s",
226  $userId,
227  $objectId,
228  $type,
229  $template->getId()
230  ));
231  }
232  } catch (ilException $exception) {
233  $this->logger->info(sprintf(
234  "Did not find an active certificate template for case: usr_id: %s/obj_id: %s/type: %s",
235  $userId,
236  $objectId,
237  $type
238  ));
239  }
240  } else {
241  $this->logger->info(sprintf(
242  "Object type is not of interest, skipping certificate evaluation for this object"
243  ));
244  }
245 
246  if ($type === 'crs') {
247  $this->logger->info(
248  'Skipping handling for course, because courses cannot be certificate trigger ' .
249  '(with globally disabled learning progress) for other certificate enabled objects'
250  );
251  return;
252  }
253 
254  $this->logger->info(
255  'Triggering certificate evaluation of possible depending course objects ...'
256  );
257 
258  foreach (\ilObject::_getAllReferences($objectId) as $refId) {
259  $templateRepository = new \ilCertificateTemplateRepository($this->db, $this->logger);
260  $progressEvaluation = new \ilCertificateCourseLearningProgressEvaluation($templateRepository);
261 
262  $templatesOfCompletedCourses = $progressEvaluation->evaluate($refId, $userId);
263  if (0 === count($templatesOfCompletedCourses)) {
264  $this->logger->info(sprintf(
265  "No dependent course certificate template configuration found for child object: usr_id: %s/obj_id: %s/ref_id: %s/type: %s",
266  $userId,
267  $objectId,
268  $refId,
269  $type
270  ));
271  continue;
272  }
273 
274  foreach ($templatesOfCompletedCourses as $courseTemplate) {
275  // We do not check if we support the type anymore, because the type 'crs' is always supported
276  try {
277  $courseObjectId = $courseTemplate->getObjId();
278 
279  if (true === $courseTemplate->isCurrentlyActive()) {
280  $type = $this->objectDataCache->lookupType($courseObjectId);
281 
282  $this->logger->info(sprintf(
283  "Trigger persisting certificate achievement for: usr_id: %s/obj_id: %s/type: %s/template_id: %s",
284  $userId,
285  $courseObjectId,
286  'crs',
287  $courseTemplate->getId()
288  ));
289  $this->processEntry($type, $courseObjectId, $userId, $courseTemplate, $settings);
290  } else {
291  $this->logger->info(sprintf(
292  "Did not trigger certificate achievement for inactive template: usr_id: %s/obj_id: %s/type: %s/template_id: %s",
293  $userId,
294  $objectId,
295  $type,
296  $courseTemplate->getId()
297  ));
298  }
299  } catch (ilException $exception) {
300  $this->logger->warning($exception->getMessage());
301  continue;
302  }
303  }
304  }
305 
306  $this->logger->info(
307  'Finished certificate evaluation'
308  );
309  }
310  }
const LP_STATUS_COMPLETED_NUM
$template
$type
static _getAllReferences($a_id)
get all reference ids of object
processEntry($type, $objectId, int $userId, ilCertificateTemplate $template, ilSetting $settings)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleNewMigratedUserCertificate()

ilCertificateAppEventListener::handleNewMigratedUserCertificate ( )
private
Exceptions

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

References $certificate, Sabre\Xml\$classMap, $template, $templateRepository, $type, $user, and ilObjectFactory\getInstanceByObjId().

Referenced by handle().

317  {
318  $this->logger->info('Try to create new certificates based on event');
319 
320  if (false === array_key_exists('obj_id', $this->parameters)) {
321  $this->logger->error('Object ID is not added to the event. Abort.');
322  return;
323  }
324 
325  if (false === array_key_exists('user_id', $this->parameters)) {
326  $this->logger->error('User ID is not added to the event. Abort.');
327  return;
328  }
329 
330  if (false === array_key_exists('background_image_path', $this->parameters)) {
331  $this->logger->error('Background Image Path is not added to the event. Abort.');
332  return;
333  }
334 
335  if (false === array_key_exists('acquired_timestamp', $this->parameters)) {
336  $this->logger->error('Acquired Timestamp is not added to the event. Abort.');
337  return;
338  }
339 
340  if (false === array_key_exists('ilias_version', $this->parameters)) {
341  $this->logger->error('ILIAS version is not added to the event. Abort.');
342  return;
343  }
344 
345  if (false === array_key_exists('certificate_content', $this->parameters)) {
346  $this->logger->error('Certificate content is not added to the event. Abort.');
347  return;
348  }
349 
350  $objId = $this->parameters['obj_id'] ?? 0;
351  $userId = $this->parameters['user_id'] ?? 0;
352  $backgroundImagePath = $this->parameters['background_image_path'] ?? '';
353  $acquiredTimestamp = $this->parameters['acquired_timestamp'] ?? '';
354  $iliasVersion = $this->parameters['ilias_version'] ?? '';
355  $certificateContent = $this->parameters['certificate_content'] ?? '';
356 
357  if ('' === $certificateContent) {
358  $this->logger->error('Certificate content is empty. Abort.');
359  return;
360  }
361 
362  if ('' === $acquiredTimestamp || $acquiredTimestamp <= 0) {
363  $this->logger->error('Acquired Timestamp is empty. Abort.');
364  return;
365  }
366 
367  $templateRepository = new \ilCertificateTemplateRepository($this->db, $this->logger);
368  $template = $templateRepository->fetchFirstCreatedTemplate($objId);
369 
370  try {
371  $certificate = $this->userCertificateRepository->fetchActiveCertificate($userId, $objId);
372  $this->logger->error(sprintf('There are already certificates generated for user_id "%s" and object_id "%s". Abort.', $userId, $objId));
373  return;
374  } catch (ilException $exception) {
375  $this->logger->info('No active user certificate found. Resume migration.');
376  }
377 
378  $type = $this->objectDataCache->lookupType($objId);
379 
381  if (!$classMap->typeExistsInMap($type)) {
382  $this->logger->error(sprintf('Migrations for type "%s" not supported. Abort.', $type));
383  return;
384  }
385 
387  if (!$user || !($user instanceof \ilObjUser)) {
388  throw new \ilException(sprintf('The given user ID("%s") is not a user', $userId));
389  }
390 
391  $userCertificate = new \ilUserCertificate(
392  $template->getId(),
393  $objId,
394  $type,
395  $userId,
396  $user->getFullname(),
397  $acquiredTimestamp,
398  $certificateContent,
399  '',
400  null,
401  1,
402  $iliasVersion,
403  true,
404  $backgroundImagePath,
405  ''
406  );
407 
408  $this->userCertificateRepository->save($userCertificate);
409  }
$template
$type
if(@file_exists(dirname(__FILE__).'/lang/eng.php')) $certificate
Definition: example_052.php:77
$user
Definition: migrateto20.php:57
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isLearningAchievementEvent()

ilCertificateAppEventListener::isLearningAchievementEvent ( )
protected
Returns
bool

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

Referenced by handle().

120  : bool
121  {
122  return (
123  'Services/Tracking' === $this->component &&
124  'updateStatus' === $this->event
125  );
126  }
+ Here is the caller graph for this function:

◆ isMigratingCertificateEvent()

ilCertificateAppEventListener::isMigratingCertificateEvent ( )
protected
Returns
bool

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

Referenced by handle().

131  : bool
132  {
133  return (
134  'Services/Certificate' === $this->component &&
135  'migrateUserCertificate' === $this->event
136  );
137  }
+ Here is the caller graph for this function:

◆ isUserDeletedEvent()

ilCertificateAppEventListener::isUserDeletedEvent ( )
protected
Returns
bool

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

Referenced by handle().

142  : bool
143  {
144  return (
145  'Services/User' === $this->component &&
146  'deleteUser' === $this->event
147  );
148  }
+ Here is the caller graph for this function:

◆ processEntry()

ilCertificateAppEventListener::processEntry (   $type,
  $objectId,
int  $userId,
ilCertificateTemplate  $template,
ilSetting  $settings 
)
private
Parameters
$type
$objectId
int$userId
ilCertificateTemplate$template
ilSetting$settings
Exceptions
ilDatabaseException
ilException
ilInvalidCertificateException

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

References $type, ilSetting\get(), ilCertificateTemplate\getId(), and ilCronConstants\IN_PROGRESS.

Referenced by handleLPUpdate().

449  {
450  $className = $this->certificateClassMap->getPlaceHolderClassNameByType($type);
451 
452  $entry = new \ilCertificateQueueEntry(
453  $objectId,
454  $userId,
455  $className,
457  $template->getId(),
458  time()
459  );
460 
461  $mode = $settings->get('persistent_certificate_mode', 'persistent_certificate_mode_cron');
462  if ($mode === 'persistent_certificate_mode_instant') {
463  $cronjob = new ilCertificateCron();
464  $cronjob->init();
465  $cronjob->processEntry(0, $entry, array());
466  return;
467  }
468 
469  $this->certificateQueueRepository->addToQueue($entry);
470  }
$type
get($a_keyword, $a_default_value=false)
get setting
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ withComponent()

ilCertificateAppEventListener::withComponent ( string  $component)
Parameters
string$component
Returns

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

References $component.

82  : self
83  {
84  $clone = clone $this;
85 
86  $clone->component = $component;
87 
88  return $clone;
89  }

◆ withEvent()

ilCertificateAppEventListener::withEvent ( string  $event)
Parameters
string$event
Returns

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

References $event.

95  : self
96  {
97  $clone = clone $this;
98 
99  $clone->event = $event;
100 
101  return $clone;
102  }

◆ withParameters()

ilCertificateAppEventListener::withParameters ( array  $parameters)
Parameters
array$parameters
Returns

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

References $parameters.

108  : self
109  {
110  $clone = clone $this;
111 
112  $clone->parameters = $parameters;
113 
114  return $clone;
115  }

Field Documentation

◆ $certificateClassMap

ilCertificateAppEventListener::$certificateClassMap
private

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

◆ $certificateQueueRepository

ilCertificateAppEventListener::$certificateQueueRepository
private

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

◆ $component

ilCertificateAppEventListener::$component = ''
protected

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

Referenced by withComponent().

◆ $db

ilCertificateAppEventListener::$db
protected

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

Referenced by __construct().

◆ $event

ilCertificateAppEventListener::$event = ''
protected

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

Referenced by withEvent().

◆ $logger

ilCertificateAppEventListener::$logger
private

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

Referenced by __construct().

◆ $migrationRepository

ilCertificateAppEventListener::$migrationRepository
private

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

◆ $objectDataCache

ilCertificateAppEventListener::$objectDataCache
private

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

Referenced by __construct().

◆ $parameters

ilCertificateAppEventListener::$parameters = []
protected

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

Referenced by withParameters().

◆ $templateRepository

ilCertificateAppEventListener::$templateRepository
private

◆ $userCertificateRepository

ilCertificateAppEventListener::$userCertificateRepository
private

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


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