ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 (string $old_relative_path, string $new_relative_path)
 
 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 26 of file class.ilCertificateTemplateDatabaseRepository.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

36 {
37 if (null === $logger) {
38 global $DIC;
39 $logger = $DIC->logger()->cert();
40 }
41 $this->logger = $logger;
42
43 if (null === $objectDataCache) {
44 global $DIC;
45 $objectDataCache = $DIC['ilObjDataCache'];
46 }
48 }
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 477 of file class.ilCertificateTemplateDatabaseRepository.php.

478 {
479 return new ilCertificateTemplate(
480 (int) $row['obj_id'],
481 $row['obj_type'],
482 $row['certificate_content'],
483 $row['certificate_hash'],
484 $row['template_values'],
485 (int) $row['version'],
486 $row['ilias_version'],
487 (int) $row['created_timestamp'],
488 (bool) $row['currently_active'],
489 (string) ($row['background_image_path'] ?? ''),
490 (string) ($row['tile_image_path'] ?? ''),
491 (string) ($row['background_image_ident'] ?? ''),
492 (string) ($row['tile_image_ident'] ?? ''),
493 isset($row['id']) ? (int) $row['id'] : null
494 );
495 }

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

+ Here is the caller graph for this function:

◆ deactivatePreviousTemplates()

ilCertificateTemplateDatabaseRepository::deactivatePreviousTemplates ( int  $objId)
private

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

398 : void
399 {
400 $this->logger->debug(sprintf('START - Deactivate previous certificate template for object: "%s"', $objId));
401
402 $sql = '
403 UPDATE ' . self::TABLE_NAME . '
404 SET currently_active = 0
405 WHERE obj_id = ' . $this->database->quote($objId, ilDBConstants::T_INTEGER);
406
407 $this->database->manipulate($sql);
408
409 $this->logger->debug(sprintf('END - Certificate template deactivated for object: "%s"', $objId));
410 }
$objId
Definition: xapitoken.php:57

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 259 of file class.ilCertificateTemplateDatabaseRepository.php.

259 : void
260 {
261 $this->logger->debug(
262 sprintf(
263 'START - Set deleted flag for certificate template("%s") for object: "%s"',
264 $templateId,
265 $objectId
266 )
267 );
268
269 $sql = '
270 UPDATE ' . self::TABLE_NAME . '
271 SET deleted = 1, currently_active = 0
272 WHERE id = ' . $this->database->quote($templateId, ilDBConstants::T_INTEGER) . '
273 AND obj_id = ' . $this->database->quote($objectId, ilDBConstants::T_INTEGER);
274
275 $this->database->manipulate($sql);
276
277 $this->logger->debug(
278 sprintf(
279 'END - Deleted flag set fo certificate template("%s") for object: "%s"',
280 $templateId,
281 $objectId
282 )
283 );
284 }

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 313 of file class.ilCertificateTemplateDatabaseRepository.php.

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

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 128 of file class.ilCertificateTemplateDatabaseRepository.php.

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

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 202 of file class.ilCertificateTemplateDatabaseRepository.php.

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

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 159 of file class.ilCertificateTemplateDatabaseRepository.php.

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

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 375 of file class.ilCertificateTemplateDatabaseRepository.php.

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

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 224 of file class.ilCertificateTemplateDatabaseRepository.php.

225 {
226 $this->logger->debug(sprintf('START - Fetch previous active certificate template for object: "%s"', $objId));
227
228 $templates = $this->fetchCertificateTemplatesByObjId($objId);
229
230 $resultTemplate = new ilCertificateTemplate(
231 $objId,
232 $this->objectDataCache->lookupType($objId),
233 '',
234 '',
235 '',
236 0,
237 '0',
238 0,
239 true,
240 '',
241 '',
242 '',
243 ''
244 );
245
246 $version = 0;
247 foreach ($templates as $template) {
248 if ($template->getVersion() > $version) {
249 $version = $template->getVersion();
250 $resultTemplate = $template;
251 }
252 }
253
254 $this->logger->debug(sprintf('Latest version active certificate template for object: "%s"', $objId));
255
256 return $resultTemplate;
257 }
$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 105 of file class.ilCertificateTemplateDatabaseRepository.php.

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

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 445 of file class.ilCertificateTemplateDatabaseRepository.php.

445 : bool
446 {
447 $this->logger->debug(
448 sprintf(
449 'START - Checking if any certificate template uses resource id "%s"',
450 $relative_image_identification
451 )
452 );
453
454 $result = $this->database->queryF(
455 'SELECT EXISTS(SELECT 1 FROM ' . self::TABLE_NAME . ' WHERE
456 (background_image_ident = %s OR tile_image_ident = %s)
457 AND currently_active = 1) AS does_exist',
459 [$relative_image_identification, $relative_image_identification]
460 );
461
462 $exists = (bool) ($this->database->fetchAssoc($result)['does_exist'] ?? false);
463
464 $this->logger->debug(
465 sprintf(
466 'END - Image path "%s" is ' . $exists ? 'in use' : 'unused',
467 $relative_image_identification
468 )
469 );
470
471 return $exists;
472 }

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 50 of file class.ilCertificateTemplateDatabaseRepository.php.

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

References $id, $objId, ILIAS\Repository\database(), deactivatePreviousTemplates(), ilCertificateTemplate\getBackgroundImageIdentification(), ilCertificateTemplate\getBackgroundImagePath(), ilCertificateTemplate\getCertificateContent(), ilCertificateTemplate\getCertificateHash(), ilCertificateTemplate\getCreatedTimestamp(), ilCertificateTemplate\getIliasVersion(), ilCertificateTemplate\getObjId(), ilCertificateTemplate\getObjType(), ilCertificateTemplate\getTemplateValues(), ilCertificateTemplate\getTileImageIdentification(), ilCertificateTemplate\getTileImagePath(), 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 94 of file class.ilCertificateTemplateDatabaseRepository.php.

94 : int
95 {
96 $sql = 'UPDATE ' . self::TABLE_NAME . ' SET currently_active = ' . $this->database->quote(
97 $currentlyActive,
99 ) .
100 ' WHERE id = ' . $this->database->quote($certificateTemplate->getId(), ilDBConstants::T_INTEGER);
101
102 return $this->database->manipulate($sql);
103 }

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

+ Here is the call graph for this function:

◆ updateDefaultBackgroundImagePaths()

ilCertificateTemplateDatabaseRepository::updateDefaultBackgroundImagePaths ( string  $old_relative_path,
string  $new_relative_path 
)

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

412 : void
413 {
414 $this->logger->debug(
415 sprintf(
416 'START - Update all default background image paths from "%s" to "%s"',
417 $old_relative_path,
418 $new_relative_path
419 )
420 );
421
422 $affected_rows = $this->database->manipulateF(
423 'UPDATE ' . self::TABLE_NAME . ' SET background_image_ident = %s ' .
424 'WHERE currently_active = 1 AND (background_image_ident = %s OR background_image_ident = %s )',
425 [
426 'text',
427 'text',
428 'text'
429 ],
430 [
431 $new_relative_path,
432 $old_relative_path,
433 '/certificates/default/background.jpg'
434 ]
435 );
436
437 $this->logger->debug(
438 sprintf(
439 'END - Updated %s certificate templates using old path',
440 $affected_rows
441 )
442 );
443 }

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

+ Here is the call graph for this function:

Field Documentation

◆ $logger

readonly ilLogger ilCertificateTemplateDatabaseRepository::$logger
private

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

Referenced by __construct().

◆ $objectDataCache

readonly ilObjectDataCache ilCertificateTemplateDatabaseRepository::$objectDataCache
private

Definition at line 30 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: