ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilCertificateAppEventListener Class Reference
+ Inheritance diagram for ilCertificateAppEventListener:
+ Collaboration diagram for ilCertificateAppEventListener:

Public Member Functions

 __construct (private readonly UserCertificateApiInterface $user_certificate_api, private readonly ilDBInterface $db, private readonly ilObjectDataCache $objectDataCache, private readonly 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)
 Handle an event in a listener. More...
 

Protected Member Functions

 isLearningAchievementEvent ()
 
 isUserDeletedEvent ()
 

Private Member Functions

 handleLPUpdate ()
 
 handleDeletedUser ()
 

Private Attributes

string $component = ''
 
string $event = ''
 
array $parameters = []
 
readonly ilCertificateQueueRepository $certificateQueueRepository
 
readonly ilCertificateTemplateRepository $templateRepository
 
readonly ilUserCertificateRepository $userCertificateRepository
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilCertificateAppEventListener::__construct ( private readonly UserCertificateApiInterface  $user_certificate_api,
private readonly ilDBInterface  $db,
private readonly ilObjectDataCache  $objectDataCache,
private readonly ilLogger  $logger 
)

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

References ILIAS\Repository\logger().

40  {
41  $this->certificateQueueRepository = new ilCertificateQueueRepository($this->db, $this->logger);
42  $this->templateRepository = new ilCertificateTemplateDatabaseRepository($this->db, $this->logger);
43  $this->userCertificateRepository = new ilUserCertificateRepository($this->db, $this->logger);
44  }
+ Here is the call graph for this function:

Member Function Documentation

◆ handle()

ilCertificateAppEventListener::handle ( )
Exceptions
IOException

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

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

+ Here is the call graph for this function:

◆ handleDeletedUser()

ilCertificateAppEventListener::handleDeletedUser ( )
private

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

References ILIAS\Repository\int(), and ILIAS\Repository\logger().

Referenced by handle().

209  : void
210  {
211  if (!array_key_exists('usr_id', $this->parameters)) {
212  $this->logger->error('User ID is not added to the event. Abort.');
213  return;
214  }
215 
216  $this->logger->debug('User has been deleted. Try to delete user certificates');
217 
218  $userId = (int) $this->parameters['usr_id'];
219 
220  $this->userCertificateRepository->deleteUserCertificates($userId);
221  $this->certificateQueueRepository->removeFromQueueByUserId($userId);
222 
223  $portfolioFileService = new ilPortfolioCertificateFileService();
224  $portfolioFileService->deleteUserDirectory($userId);
225 
226  $this->logger->debug(sprintf(
227  'All relevant data sources for the user certificates for user (usr_id: "%s" deleted)',
228  $userId
229  ));
230  }
+ 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

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<string,mixed>$a_parameter parameter array (assoc), array("name" => ..., "phone_office" => ...)

Implements ilAppEventListener.

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

References $DIC.

108  : void
109  {
110  global $DIC;
111 
112  $listener = new self(
113  $DIC->certificate()->userCertificates(),
114  $DIC->database(),
115  $DIC['ilObjDataCache'],
116  $DIC->logger()->cert()
117  );
118 
119  $listener
120  ->withComponent($a_component)
121  ->withEvent($a_event)
122  ->withParameters($a_parameter)
123  ->handle();
124  }
global $DIC
Definition: feed.php:28

◆ handleLPUpdate()

ilCertificateAppEventListener::handleLPUpdate ( )
private

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

References Vendor\Package\$e, $refId, ilObject\_getAllReferences(), ILIAS\Repository\int(), ILIAS\Repository\logger(), ilLPStatus\LP_STATUS_COMPLETED_NUM, ilLPStatus\LP_STATUS_NOT_ATTEMPTED_NUM, and ILIAS\Repository\objectDataCache().

Referenced by handle().

126  : void
127  {
128  $status = (int) ($this->parameters['status'] ?? ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM);
129  if ($status !== ilLPStatus::LP_STATUS_COMPLETED_NUM) {
130  return;
131  }
132 
133  $object_id = (int) ($this->parameters['obj_id'] ?? 0);
134  $usr_id = (int) ($this->parameters['usr_id'] ?? 0);
135  $type = $this->objectDataCache->lookupType($object_id);
136 
137  $this->logger->debug(sprintf(
138  "Certificate evaluation triggered, received 'completed' learning progress for: usr_id: %s/obj_id: %s/type: %s",
139  $usr_id,
140  $object_id,
141  $type
142  ));
143 
144  try {
145  $this->user_certificate_api->certificateCriteriaMet(
146  $usr_id,
147  $object_id
148  );
150  $this->logger->debug(sprintf(
151  'Consumer not supported, or did not find an active certificate template for case: usr_id: %s/obj_id: %s/type: %s',
152  $usr_id,
153  $object_id,
154  $type
155  ));
156  } catch (ilException $e) {
157  $this->logger->warning($e->getMessage());
158  }
159 
160  if ($type === 'crs') {
161  $this->logger->debug(
162  'Skipping handling for course, because courses cannot be certificate trigger ' .
163  '(with globally disabled learning progress) for other certificate enabled objects'
164  );
165  return;
166  }
167 
168  $this->logger->debug(
169  'Triggering certificate evaluation of possible depending course objects ...'
170  );
171 
172  $progressEvaluation = new ilCertificateCourseLearningProgressEvaluation(
174  $this->templateRepository
175  )
176  );
177  foreach (ilObject::_getAllReferences($object_id) as $refId) {
178  $templatesOfCompletedCourses = $progressEvaluation->evaluate($refId, $usr_id);
179  if ([] === $templatesOfCompletedCourses) {
180  $this->logger->debug(sprintf(
181  'No dependent course certificate template configuration found for child object: usr_id: %s/obj_id: %s/ref_id: %s/type: %s',
182  $usr_id,
183  $object_id,
184  $refId,
185  $type
186  ));
187  continue;
188  }
189 
190  foreach ($templatesOfCompletedCourses as $courseTemplate) {
191  // We do not check if we support the type anymore, because the type 'crs' is always supported
192  try {
193  $this->user_certificate_api->certificateCriteriaMetForGivenTemplate(
194  $usr_id,
195  $courseTemplate
196  );
197  } catch (ilException $e) {
198  $this->logger->warning($e->getMessage());
199  continue;
200  }
201  }
202  }
203 
204  $this->logger->debug(
205  'Finished certificate evaluation'
206  );
207  }
const LP_STATUS_COMPLETED_NUM
static _getAllReferences(int $id)
get all reference ids for object ID
A certicate template repository which caches results of query commands List of cached results (other ...
$refId
Definition: xapitoken.php:58
const LP_STATUS_NOT_ATTEMPTED_NUM
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isLearningAchievementEvent()

ilCertificateAppEventListener::isLearningAchievementEvent ( )
protected

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

References ILIAS\Repository\event().

Referenced by handle().

76  : bool
77  {
78  return (
79  $this->component === 'Services/Tracking' &&
80  $this->event === 'updateStatus'
81  );
82  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isUserDeletedEvent()

ilCertificateAppEventListener::isUserDeletedEvent ( )
protected

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

References ILIAS\Repository\event().

Referenced by handle().

84  : bool
85  {
86  return (
87  $this->component === 'Services/User' &&
88  $this->event === 'deleteUser'
89  );
90  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ withComponent()

ilCertificateAppEventListener::withComponent ( string  $component)

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

References $component.

46  : self
47  {
48  $clone = clone $this;
49 
50  $clone->component = $component;
51 
52  return $clone;
53  }

◆ withEvent()

ilCertificateAppEventListener::withEvent ( string  $event)

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

References $event.

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

◆ withParameters()

ilCertificateAppEventListener::withParameters ( array  $parameters)
Parameters
array<string,mixed>$parameters

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

References $parameters.

67  : self
68  {
69  $clone = clone $this;
70 
71  $clone->parameters = $parameters;
72 
73  return $clone;
74  }

Field Documentation

◆ $certificateQueueRepository

readonly ilCertificateQueueRepository ilCertificateAppEventListener::$certificateQueueRepository
private

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

◆ $component

string ilCertificateAppEventListener::$component = ''
private

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

Referenced by withComponent().

◆ $event

string ilCertificateAppEventListener::$event = ''
private

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

Referenced by withEvent().

◆ $parameters

array ilCertificateAppEventListener::$parameters = []
private

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

Referenced by withParameters().

◆ $templateRepository

readonly ilCertificateTemplateRepository ilCertificateAppEventListener::$templateRepository
private

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

◆ $userCertificateRepository

readonly ilUserCertificateRepository ilCertificateAppEventListener::$userCertificateRepository
private

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


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