ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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)
 
 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

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

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

35  {
36  if (null === $logger) {
37  global $DIC;
38  $logger = $DIC->logger()->cert();
39  }
40  $this->logger = $logger;
41 
42  if (null === $objectDataCache) {
43  global $DIC;
44  $objectDataCache = $DIC['ilObjDataCache'];
45  }
47  }
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

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

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

436  {
437  return new ilCertificateTemplate(
438  (int) $row['obj_id'],
439  $row['obj_type'],
440  $row['certificate_content'],
441  $row['certificate_hash'],
442  $row['template_values'],
443  (int) $row['version'],
444  $row['ilias_version'],
445  (int) $row['created_timestamp'],
446  (bool) $row['currently_active'],
447  (string) $row['background_image_path'],
448  (string) $row['thumbnail_image_path'],
449  isset($row['id']) ? (int) $row['id'] : null
450  );
451  }
+ Here is the caller graph for this function:

◆ deactivatePreviousTemplates()

ilCertificateTemplateDatabaseRepository::deactivatePreviousTemplates ( int  $objId)
private

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

References ILIAS\Repository\logger().

Referenced by save().

368  : void
369  {
370  $this->logger->debug(sprintf('START - Deactivate previous certificate template for object: "%s"', $objId));
371 
372  $sql = '
373 UPDATE il_cert_template
374 SET currently_active = 0
375 WHERE obj_id = ' . $this->database->quote($objId, 'integer');
376 
377  $this->database->manipulate($sql);
378 
379  $this->logger->debug(sprintf('END - Certificate template deactivated for object: "%s"', $objId));
380  }
$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 237 of file class.ilCertificateTemplateDatabaseRepository.php.

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

237  : void
238  {
239  $this->logger->debug(sprintf(
240  'START - Set deleted flag for certificate template("%s") for object: "%s"',
241  $templateId,
242  $objectId
243  ));
244 
245  $sql = '
246 UPDATE il_cert_template
247 SET deleted = 1, currently_active = 0
248 WHERE id = ' . $this->database->quote($templateId, 'integer') . '
249 AND obj_id = ' . $this->database->quote($objectId, 'integer');
250 
251  $this->database->manipulate($sql);
252 
253  $this->logger->debug(sprintf(
254  'END - Deleted flag set fo certificate template("%s") for object: "%s"',
255  $templateId,
256  $objectId
257  ));
258  }
+ Here is the call graph for this function:

◆ fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress()

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

Implements ilCertificateTemplateRepository.

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

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

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

◆ fetchCertificateTemplatesByObjId()

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

Implements ilCertificateTemplateRepository.

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

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

Referenced by deleteTemplate(), and fetchPreviousCertificate().

113  : array
114  {
115  $this->logger->debug(sprintf('START - Fetch multiple certificate templates for object: "%s"', $objId));
116 
117  $result = [];
118 
119  $sql = '
120 SELECT * FROM
121 il_cert_template
122 WHERE obj_id = ' . $this->database->quote($objId, 'integer') . '
123 AND deleted = 0
124 ORDER BY version ASC';
125 
126  $query = $this->database->query($sql);
127 
128  while ($row = $this->database->fetchAssoc($query)) {
129  $result[] = $this->createCertificateTemplate($row);
130  }
131 
132  $this->logger->debug(sprintf(
133  'END - Fetching of certificate templates for object: "%s" with "%s" results',
134  $objId,
135  count($result)
136  ));
137 
138  return $result;
139  }
$objId
Definition: xapitoken.php:57
+ 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 182 of file class.ilCertificateTemplateDatabaseRepository.php.

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

183  {
184  $this->logger->debug(sprintf('START - Fetch currently active certificate template for object: "%s"', $objId));
185 
186  $sql = '
187 SELECT * FROM il_cert_template
188 WHERE obj_id = ' . $this->database->quote($objId, 'integer') . '
189 AND deleted = 0
190 AND currently_active = 1
191 ';
192 
193  $query = $this->database->query($sql);
194 
195  while ($row = $this->database->fetchAssoc($query)) {
196  $this->logger->debug(sprintf('END - Found active certificate for: "%s"', $objId));
197 
198  return $this->createCertificateTemplate($row);
199  }
200 
201  throw new ilCouldNotFindCertificateTemplate((sprintf('NO active certificate template found for: "%s"', $objId)));
202  }
$objId
Definition: xapitoken.php:57
+ Here is the call graph for this function:

◆ fetchCurrentlyUsedCertificate()

ilCertificateTemplateDatabaseRepository::fetchCurrentlyUsedCertificate ( int  $objId)

Implements ilCertificateTemplateRepository.

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

References createCertificateTemplate(), ILIAS\Repository\logger(), and ILIAS\Repository\objectDataCache().

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

◆ fetchFirstCreatedTemplate()

ilCertificateTemplateDatabaseRepository::fetchFirstCreatedTemplate ( int  $objId)
Exceptions
ilCouldNotFindCertificateTemplate

Implements ilCertificateTemplateRepository.

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

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

348  {
349  $this->logger->debug(sprintf('START - Fetch first create certificate template for object: "%s"', $objId));
350 
351  $this->database->setLimit(1, 0);
352 
353  $sql = 'SELECT * FROM il_cert_template
354 WHERE obj_id = ' . $this->database->quote($objId, 'integer') . '
355 ORDER BY id ASC ';
356 
357  $query = $this->database->query($sql);
358 
359  while ($row = $this->database->fetchAssoc($query)) {
360  $this->logger->debug(sprintf('END - Found first create certificate template for object: "%s"', $objId));
361 
362  return $this->createCertificateTemplate($row);
363  }
364 
365  throw new ilCouldNotFindCertificateTemplate('No matching template found. MAY missing DBUpdate. Please check if the correct version is installed.');
366  }
$objId
Definition: xapitoken.php:57
+ Here is the call graph for this function:

◆ fetchPreviousCertificate()

ilCertificateTemplateDatabaseRepository::fetchPreviousCertificate ( int  $objId)

Implements ilCertificateTemplateRepository.

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

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

205  {
206  $this->logger->debug(sprintf('START - Fetch previous active certificate template for object: "%s"', $objId));
207 
208  $templates = $this->fetchCertificateTemplatesByObjId($objId);
209 
210  $resultTemplate = new ilCertificateTemplate(
211  $objId,
212  $this->objectDataCache->lookupType($objId),
213  '',
214  '',
215  '',
216  0,
217  "0",
218  0,
219  true,
220  '',
221  ''
222  );
223 
224  $version = 0;
225  foreach ($templates as $template) {
226  if ($template->getVersion() > $version) {
227  $version = $template->getVersion();
228  $resultTemplate = $template;
229  }
230  }
231 
232  $this->logger->debug(sprintf('Latest version active certificate template for object: "%s"', $objId));
233 
234  return $resultTemplate;
235  }
$objId
Definition: xapitoken.php:57
$version
Definition: plugin.php:24
+ Here is the call graph for this function:

◆ fetchTemplate()

ilCertificateTemplateDatabaseRepository::fetchTemplate ( int  $templateId)
Exceptions
ilCouldNotFindCertificateTemplate

Implements ilCertificateTemplateRepository.

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

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

92  {
93  $this->logger->debug(sprintf('START - Fetch certificate template with id: "%s"', $templateId));
94 
95  $sql = '
96 SELECT * FROM
97 il_cert_template
98 WHERE id = ' . $this->database->quote($templateId, 'integer') . '
99 ORDER BY version ASC';
100 
101  $query = $this->database->query($sql);
102 
103  while ($row = $this->database->fetchAssoc($query)) {
104  return $this->createCertificateTemplate($row);
105  }
106 
107  throw new ilCouldNotFindCertificateTemplate(sprintf('No template with id "%s" found', $templateId));
108  }
+ Here is the call graph for this function:

◆ isBackgroundImageUsed()

ilCertificateTemplateDatabaseRepository::isBackgroundImageUsed ( string  $relative_image_path)

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

References ILIAS\Repository\logger().

409  : bool
410  {
411  $this->logger->debug(sprintf(
412  'START - Checking if any certificate template uses background image path "%s"',
413  $relative_image_path
414  ));
415 
416  $result = $this->database->queryF(
417  'SELECT EXISTS(SELECT 1 FROM il_cert_template WHERE background_image_path = %s AND currently_active = 1) AS does_exist',
418  ['text'],
419  [$relative_image_path]
420  );
421 
422  $exists = (bool) ($this->database->fetchAssoc($result)['does_exist'] ?? false);
423 
424  $this->logger->debug(sprintf(
425  'END - Image path "%s" is ' . $exists ? "in use" : "unused",
426  $relative_image_path
427  ));
428 
429  return $exists;
430  }
+ Here is the call graph for this function:

◆ save()

ilCertificateTemplateDatabaseRepository::save ( ilCertificateTemplate  $certificateTemplate)

Implements ilCertificateTemplateRepository.

Definition at line 49 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().

49  : void
50  {
51  $this->logger->debug('START - Save new certificate template');
52 
53  $objId = $certificateTemplate->getObjId();
54 
55  $id = $this->database->nextId('il_cert_template');
56 
58 
59  $columns = [
60  'id' => ['integer', $id],
61  'obj_id' => ['integer', $objId],
62  'obj_type' => ['text', $certificateTemplate->getObjType()],
63  'certificate_content' => ['clob', $certificateTemplate->getCertificateContent()],
64  'certificate_hash' => ['text', $certificateTemplate->getCertificateHash()],
65  'template_values' => ['clob', $certificateTemplate->getTemplateValues()],
66  'version' => ['integer', $certificateTemplate->getVersion()],
67  'ilias_version' => ['text', $certificateTemplate->getIliasVersion()],
68  'created_timestamp' => ['integer', $certificateTemplate->getCreatedTimestamp()],
69  'currently_active' => ['integer', (int) $certificateTemplate->isCurrentlyActive()],
70  'background_image_path' => ['text', $certificateTemplate->getBackgroundImagePath()],
71  'deleted' => ['integer', (int) $certificateTemplate->isDeleted()],
72  'thumbnail_image_path' => ['text', $certificateTemplate->getThumbnailImagePath()]
73  ];
74 
75  $this->database->insert('il_cert_template', $columns);
76 
77  $this->logger->debug(sprintf(
78  'END - certificate template saved with columns: %s',
79  json_encode($columns, JSON_THROW_ON_ERROR)
80  ));
81  }
$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 
)

Implements ilCertificateTemplateRepository.

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

References ilCertificateTemplate\getId().

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

◆ updateDefaultBackgroundImagePaths()

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

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

References ILIAS\Repository\logger().

382  : void
383  {
384  $this->logger->debug(sprintf(
385  'START - Update all default background image paths from "%s" to "%s"',
386  $old_relative_path,
387  $new_relative_path
388  ));
389 
390  $affected_rows = $this->database->manipulateF(
391  'UPDATE il_cert_template SET background_image_path = %s WHERE currently_active = 1 AND (background_image_path = %s OR background_image_path = %s )',
392  [
393  'text',
394  'text',
395  'text'
396  ],
397  [
398  $new_relative_path,
399  $old_relative_path,
400  '/certificates/default/background.jpg']
401  );
402 
403  $this->logger->debug(sprintf(
404  'END - Updated %s certificate templates using old path',
405  $affected_rows
406  ));
407  }
+ Here is the call graph for this function:

Field Documentation

◆ $logger

readonly ilLogger ilCertificateTemplateDatabaseRepository::$logger
private

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

Referenced by __construct().

◆ $objectDataCache

readonly ilObjectDataCache ilCertificateTemplateDatabaseRepository::$objectDataCache
private

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

Referenced by __construct().


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