ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilCertificateTemplateDatabaseRepository Class Reference
+ Inheritance diagram for ilCertificateTemplateDatabaseRepository:
+ Collaboration diagram for ilCertificateTemplateDatabaseRepository:

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)
 
 deleteTemplate (int $templateId, int $objectId)
 
 fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress (bool $isGlobalLpEnabled, ?int $forRefId=null)
 
 fetchFirstCreatedTemplate (int $objId)
 
 updateDefaultBackgroundImagePaths (string $old_relative_path, string $new_relative_path)
 
 isBackgroundImageUsed (string $relative_image_path)
 
- Public Member Functions inherited from ilCertificateTemplateRepository
 activatePreviousCertificate (int $objId)
 

Private Member Functions

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

Private Attributes

ilDBInterface $database
 
ilLogger $logger
 
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 ( ilDBInterface  $database,
?ilLogger  $logger = null,
?ilObjectDataCache  $objectDataCache = null 
)

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

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

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: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ createCertificateTemplate()

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

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

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

450  {
451  return new ilCertificateTemplate(
452  (int) $row['obj_id'],
453  $row['obj_type'],
454  $row['certificate_content'],
455  $row['certificate_hash'],
456  $row['template_values'],
457  (int) $row['version'],
458  $row['ilias_version'],
459  (int) $row['created_timestamp'],
460  (bool) $row['currently_active'],
461  (string) $row['background_image_path'],
462  (string) $row['thumbnail_image_path'],
463  isset($row['id']) ? (int) $row['id'] : null
464  );
465  }
+ Here is the caller graph for this function:

◆ deactivatePreviousTemplates()

ilCertificateTemplateDatabaseRepository::deactivatePreviousTemplates ( int  $objId)
private

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

References ILIAS\Repository\logger().

Referenced by save().

381  : void
382  {
383  $this->logger->debug(sprintf('START - Deactivate previous certificate template for object: "%s"', $objId));
384 
385  $sql = '
386 UPDATE il_cert_template
387 SET currently_active = 0
388 WHERE obj_id = ' . $this->database->quote($objId, 'integer');
389 
390  $this->database->manipulate($sql);
391 
392  $this->logger->debug(sprintf('END - Certificate template deactivated for object: "%s"', $objId));
393  }
$objId
Definition: xapitoken.php:57
+ 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 248 of file class.ilCertificateTemplateDatabaseRepository.php.

References $objId, ilCertificateTemplateRepository\activatePreviousCertificate(), fetchCertificateTemplatesByObjId(), and ILIAS\Repository\logger().

248  : void
249  {
250  $this->logger->debug(sprintf(
251  'START - Set deleted flag for certificate template("%s") for object: "%s"',
252  $templateId,
253  $objectId
254  ));
255 
256  $sql = '
257 UPDATE il_cert_template
258 SET deleted = 1, currently_active = 0
259 WHERE id = ' . $this->database->quote($templateId, 'integer') . '
260 AND obj_id = ' . $this->database->quote($objectId, 'integer');
261 
262  $this->database->manipulate($sql);
263 
264  $this->logger->debug(sprintf(
265  'END - Deleted flag set fo certificate template("%s") for object: "%s"',
266  $templateId,
267  $objectId
268  ));
269  }
+ Here is the call graph for this function:

◆ fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress()

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

Implements ilCertificateTemplateRepository.

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

References $query, createCertificateTemplate(), ILIAS\Repository\logger(), and ilLPObjSettings\LP_MODE_DEACTIVATED.

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

◆ fetchCertificateTemplatesByObjId()

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

Implements ilCertificateTemplateRepository.

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

References $query, createCertificateTemplate(), and ILIAS\Repository\logger().

Referenced by deleteTemplate(), and fetchPreviousCertificate().

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 il_cert_template
131 WHERE obj_id = ' . $this->database->quote($objId, 'integer') . '
132 AND deleted = 0
133 ORDER BY version ASC';
134 
135  $query = $this->database->query($sql);
136 
137  while ($row = $this->database->fetchAssoc($query)) {
138  $result[] = $this->createCertificateTemplate($row);
139  }
140 
141  $this->logger->debug(sprintf(
142  'END - Fetching of certificate templates for object: "%s" with "%s" results',
143  $objId,
144  count($result)
145  ));
146 
147  return $result;
148  }
$objId
Definition: xapitoken.php:57
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fetchCurrentlyActiveCertificate()

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

Implements ilCertificateTemplateRepository.

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

References $query, createCertificateTemplate(), and ILIAS\Repository\logger().

194  {
195  $this->logger->debug(sprintf('START - Fetch currently active certificate template for object: "%s"', $objId));
196 
197  $sql = '
198 SELECT * FROM il_cert_template
199 WHERE obj_id = ' . $this->database->quote($objId, 'integer') . '
200 AND deleted = 0
201 AND currently_active = 1
202 ';
203 
204  $query = $this->database->query($sql);
205 
206  while ($row = $this->database->fetchAssoc($query)) {
207  $this->logger->debug(sprintf('END - Found active certificate for: "%s"', $objId));
208 
209  return $this->createCertificateTemplate($row);
210  }
211 
212  throw new ilException((sprintf('NO active certificate template found for: "%s"', $objId)));
213  }
$objId
Definition: xapitoken.php:57
$query
+ Here is the call graph for this function:

◆ fetchCurrentlyUsedCertificate()

ilCertificateTemplateDatabaseRepository::fetchCurrentlyUsedCertificate ( int  $objId)

Implements ilCertificateTemplateRepository.

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

References $query, createCertificateTemplate(), and ILIAS\Repository\logger().

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

◆ fetchFirstCreatedTemplate()

ilCertificateTemplateDatabaseRepository::fetchFirstCreatedTemplate ( int  $objId)
Parameters
int$objId
Returns
ilCertificateTemplate
Exceptions
ilException

Implements ilCertificateTemplateRepository.

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

References $query, createCertificateTemplate(), and ILIAS\Repository\logger().

361  {
362  $this->logger->debug(sprintf('START - Fetch first create certificate template for object: "%s"', $objId));
363 
364  $this->database->setLimit(1, 0);
365 
366  $sql = 'SELECT * FROM il_cert_template
367 WHERE obj_id = ' . $this->database->quote($objId, 'integer') . '
368 ORDER BY id ASC ';
369 
370  $query = $this->database->query($sql);
371 
372  while ($row = $this->database->fetchAssoc($query)) {
373  $this->logger->debug(sprintf('END - Found first create certificate template for object: "%s"', $objId));
374 
375  return $this->createCertificateTemplate($row);
376  }
377 
378  throw new ilException('No matching template found. MAY missing DBUpdate. Please check if the correct version is installed.');
379  }
$objId
Definition: xapitoken.php:57
$query
+ Here is the call graph for this function:

◆ fetchPreviousCertificate()

ilCertificateTemplateDatabaseRepository::fetchPreviousCertificate ( int  $objId)

Implements ilCertificateTemplateRepository.

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

References $version, fetchCertificateTemplatesByObjId(), ilCertificateTemplate\getVersion(), and ILIAS\Repository\logger().

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

◆ fetchTemplate()

ilCertificateTemplateDatabaseRepository::fetchTemplate ( int  $templateId)
Parameters
int$templateId
Returns
ilCertificateTemplate
Exceptions
ilException

Implements ilCertificateTemplateRepository.

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

References $query, createCertificateTemplate(), and ILIAS\Repository\logger().

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

◆ isBackgroundImageUsed()

ilCertificateTemplateDatabaseRepository::isBackgroundImageUsed ( string  $relative_image_path)

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

References ILIAS\Repository\logger().

422  : bool
423  {
424  $this->logger->debug(sprintf(
425  'START - Checking if any certificate template uses background image path "%s"',
426  $relative_image_path
427  ));
428 
429  $result = $this->database->queryF(
430  'SELECT EXISTS(SELECT 1 FROM il_cert_template WHERE background_image_path = %s AND currently_active = 1) AS does_exist',
431  ['text'],
432  [$relative_image_path]
433  );
434 
435  $exists = (bool) ($this->database->fetchAssoc($result)['does_exist'] ?? false);
436 
437  $this->logger->debug(sprintf(
438  'END - Image path "%s" is ' . $exists ? "in use" : "unused",
439  $relative_image_path
440  ));
441 
442  return $exists;
443  }
+ Here is the call graph for this function:

◆ save()

ilCertificateTemplateDatabaseRepository::save ( ilCertificateTemplate  $certificateTemplate)

Implements ilCertificateTemplateRepository.

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

References $id, $objId, deactivatePreviousTemplates(), ilCertificateTemplate\getBackgroundImagePath(), ilCertificateTemplate\getCertificateContent(), ilCertificateTemplate\getCertificateHash(), ilCertificateTemplate\getCreatedTimestamp(), ilCertificateTemplate\getIliasVersion(), ilCertificateTemplate\getObjId(), ilCertificateTemplate\getObjType(), ilCertificateTemplate\getTemplateValues(), ilCertificateTemplate\getThumbnailImagePath(), ilCertificateTemplate\getVersion(), ILIAS\Repository\int(), ilCertificateTemplate\isCurrentlyActive(), ilCertificateTemplate\isDeleted(), and ILIAS\Repository\logger().

52  : void
53  {
54  $this->logger->debug('START - Save new certificate template');
55 
56  $objId = $certificateTemplate->getObjId();
57 
58  $id = $this->database->nextId('il_cert_template');
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  'background_image_path' => ['text', $certificateTemplate->getBackgroundImagePath()],
74  'deleted' => ['integer', (int) $certificateTemplate->isDeleted()],
75  'thumbnail_image_path' => ['text', $certificateTemplate->getThumbnailImagePath()]
76  ];
77 
78  $this->database->insert('il_cert_template', $columns);
79 
80  $this->logger->debug(sprintf(
81  'END - certificate template saved with columns: %s',
82  json_encode($columns, JSON_THROW_ON_ERROR)
83  ));
84  }
$objId
Definition: xapitoken.php:57
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ updateActivity()

ilCertificateTemplateDatabaseRepository::updateActivity ( ilCertificateTemplate  $certificateTemplate,
bool  $currentlyActive 
)
Parameters
ilCertificateTemplate$certificateTemplate
bool$currentlyActive
Returns
int

Implements ilCertificateTemplateRepository.

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

References ilCertificateTemplate\getId().

86  : int
87  {
88  $sql = 'UPDATE il_cert_template SET currently_active = ' . $this->database->quote($currentlyActive, 'integer') .
89  ' WHERE id = ' . $this->database->quote($certificateTemplate->getId(), 'integer');
90 
91  return $this->database->manipulate($sql);
92  }
+ Here is the call graph for this function:

◆ updateDefaultBackgroundImagePaths()

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

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

References ILIAS\Repository\logger().

395  : void
396  {
397  $this->logger->debug(sprintf(
398  'START - Update all default background image paths from "%s" to "%s"',
399  $old_relative_path,
400  $new_relative_path
401  ));
402 
403  $affected_rows = $this->database->manipulateF(
404  'UPDATE il_cert_template SET background_image_path = %s WHERE currently_active = 1 AND (background_image_path = %s OR background_image_path = %s )',
405  [
406  'text',
407  'text',
408  'text'
409  ],
410  [
411  $new_relative_path,
412  $old_relative_path,
413  '/certificates/default/background.jpg']
414  );
415 
416  $this->logger->debug(sprintf(
417  'END - Updated %s certificate templates using old path',
418  $affected_rows
419  ));
420  }
+ Here is the call graph for this function:

Field Documentation

◆ $database

ilDBInterface ilCertificateTemplateDatabaseRepository::$database
private

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

Referenced by __construct().

◆ $logger

ilLogger ilCertificateTemplateDatabaseRepository::$logger
private

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

Referenced by __construct().

◆ $objectDataCache

ilObjectDataCache ilCertificateTemplateDatabaseRepository::$objectDataCache
private

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

Referenced by __construct().


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