ILIAS  release_7 Revision v7.30-3-g800a261c036
ilCertificateTemplateRepository Class Reference
+ Collaboration diagram for ilCertificateTemplateRepository:

Public Member Functions

 __construct (\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)
 Fetch latest created certificate EVEN IF it is deleted. More...
 
 deleteTemplate (int $templateId, int $objectId)
 
 fetchActiveTemplatesByType (string $type)
 
 fetchFirstCreatedTemplate (int $objId)
 
 updateDefaultBackgroundImagePaths (string $oldRelativePath, string $newRelativePath)
 
 isBackgroundImageUsed (string $relativeImagePath)
 

Private Member Functions

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

Private Attributes

 $database
 
 $logger
 
 $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 10 of file class.ilCertificateTemplateRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ilCertificateTemplateRepository::__construct ( \ilDBInterface  $database,
\ilLogger  $logger = null,
\ilObjectDataCache  $objectDataCache = null 
)
Parameters
\ilDBInterface$database
\ilLogger$logger
\ilObjectDataCache | null$objectDataCache

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

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

References $database, $DIC, $logger, and $objectDataCache.

Member Function Documentation

◆ createCertificateTemplate()

ilCertificateTemplateRepository::createCertificateTemplate ( array  $row)
private
Parameters
array$row
Returns
ilCertificateTemplate

Definition at line 427 of file class.ilCertificateTemplateRepository.php.

428 {
429 return new ilCertificateTemplate(
430 $row['obj_id'],
431 $row['obj_type'],
432 $row['certificate_content'],
433 $row['certificate_hash'],
434 $row['template_values'],
435 $row['version'],
436 $row['ilias_version'],
437 $row['created_timestamp'],
438 (boolean) $row['currently_active'],
439 $row['background_image_path'],
440 $row['thumbnail_image_path'],
441 $row['id']
442 );
443 }

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

+ Here is the caller graph for this function:

◆ deactivatePreviousTemplates()

ilCertificateTemplateRepository::deactivatePreviousTemplates ( int  $objId)
private
Parameters
int$objId
Exceptions
ilDatabaseException

Definition at line 359 of file class.ilCertificateTemplateRepository.php.

360 {
361 $this->logger->info(sprintf('START - Deactivate previous certificate template for object: "%s"', $objId));
362
363 $sql = '
364UPDATE il_cert_template
365SET currently_active = 0
366WHERE obj_id = ' . $this->database->quote($objId, 'integer');
367
368 $this->database->manipulate($sql);
369
370 $this->logger->info(sprintf('END - Certificate template deactivated for object: "%s"', $objId));
371 }
$objId
Definition: xapitoken.php:39

References $objId.

Referenced by save().

+ Here is the caller graph for this function:

◆ deleteTemplate()

ilCertificateTemplateRepository::deleteTemplate ( int  $templateId,
int  $objectId 
)
Parameters
int$templateId
int$objectId
Exceptions
ilDatabaseException

Definition at line 256 of file class.ilCertificateTemplateRepository.php.

257 {
258 $this->logger->info(sprintf('START - Set deleted flag for certificate template("%s") for object: "%s"', $templateId, $objectId));
259
260 $sql = '
261UPDATE il_cert_template
262SET deleted = 1, currently_active = 0
263WHERE id = ' . $this->database->quote($templateId, 'integer') . '
264AND obj_id = ' . $this->database->quote($objectId, 'integer');
265
266 $this->database->manipulate($sql);
267
268 $this->logger->info(sprintf('END - Deleted flag set fo certificate template("%s") for object: "%s"', $templateId, $objectId));
269 }

◆ fetchActiveTemplatesByType()

ilCertificateTemplateRepository::fetchActiveTemplatesByType ( string  $type)
Parameters
string$type
Returns
ilCertificateTemplate[]

Definition at line 307 of file class.ilCertificateTemplateRepository.php.

307 : array
308 {
309 $this->logger->info(sprintf('START - Fetch all active certificate templates for object type: "%s"', $type));
310
311 $sql = '
312 SELECT il_cert_template.* FROM il_cert_template
313 INNER JOIN object_data od ON od.obj_id = il_cert_template.obj_id
314 WHERE obj_type = ' . $this->database->quote($type, 'text') . '
315 AND currently_active = 1
316 ';
317 $query = $this->database->query($sql);
318
319 $result = array();
320 while ($row = $this->database->fetchAssoc($query)) {
321 $result[] = $this->createCertificateTemplate($row);
322 }
323
324 $this->logger->info(sprintf('END - All certificate templates for object type: "%s": "%s"', $type, json_encode($result)));
325
326 return $result;
327 }
$result
$query
$type

References $query, $result, $type, and createCertificateTemplate().

+ Here is the call graph for this function:

◆ fetchCertificateTemplatesByObjId()

ilCertificateTemplateRepository::fetchCertificateTemplatesByObjId ( int  $objId)
Parameters
int$objId
Returns
\ilCertificateTemplate[]

Definition at line 119 of file class.ilCertificateTemplateRepository.php.

119 : array
120 {
121 $this->logger->info(sprintf('START - Fetch multiple certificate templates for object: "%s"', $objId));
122
123 $result = array();
124
125 $sql = '
126SELECT * FROM
127il_cert_template
128WHERE obj_id = ' . $this->database->quote($objId, 'integer') . '
129AND deleted = 0
130ORDER BY version ASC';
131
132 $query = $this->database->query($sql);
133
134 while ($row = $this->database->fetchAssoc($query)) {
135 $result[] = $this->createCertificateTemplate($row);
136 }
137
138 $this->logger->info(sprintf('END - Fetching of certificate templates for object: "%s" with "%s" results', $objId, count($result)));
139
140 return $result;
141 }

References $objId, $query, $result, and createCertificateTemplate().

Referenced by fetchPreviousCertificate().

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

◆ fetchCurrentlyActiveCertificate()

ilCertificateTemplateRepository::fetchCurrentlyActiveCertificate ( int  $objId)
Parameters
int$objId
Returns
\ilCertificateTemplate
Exceptions
ilException

Definition at line 190 of file class.ilCertificateTemplateRepository.php.

191 {
192 $this->logger->info(sprintf('START - Fetch currently active certificate template for object: "%s"', $objId));
193
194 $sql = '
195SELECT * FROM il_cert_template
196WHERE obj_id = ' . $this->database->quote($objId, 'integer') . '
197AND deleted = 0
198AND currently_active = 1
199';
200
201 $query = $this->database->query($sql);
202
203 while ($row = $this->database->fetchAssoc($query)) {
204 $this->logger->info(sprintf('END - Found active certificate for: "%s"', $objId));
205
206 return $this->createCertificateTemplate($row);
207 }
208
209 throw new ilException((sprintf('NO active certificate template found for: "%s"', $objId)));
210 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $objId, $query, and createCertificateTemplate().

+ Here is the call graph for this function:

◆ fetchCurrentlyUsedCertificate()

ilCertificateTemplateRepository::fetchCurrentlyUsedCertificate ( int  $objId)
Parameters
int$objId
Returns
\ilCertificateTemplate

Definition at line 147 of file class.ilCertificateTemplateRepository.php.

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

References $objId, $query, and createCertificateTemplate().

+ Here is the call graph for this function:

◆ fetchFirstCreatedTemplate()

ilCertificateTemplateRepository::fetchFirstCreatedTemplate ( int  $objId)
Parameters
int$objId
Returns
\ilCertificateTemplate
Exceptions

ilException

Definition at line 334 of file class.ilCertificateTemplateRepository.php.

335 {
336 $this->logger->info(sprintf('START - Fetch first create certificate template for object: "%s"', $objId));
337
338 $this->database->setLimit(1, 0);
339
340 $sql = 'SELECT * FROM il_cert_template
341WHERE obj_id = ' . $this->database->quote($objId, 'integer') . '
342ORDER BY id ASC ';
343
344 $query = $this->database->query($sql);
345
346 while ($row = $this->database->fetchAssoc($query)) {
347 $this->logger->info(sprintf('END - Found first create certificate template for object: "%s"', $objId));
348
349 return $this->createCertificateTemplate($row);
350 }
351
352 throw new ilException('No matching template found. MAY missing DBUpdate. Please check if the correct version is installed.');
353 }

References $objId, $query, and createCertificateTemplate().

+ Here is the call graph for this function:

◆ fetchPreviousCertificate()

ilCertificateTemplateRepository::fetchPreviousCertificate ( int  $objId)

Fetch latest created certificate EVEN IF it is deleted.

Parameters
int$objId
Returns
\ilCertificateTemplate

Definition at line 218 of file class.ilCertificateTemplateRepository.php.

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

References $objId, and fetchCertificateTemplatesByObjId().

+ Here is the call graph for this function:

◆ fetchTemplate()

ilCertificateTemplateRepository::fetchTemplate ( int  $templateId)

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

97 {
98 $this->logger->info(sprintf('START - Fetch certificate template with id: "%s"', $templateId));
99
100 $sql = '
101SELECT * FROM
102il_cert_template
103WHERE id = ' . $this->database->quote($templateId, 'integer') . '
104ORDER BY version ASC';
105
106 $query = $this->database->query($sql);
107
108 while ($row = $this->database->fetchAssoc($query)) {
109 return $this->createCertificateTemplate($row);
110 }
111
112 throw new ilException(sprintf('No template with id "%s" found', $templateId));
113 }

References $query, and createCertificateTemplate().

+ Here is the call graph for this function:

◆ isBackgroundImageUsed()

ilCertificateTemplateRepository::isBackgroundImageUsed ( string  $relativeImagePath)

Definition at line 400 of file class.ilCertificateTemplateRepository.php.

400 : bool
401 {
402 $this->logger->debug(sprintf(
403 'START - Checking if any certificate template uses background image path "%s"',
404 $relativeImagePath
405 ));
406
407 $result = $this->database->queryF(
408 'SELECT EXISTS(SELECT 1 FROM il_cert_template WHERE background_image_path = %s AND currently_active = 1) AS does_exist',
409 ['text'],
410 [$relativeImagePath]
411 );
412
413 $exists = (bool) ($this->database->fetchAssoc($result)['does_exist'] ?? false);
414
415 $this->logger->debug(sprintf(
416 'END - Image path "%s" is ' . $exists ? "in use" : "unused",
417 $relativeImagePath
418 ));
419
420 return $exists;
421 }

References $result.

◆ save()

ilCertificateTemplateRepository::save ( ilCertificateTemplate  $certificateTemplate)
Parameters
ilCertificateTemplate$certificateTemplate
Exceptions
ilDatabaseException

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

57 {
58 $this->logger->info('START - Save new certificate template');
59
60 $objId = $certificateTemplate->getObjId();
61
62 $id = $this->database->nextId('il_cert_template');
63
65
66 $columns = array(
67 'id' => array('integer', $id),
68 'obj_id' => array('integer', $objId),
69 'obj_type' => array('text', $certificateTemplate->getObjType()),
70 'certificate_content' => array('clob', $certificateTemplate->getCertificateContent()),
71 'certificate_hash' => array('text', $certificateTemplate->getCertificateHash()),
72 'template_values' => array('clob', $certificateTemplate->getTemplateValues()),
73 'version' => array('integer', $certificateTemplate->getVersion()),
74 'ilias_version' => array('text', $certificateTemplate->getIliasVersion()),
75 'created_timestamp' => array('integer', $certificateTemplate->getCreatedTimestamp()),
76 'currently_active' => array('integer', (integer) $certificateTemplate->isCurrentlyActive()),
77 'background_image_path' => array('text', $certificateTemplate->getBackgroundImagePath()),
78 'deleted' => array('integer', (integer) $certificateTemplate->isDeleted()),
79 'thumbnail_image_path' => array('text', $certificateTemplate->getThumbnailImagePath())
80 );
81
82 $this->database->insert('il_cert_template', $columns);
83
84 $this->logger->info('END - certificate template saved with columns: ', json_encode($columns));
85 }
if(! $in) $columns
Definition: Utf8Test.php:45

References $columns, $objId, deactivatePreviousTemplates(), ilCertificateTemplate\getBackgroundImagePath(), ilCertificateTemplate\getCertificateContent(), ilCertificateTemplate\getCertificateHash(), ilCertificateTemplate\getCreatedTimestamp(), ilCertificateTemplate\getIliasVersion(), ilCertificateTemplate\getObjId(), ilCertificateTemplate\getObjType(), ilCertificateTemplate\getTemplateValues(), ilCertificateTemplate\getThumbnailImagePath(), ilCertificateTemplate\getVersion(), ilCertificateTemplate\isCurrentlyActive(), and ilCertificateTemplate\isDeleted().

+ Here is the call graph for this function:

◆ updateActivity()

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

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

89 {
90 $sql = 'UPDATE il_cert_template SET currently_active = ' . $this->database->quote($currentlyActive, 'integer') .
91 ' WHERE id = ' . $this->database->quote($certificateTemplate->getId(), 'integer');
92
93 return $this->database->manipulate($sql);
94 }

References ilCertificateTemplate\getId().

+ Here is the call graph for this function:

◆ updateDefaultBackgroundImagePaths()

ilCertificateTemplateRepository::updateDefaultBackgroundImagePaths ( string  $oldRelativePath,
string  $newRelativePath 
)

Definition at line 373 of file class.ilCertificateTemplateRepository.php.

373 : void
374 {
375 $this->logger->debug(sprintf(
376 'START - Update all default background image paths from "%s" to "%s"',
377 $oldRelativePath,
378 $newRelativePath
379 ));
380
381 $affectedRows = $this->database->manipulateF(
382 'UPDATE il_cert_template SET background_image_path = %s WHERE currently_active = 1 AND (background_image_path = %s OR background_image_path = %s )',
383 [
384 'text',
385 'text',
386 'text'
387 ],
388 [
389 $newRelativePath,
390 $oldRelativePath,
391 '/certificates/default/background.jpg']
392 );
393
394 $this->logger->debug(sprintf(
395 'END - Updated %s certificate templates using old path',
396 $affectedRows
397 ));
398 }

Field Documentation

◆ $database

ilCertificateTemplateRepository::$database
private

Definition at line 15 of file class.ilCertificateTemplateRepository.php.

Referenced by __construct().

◆ $logger

ilCertificateTemplateRepository::$logger
private

Definition at line 20 of file class.ilCertificateTemplateRepository.php.

Referenced by __construct().

◆ $objectDataCache

ilCertificateTemplateRepository::$objectDataCache
private

Definition at line 25 of file class.ilCertificateTemplateRepository.php.

Referenced by __construct().


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