ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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...
 
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 25 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 36 of file class.ilCertificateAppEventListener.php.

References ILIAS\Repository\logger().

+ Here is the call graph for this function:

Member Function Documentation

◆ handle()

ilCertificateAppEventListener::handle ( )
Exceptions
IOException

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

96 : void
97 {
98 try {
99 if ($this->isLearningAchievementEvent()) {
100 $this->handleLPUpdate();
101 } elseif ($this->isUserDeletedEvent()) {
102 $this->handleDeletedUser();
103 }
104 } catch (ilException $e) {
105 $this->logger->error($e->getMessage());
106 }
107 }
Base class for ILIAS Exception handling.

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

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

References ILIAS\Repository\int(), ILIAS\Repository\logger(), and ILIAS\UI\examples\Prompt\Standard\parameters().

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

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

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

References $DIC.

◆ handleLPUpdate()

ilCertificateAppEventListener::handleLPUpdate ( )
private

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

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

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

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

77 : bool
78 {
79 return (
80 $this->component === 'components/ILIAS/Tracking' &&
81 $this->event === 'updateStatus'
82 );
83 }

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

85 : bool
86 {
87 return (
88 $this->component === 'components/ILIAS/User' &&
89 $this->event === 'deleteUser'
90 );
91 }

References ILIAS\Repository\event().

Referenced by handle().

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

◆ withComponent()

ilCertificateAppEventListener::withComponent ( string  $component)

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

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

References $component.

◆ withEvent()

ilCertificateAppEventListener::withEvent ( string  $event)

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

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

References $event.

◆ withParameters()

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

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

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

References $parameters.

Field Documentation

◆ $certificateQueueRepository

readonly ilCertificateQueueRepository ilCertificateAppEventListener::$certificateQueueRepository
private

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

◆ $component

string ilCertificateAppEventListener::$component = ''
private

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

Referenced by withComponent().

◆ $event

string ilCertificateAppEventListener::$event = ''
private

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

Referenced by withEvent().

◆ $parameters

array ilCertificateAppEventListener::$parameters = []
private

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

Referenced by withParameters().

◆ $templateRepository

readonly ilCertificateTemplateRepository ilCertificateAppEventListener::$templateRepository
private

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

◆ $userCertificateRepository

readonly ilUserCertificateRepository ilCertificateAppEventListener::$userCertificateRepository
private

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


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