ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
ilCertificateTemplateDatabaseRepository Class Reference
+ Inheritance diagram for ilCertificateTemplateDatabaseRepository:
+ Collaboration diagram for ilCertificateTemplateDatabaseRepository:

Public Member Functions

 __construct (private readonly ilDBInterface $database, ?ilLogger $logger=null, ?ilObjectDataCache $objectDataCache=null)
 
 save (ilCertificateTemplate $certificateTemplate)
 
 updateActivity (ilCertificateTemplate $certificateTemplate, bool $currentlyActive)
 
 fetchTemplate (int $templateId)
 
 fetchCertificateTemplatesByObjId (int $objId)
 
 fetchCurrentlyUsedCertificate (int $objId)
 
 fetchCurrentlyActiveCertificate (int $objId)
 
 fetchPreviousCertificate (int $objId)
 
 deleteTemplate (int $templateId, int $objectId)
 
 fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress (bool $isGlobalLpEnabled, ?int $forRefId=null)
 
 fetchFirstCreatedTemplate (int $objId)
 
 updateDefaultBackgroundImagePaths (ResourceIdentification|string $new_rid, ResourceIdentification|string $old_rid)
 
 isResourceUsed (string $relative_image_identification)
 
- Public Member Functions inherited from ilCertificateTemplateRepository
 save (ilCertificateTemplate $certificateTemplate)
 
 updateActivity (ilCertificateTemplate $certificateTemplate, bool $currentlyActive)
 
 fetchTemplate (int $templateId)
 
 fetchCertificateTemplatesByObjId (int $objId)
 
 fetchCurrentlyUsedCertificate (int $objId)
 
 fetchCurrentlyActiveCertificate (int $objId)
 
 fetchPreviousCertificate (int $objId)
 
 deleteTemplate (int $templateId, int $objectId)
 
 activatePreviousCertificate (int $objId)
 
 fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress (bool $isGlobalLpEnabled, ?int $forRefId=null)
 
 fetchFirstCreatedTemplate (int $objId)
 

Data Fields

const TABLE_NAME = 'il_cert_template'
 

Private Member Functions

 deactivatePreviousTemplates (int $objId)
 
 createCertificateTemplate (array $row)
 

Private Attributes

readonly ilLogger $logger
 
readonly ilObjectDataCache $objectDataCache
 

Detailed Description

Author
Niels Theen nthee.nosp@m.n@da.nosp@m.tabay.nosp@m..de Repository that allows interaction with the database in the context of certificate templates.

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

Constructor & Destructor Documentation

◆ __construct()

ilCertificateTemplateDatabaseRepository::__construct ( private readonly ilDBInterface  $database,
?ilLogger  $logger = null,
?ilObjectDataCache  $objectDataCache = null 
)

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

38 {
39 if (null === $logger) {
40 global $DIC;
41 $logger = $DIC->logger()->cert();
42 }
43 $this->logger = $logger;
44
45 if (null === $objectDataCache) {
46 global $DIC;
47 $objectDataCache = $DIC['ilObjDataCache'];
48 }
50 }
global $DIC
Definition: shib_login.php:26

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

+ Here is the call graph for this function:

Member Function Documentation

◆ createCertificateTemplate()

ilCertificateTemplateDatabaseRepository::createCertificateTemplate ( array  $row)
private
Parameters
array<string,mixed>$row

Definition at line 462 of file class.ilCertificateTemplateDatabaseRepository.php.

463 {
464 return new ilCertificateTemplate(
465 (int) $row['obj_id'],
466 $row['obj_type'],
467 $row['certificate_content'],
468 $row['certificate_hash'],
469 $row['template_values'],
470 (int) $row['version'],
471 $row['ilias_version'],
472 (int) $row['created_timestamp'],
473 (bool) $row['currently_active'],
474 (string) ($row['background_image_ident'] ?? ''),
475 (string) ($row['tile_image_ident'] ?? ''),
476 isset($row['id']) ? (int) $row['id'] : null
477 );
478 }

Referenced by fetchCertificateTemplatesByObjId(), fetchCurrentlyActiveCertificate(), fetchCurrentlyUsedCertificate(), and fetchTemplate().

+ Here is the caller graph for this function:

◆ deactivatePreviousTemplates()

ilCertificateTemplateDatabaseRepository::deactivatePreviousTemplates ( int  $objId)
private

Definition at line 388 of file class.ilCertificateTemplateDatabaseRepository.php.

388 : void
389 {
390 $this->logger->debug(sprintf('START - Deactivate previous certificate template for object: "%s"', $objId));
391
392 $sql = '
393 UPDATE ' . self::TABLE_NAME . '
394 SET currently_active = 0
395 WHERE obj_id = ' . $this->database->quote($objId, ilDBConstants::T_INTEGER);
396
397 $this->database->manipulate($sql);
398
399 $this->logger->debug(sprintf('END - Certificate template deactivated for object: "%s"', $objId));
400 }
$objId
Definition: xapitoken.php:55

References $objId, ILIAS\Repository\database(), ILIAS\Repository\logger(), and ilDBConstants\T_INTEGER.

Referenced by save().

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

◆ deleteTemplate()

ilCertificateTemplateDatabaseRepository::deleteTemplate ( int  $templateId,
int  $objectId 
)

Implements ilCertificateTemplateRepository.

Definition at line 249 of file class.ilCertificateTemplateDatabaseRepository.php.

249 : void
250 {
251 $this->logger->debug(
252 sprintf(
253 'START - Set deleted flag for certificate template("%s") for object: "%s"',
254 $templateId,
255 $objectId
256 )
257 );
258
259 $sql = '
260 UPDATE ' . self::TABLE_NAME . '
261 SET deleted = 1, currently_active = 0
262 WHERE id = ' . $this->database->quote($templateId, ilDBConstants::T_INTEGER) . '
263 AND obj_id = ' . $this->database->quote($objectId, ilDBConstants::T_INTEGER);
264
265 $this->database->manipulate($sql);
266
267 $this->logger->debug(
268 sprintf(
269 'END - Deleted flag set fo certificate template("%s") for object: "%s"',
270 $templateId,
271 $objectId
272 )
273 );
274 }

References ILIAS\Repository\database(), ILIAS\Repository\logger(), and ilDBConstants\T_INTEGER.

+ Here is the call graph for this function:

◆ fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress()

ilCertificateTemplateDatabaseRepository::fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress ( bool  $isGlobalLpEnabled,
?int  $forRefId = null 
)
Returns
ilCertificateTemplate[]

Implements ilCertificateTemplateRepository.

Definition at line 303 of file class.ilCertificateTemplateDatabaseRepository.php.

306 : array {
307 $this->logger->debug(
308 'START - Fetch all active course certificate templates with disabled learning progress: "%s"'
309 );
310
311 $joinLpSettings = '';
312 $whereLpSettings = '';
313 $onSettingsForRefId = '';
314
315 if ($isGlobalLpEnabled) {
316 $joinLpSettings = 'LEFT JOIN ut_lp_settings uls ON uls.obj_id = od.obj_id';
317 $whereLpSettings = sprintf(
318 'AND (uls.u_mode IS NULL OR uls.u_mode = %s)',
319 $this->database->quote(ilLPObjSettings::LP_MODE_DEACTIVATED, 'integer')
320 );
321 }
322
323 if (is_int($forRefId)) {
324 $onSettingsForRefId = " AND settings.value IS NOT NULL AND (JSON_CONTAINS(settings.value, '\"{$forRefId}\"', '$') = 1 OR JSON_CONTAINS(settings.value, '{$forRefId}', '$')) ";
325 }
326
327 $sql = '
328 SELECT ' . self::TABLE_NAME . '.*
329 FROM ' . self::TABLE_NAME . '
330 INNER JOIN object_data od ON od.obj_id = ' . self::TABLE_NAME . ".obj_id
331 INNER JOIN settings ON settings.module = %s AND settings.keyword = {$this->database->concat(
332 [
333 [$this->database->quote('cert_subitems_', 'text'), 'text'],
334 ['od.obj_id', 'text']
335 ],
336 false
337 )} $onSettingsForRefId $joinLpSettings
338 WHERE " . self::TABLE_NAME . '.obj_type = %s
339 AND ' . self::TABLE_NAME . '.currently_active = %s
340 ' . $whereLpSettings;
341 $query = $this->database->queryF(
342 $sql,
343 ['text', 'text', 'integer'],
344 ['crs', 'crs', 1]
345 );
346
347 $result = [];
348 while ($row = $this->database->fetchAssoc($query)) {
349 $result[] = $this->createCertificateTemplate($row);
350 }
351
352 $this->logger->debug(
353 sprintf(
354 'END - All active course certificate templates with disabled learning progress: "%s"',
355 json_encode($result, JSON_THROW_ON_ERROR)
356 )
357 );
358
359 return $result;
360 }

References ILIAS\Repository\database(), and ilLPObjSettings\LP_MODE_DEACTIVATED.

+ Here is the call graph for this function:

◆ fetchCertificateTemplatesByObjId()

ilCertificateTemplateDatabaseRepository::fetchCertificateTemplatesByObjId ( int  $objId)
Returns
ilCertificateTemplate[]

Implements ilCertificateTemplateRepository.

Definition at line 122 of file class.ilCertificateTemplateDatabaseRepository.php.

122 : array
123 {
124 $this->logger->debug(sprintf('START - Fetch multiple certificate templates for object: "%s"', $objId));
125
126 $result = [];
127
128 $sql = '
129 SELECT * FROM ' .
130 self::TABLE_NAME . ' ' .
131 'WHERE obj_id = ' . $this->database->quote($objId, ilDBConstants::T_INTEGER) . ' ' .
132 'AND deleted = 0 ' .
133 'ORDER BY version ASC'
134 ;
135
136 $query = $this->database->query($sql);
137
138 while ($row = $this->database->fetchAssoc($query)) {
139 $result[] = $this->createCertificateTemplate($row);
140 }
141
142 $this->logger->debug(
143 sprintf(
144 'END - Fetching of certificate templates for object: "%s" with "%s" results',
145 $objId,
146 count($result)
147 )
148 );
149
150 return $result;
151 }

References $objId, createCertificateTemplate(), ILIAS\Repository\database(), ILIAS\Repository\logger(), and ilDBConstants\T_INTEGER.

Referenced by fetchPreviousCertificate().

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

◆ fetchCurrentlyActiveCertificate()

ilCertificateTemplateDatabaseRepository::fetchCurrentlyActiveCertificate ( int  $objId)
Exceptions
ilCouldNotFindCertificateTemplate

Implements ilCertificateTemplateRepository.

Definition at line 194 of file class.ilCertificateTemplateDatabaseRepository.php.

195 {
196 $this->logger->debug(sprintf('START - Fetch currently active certificate template for object: "%s"', $objId));
197
198 $sql = '
199 SELECT * FROM ' . self::TABLE_NAME . '
200 WHERE obj_id = ' . $this->database->quote($objId, ilDBConstants::T_INTEGER) . '
201 AND deleted = 0
202 AND currently_active = 1
203 ';
204
205 $query = $this->database->query($sql);
206
207 while ($row = $this->database->fetchAssoc($query)) {
208 $this->logger->debug(sprintf('END - Found active certificate for: "%s"', $objId));
209
210 return $this->createCertificateTemplate($row);
211 }
212
213 throw new ilCouldNotFindCertificateTemplate(sprintf('NO active certificate template found for: "%s"', $objId));
214 }

References $objId, createCertificateTemplate(), ILIAS\Repository\database(), ILIAS\Repository\logger(), and ilDBConstants\T_INTEGER.

+ Here is the call graph for this function:

◆ fetchCurrentlyUsedCertificate()

ilCertificateTemplateDatabaseRepository::fetchCurrentlyUsedCertificate ( int  $objId)

Implements ilCertificateTemplateRepository.

Definition at line 153 of file class.ilCertificateTemplateDatabaseRepository.php.

154 {
155 $this->logger->debug(sprintf('START - Fetch currently active certificate template for object: "%s"', $objId));
156
157 $this->database->setLimit(1);
158
159 $sql = '
160 SELECT * FROM ' . self::TABLE_NAME . '
161 WHERE obj_id = ' . $this->database->quote($objId, ilDBConstants::T_INTEGER) . '
162 AND deleted = 0
163 ORDER BY id DESC
164 ';
165
166 $query = $this->database->query($sql);
167
168 while ($row = $this->database->fetchAssoc($query)) {
169 $this->logger->debug(sprintf('END - Found active certificate for: "%s"', $objId));
170
171 return $this->createCertificateTemplate($row);
172 }
173
174 $this->logger->debug(sprintf('END - Found NO active certificate for: "%s"', $objId));
175
176 return new ilCertificateTemplate(
177 $objId,
178 $this->objectDataCache->lookupType($objId),
179 '',
180 '',
181 '',
182 0,
183 '0',
184 0,
185 false,
186 '',
187 ''
188 );
189 }

References $objId, createCertificateTemplate(), ILIAS\Repository\database(), ILIAS\Repository\logger(), ILIAS\Repository\objectDataCache(), and ilDBConstants\T_INTEGER.

+ Here is the call graph for this function:

◆ fetchFirstCreatedTemplate()

ilCertificateTemplateDatabaseRepository::fetchFirstCreatedTemplate ( int  $objId)
Exceptions
ilCouldNotFindCertificateTemplate

Implements ilCertificateTemplateRepository.

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

366 {
367 $this->logger->debug(sprintf('START - Fetch first create certificate template for object: "%s"', $objId));
368
369 $this->database->setLimit(1, 0);
370
371 $sql = '
372 SELECT * FROM ' . self::TABLE_NAME . '
373 WHERE obj_id = ' . $this->database->quote($objId, ilDBConstants::T_INTEGER) . '
374 ORDER BY id ASC
375 ';
376
377 $query = $this->database->query($sql);
378
379 while ($row = $this->database->fetchAssoc($query)) {
380 $this->logger->debug(sprintf('END - Found first create certificate template for object: "%s"', $objId));
381
382 return $this->createCertificateTemplate($row);
383 }
384
385 throw new ilCouldNotFindCertificateTemplate('No matching template found. MAY missing DBUpdate. Please check if the correct version is installed.');
386 }

References $objId, ILIAS\Repository\database(), ILIAS\Repository\logger(), and ilDBConstants\T_INTEGER.

+ Here is the call graph for this function:

◆ fetchPreviousCertificate()

ilCertificateTemplateDatabaseRepository::fetchPreviousCertificate ( int  $objId)

Implements ilCertificateTemplateRepository.

Definition at line 216 of file class.ilCertificateTemplateDatabaseRepository.php.

217 {
218 $this->logger->debug(sprintf('START - Fetch previous active certificate template for object: "%s"', $objId));
219
220 $templates = $this->fetchCertificateTemplatesByObjId($objId);
221
222 $resultTemplate = new ilCertificateTemplate(
223 $objId,
224 $this->objectDataCache->lookupType($objId),
225 '',
226 '',
227 '',
228 0,
229 '0',
230 0,
231 true,
232 '',
233 ''
234 );
235
236 $version = 0;
237 foreach ($templates as $template) {
238 if ($template->getVersion() > $version) {
239 $version = $template->getVersion();
240 $resultTemplate = $template;
241 }
242 }
243
244 $this->logger->debug(sprintf('Latest version active certificate template for object: "%s"', $objId));
245
246 return $resultTemplate;
247 }
$version
Definition: plugin.php:24

References $objId, $version, fetchCertificateTemplatesByObjId(), ILIAS\Repository\logger(), and ILIAS\Repository\objectDataCache().

+ Here is the call graph for this function:

◆ fetchTemplate()

ilCertificateTemplateDatabaseRepository::fetchTemplate ( int  $templateId)
Exceptions
ilCouldNotFindCertificateTemplate

Implements ilCertificateTemplateRepository.

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

100 {
101 $this->logger->debug(sprintf('START - Fetch certificate template with id: "%s"', $templateId));
102
103 $sql = '
104 SELECT * FROM
105 ' . self::TABLE_NAME . '
106 WHERE id = ' . $this->database->quote($templateId, ilDBConstants::T_INTEGER) . '
107 ORDER BY version ASC
108 ';
109
110 $query = $this->database->query($sql);
111
112 while ($row = $this->database->fetchAssoc($query)) {
113 return $this->createCertificateTemplate($row);
114 }
115
116 throw new ilCouldNotFindCertificateTemplate(sprintf('No template with id "%s" found', $templateId));
117 }

References createCertificateTemplate(), ILIAS\Repository\database(), ILIAS\Repository\logger(), and ilDBConstants\T_INTEGER.

+ Here is the call graph for this function:

◆ isResourceUsed()

ilCertificateTemplateDatabaseRepository::isResourceUsed ( string  $relative_image_identification)

Definition at line 430 of file class.ilCertificateTemplateDatabaseRepository.php.

430 : bool
431 {
432 $this->logger->debug(
433 sprintf(
434 'START - Checking if any certificate template uses resource id "%s"',
435 $relative_image_identification
436 )
437 );
438
439 $result = $this->database->queryF(
440 'SELECT EXISTS(SELECT 1 FROM ' . self::TABLE_NAME . ' WHERE
441 (background_image_ident = %s OR tile_image_ident = %s)
442 AND currently_active = 1) AS does_exist',
444 [$relative_image_identification, $relative_image_identification]
445 );
446
447 $exists = (bool) ($this->database->fetchAssoc($result)['does_exist'] ?? false);
448
449 $this->logger->debug(
450 sprintf(
451 'END - Image identification "%s" is ' . $exists ? 'in use' : 'unused',
452 $relative_image_identification
453 )
454 );
455
456 return $exists;
457 }

References ILIAS\Repository\database(), ILIAS\Repository\logger(), and ilDBConstants\T_TEXT.

+ Here is the call graph for this function:

◆ save()

ilCertificateTemplateDatabaseRepository::save ( ilCertificateTemplate  $certificateTemplate)

Implements ilCertificateTemplateRepository.

Definition at line 52 of file class.ilCertificateTemplateDatabaseRepository.php.

52 : void
53 {
54 $this->logger->debug('START - Save new certificate template');
55
56 $objId = $certificateTemplate->getObjId();
57
58 $id = $this->database->nextId(self::TABLE_NAME);
59
61
62 $columns = [
63 'id' => ['integer', $id],
64 'obj_id' => ['integer', $objId],
65 'obj_type' => ['text', $certificateTemplate->getObjType()],
66 'certificate_content' => ['clob', $certificateTemplate->getCertificateContent()],
67 'certificate_hash' => ['text', $certificateTemplate->getCertificateHash()],
68 'template_values' => ['clob', $certificateTemplate->getTemplateValues()],
69 'version' => ['integer', $certificateTemplate->getVersion()],
70 'ilias_version' => ['text', $certificateTemplate->getIliasVersion()],
71 'created_timestamp' => ['integer', $certificateTemplate->getCreatedTimestamp()],
72 'currently_active' => ['integer', (int) $certificateTemplate->isCurrentlyActive()],
73 'deleted' => ['integer', (int) $certificateTemplate->isDeleted()],
74 'background_image_ident' => [ilDBConstants::T_TEXT, $certificateTemplate->getBackgroundImageIdentification()],
75 'tile_image_ident' => [ilDBConstants::T_TEXT, $certificateTemplate->getTileImageIdentification()]
76 ];
77
78 $this->database->insert(self::TABLE_NAME, $columns);
79
80 $this->logger->debug(
81 sprintf(
82 'END - certificate template saved with columns: %s',
83 json_encode($columns, JSON_THROW_ON_ERROR)
84 )
85 );
86 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id, $objId, ILIAS\Repository\database(), deactivatePreviousTemplates(), ilCertificateTemplate\getBackgroundImageIdentification(), ilCertificateTemplate\getCertificateContent(), ilCertificateTemplate\getCertificateHash(), ilCertificateTemplate\getCreatedTimestamp(), ilCertificateTemplate\getIliasVersion(), ilCertificateTemplate\getObjId(), ilCertificateTemplate\getObjType(), ilCertificateTemplate\getTemplateValues(), ilCertificateTemplate\getTileImageIdentification(), ilCertificateTemplate\getVersion(), ILIAS\Repository\int(), ilCertificateTemplate\isCurrentlyActive(), ilCertificateTemplate\isDeleted(), ILIAS\Repository\logger(), and ilDBConstants\T_TEXT.

+ Here is the call graph for this function:

◆ updateActivity()

ilCertificateTemplateDatabaseRepository::updateActivity ( ilCertificateTemplate  $certificateTemplate,
bool  $currentlyActive 
)

Implements ilCertificateTemplateRepository.

Definition at line 88 of file class.ilCertificateTemplateDatabaseRepository.php.

88 : int
89 {
90 $sql = 'UPDATE ' . self::TABLE_NAME . ' SET currently_active = ' . $this->database->quote(
91 $currentlyActive,
93 ) .
94 ' WHERE id = ' . $this->database->quote($certificateTemplate->getId(), ilDBConstants::T_INTEGER);
95
96 return $this->database->manipulate($sql);
97 }

References ILIAS\Repository\database(), ilCertificateTemplate\getId(), and ilDBConstants\T_INTEGER.

+ Here is the call graph for this function:

◆ updateDefaultBackgroundImagePaths()

ilCertificateTemplateDatabaseRepository::updateDefaultBackgroundImagePaths ( ResourceIdentification|string  $new_rid,
ResourceIdentification|string  $old_rid 
)

Definition at line 402 of file class.ilCertificateTemplateDatabaseRepository.php.

405 : void {
406 $this->logger->debug(sprintf(
407 'START - Update all default background image ResourceIdentifications from "%s" to "%s"',
408 $old_rid,
409 $new_rid
410 ));
411
412 $affected_rows = $this->database->manipulateF(
413 'UPDATE il_cert_template SET background_image_ident = %s WHERE currently_active = 1 AND background_image_ident = %s',
414 [
417 ],
418 [
419 $new_rid instanceof ResourceIdentification ? $new_rid->serialize() : $new_rid,
420 $old_rid instanceof ResourceIdentification ? $old_rid->serialize() : $old_rid,
421 ]
422 );
423
424 $this->logger->debug(sprintf(
425 'END - Updated %s certificate templates using old ResourceIdentification',
426 $affected_rows
427 ));
428 }

Field Documentation

◆ $logger

readonly ilLogger ilCertificateTemplateDatabaseRepository::$logger
private

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

Referenced by __construct().

◆ $objectDataCache

readonly ilObjectDataCache ilCertificateTemplateDatabaseRepository::$objectDataCache
private

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

Referenced by __construct().

◆ TABLE_NAME

const ilCertificateTemplateDatabaseRepository::TABLE_NAME = 'il_cert_template'

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