ILIAS  release_7 Revision v7.30-3-g800a261c036
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 ()
 
 isUserDeletedEvent ()
 
 isCompletedStudyProgramme ()
 

Protected Attributes

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

Private Member Functions

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

Private Attributes

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

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 58 of file class.ilCertificateAppEventListener.php.

References $db, $logger, and $objectDataCache.

62  {
63  $this->db = $db;
64  $this->objectDataCache = $objectDataCache;
65  $this->logger = $logger;
66  $this->certificateQueueRepository = new \ilCertificateQueueRepository($this->db, $this->logger);
67  $this->certificateClassMap = new \ilCertificateTypeClassMap();
68  $this->templateRepository = new \ilCertificateTemplateRepository($this->db, $this->logger);
69  $this->userCertificateRepository = new \ilUserCertificateRepository($this->db, $this->logger);
70  }

Member Function Documentation

◆ handle()

ilCertificateAppEventListener::handle ( )

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

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

+ Here is the call graph for this function:

◆ handleCompletedStudyProgramme()

ilCertificateAppEventListener::handleCompletedStudyProgramme ( )
private

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

References ilCronConstants\IN_PROGRESS.

Referenced by handle().

366  {
367  $settings = new ilSetting('certificate');
368  $objectId = $this->parameters['prg_id'] ?? 0;
369  $userId = $this->parameters['usr_id'] ?? 0;
370  try {
371  $template = $this->templateRepository->fetchCurrentlyActiveCertificate($objectId);
372  if (true === $template->isCurrentlyActive()) {
373  $entry = new \ilCertificateQueueEntry(
374  $objectId,
375  $userId,
376  ilStudyProgrammePlaceholderValues::class,
378  $template->getId(),
379  time()
380  );
381  $mode = $settings->get('persistent_certificate_mode', '');
382  if ($mode === 'persistent_certificate_mode_instant') {
383  $cronjob = new ilCertificateCron();
384  $cronjob->init();
385  return $cronjob->processEntry(0, $entry, array());
386  }
387  $this->certificateQueueRepository->addToQueue($entry);
388  }
389  } catch (ilException $exception) {
390  $this->logger->warning($exception->getMessage());
391  }
392  }
+ Here is the caller graph for this function:

◆ handleDeletedUser()

ilCertificateAppEventListener::handleDeletedUser ( )
private
Exceptions

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

Referenced by handle().

307  {
308  $portfolioFileService = new ilPortfolioCertificateFileService();
309 
310  if (false === array_key_exists('usr_id', $this->parameters)) {
311  $this->logger->error('User ID is not added to the event. Abort.');
312  return;
313  }
314 
315  $this->logger->info('User has been deleted. Try to delete user certificates');
316 
317  $userId = $this->parameters['usr_id'];
318 
319  $this->userCertificateRepository->deleteUserCertificates((int) $userId);
320 
321  $this->certificateQueueRepository->removeFromQueueByUserId((int) $userId);
322 
323  $portfolioFileService->deleteUserDirectory($userId);
324 
325  $this->logger->info(sprintf(
326  'All relevant data sources for the user certificates for user(user_id: "%s" deleted)',
327  $userId
328  ));
329  }
+ 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 162 of file class.ilCertificateAppEventListener.php.

References $DIC.

163  {
164  global $DIC;
165 
166  $listener = new static(
167  $DIC->database(),
168  $DIC['ilObjDataCache'],
169  $DIC->logger()->cert()
170  );
171 
172  $listener
173  ->withComponent($a_component)
174  ->withEvent($a_event)
175  ->withParameters($a_parameter)
176  ->handle();
177  }
global $DIC
Definition: goto.php:24

◆ handleLPUpdate()

ilCertificateAppEventListener::handleLPUpdate ( )
private
Exceptions

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

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

Referenced by handle().

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

◆ isCompletedStudyProgramme()

ilCertificateAppEventListener::isCompletedStudyProgramme ( )
protected

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

Referenced by handle().

133  : bool
134  {
135  return (
136  'Modules/StudyProgramme' === $this->component &&
137  'userSuccessful' === $this->event
138  );
139  }
+ Here is the caller graph for this function:

◆ isLearningAchievementEvent()

ilCertificateAppEventListener::isLearningAchievementEvent ( )
protected
Returns
bool

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

Referenced by handle().

114  : bool
115  {
116  return (
117  'Services/Tracking' === $this->component &&
118  'updateStatus' === $this->event
119  );
120  }
+ Here is the caller graph for this function:

◆ isUserDeletedEvent()

ilCertificateAppEventListener::isUserDeletedEvent ( )
protected
Returns
bool

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

Referenced by handle().

125  : bool
126  {
127  return (
128  'Services/User' === $this->component &&
129  'deleteUser' === $this->event
130  );
131  }
+ 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 341 of file class.ilCertificateAppEventListener.php.

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

Referenced by handleLPUpdate().

342  {
343  $className = $this->certificateClassMap->getPlaceHolderClassNameByType($type);
344 
345  $entry = new \ilCertificateQueueEntry(
346  $objectId,
347  $userId,
348  $className,
350  $template->getId(),
351  time()
352  );
353 
354  $mode = $settings->get('persistent_certificate_mode', 'persistent_certificate_mode_cron');
355  if ($mode === 'persistent_certificate_mode_instant') {
356  $cronjob = new ilCertificateCron();
357  $cronjob->init();
358  $cronjob->processEntry(0, $entry, array());
359  return;
360  }
361 
362  $this->certificateQueueRepository->addToQueue($entry);
363  }
$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 76 of file class.ilCertificateAppEventListener.php.

References $component.

76  : self
77  {
78  $clone = clone $this;
79 
80  $clone->component = $component;
81 
82  return $clone;
83  }

◆ withEvent()

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

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

References $event.

89  : self
90  {
91  $clone = clone $this;
92 
93  $clone->event = $event;
94 
95  return $clone;
96  }

◆ withParameters()

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

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

References $parameters.

102  : self
103  {
104  $clone = clone $this;
105 
106  $clone->parameters = $parameters;
107 
108  return $clone;
109  }

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

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

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

Referenced by handleLPUpdate().

◆ $userCertificateRepository

ilCertificateAppEventListener::$userCertificateRepository
private

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


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