19declare(strict_types=1);
45 if (
null === $objectDataCache) {
54 $this->
logger->debug(
'START - Save new certificate template');
58 $id = $this->database->nextId(
'il_cert_template');
63 'id' => [
'integer',
$id],
64 'obj_id' => [
'integer',
$objId],
65 'obj_type' => [
'text', $certificateTemplate->
getObjType()],
69 'version' => [
'integer', $certificateTemplate->
getVersion()],
74 'deleted' => [
'integer', (
int) $certificateTemplate->
isDeleted()],
78 $this->database->insert(
'il_cert_template', $columns);
80 $this->
logger->debug(sprintf(
81 'END - certificate template saved with columns: %s',
82 json_encode($columns, JSON_THROW_ON_ERROR)
88 $sql =
'UPDATE il_cert_template SET currently_active = ' . $this->database->quote($currentlyActive,
'integer') .
89 ' WHERE id = ' . $this->database->quote($certificateTemplate->
getId(),
'integer');
91 return $this->database->manipulate($sql);
101 $this->
logger->debug(sprintf(
'START - Fetch certificate template with id: "%s"', $templateId));
106WHERE id = ' . $this->database->quote($templateId,
'integer') .
'
107ORDER BY version ASC';
109 $query = $this->database->query($sql);
111 while ($row = $this->database->fetchAssoc(
$query)) {
115 throw new ilException(sprintf(
'No template with id "%s" found', $templateId));
124 $this->
logger->debug(sprintf(
'START - Fetch multiple certificate templates for object: "%s"',
$objId));
131WHERE obj_id = ' . $this->database->quote(
$objId,
'integer') .
'
133ORDER BY version ASC';
135 $query = $this->database->query($sql);
137 while ($row = $this->database->fetchAssoc(
$query)) {
141 $this->
logger->debug(sprintf(
142 'END - Fetching of certificate templates for object: "%s" with "%s" results',
152 $this->
logger->debug(sprintf(
'START - Fetch currently active certificate template for object: "%s"',
$objId));
154 $this->database->setLimit(1);
157SELECT * FROM il_cert_template
158WHERE obj_id = ' . $this->database->quote(
$objId,
'integer') .
'
163 $query = $this->database->query($sql);
165 while ($row = $this->database->fetchAssoc(
$query)) {
166 $this->
logger->debug(sprintf(
'END - Found active certificate for: "%s"',
$objId));
171 $this->
logger->debug(sprintf(
'END - Found NO active certificate for: "%s"',
$objId));
175 $this->objectDataCache->lookupType(
$objId),
195 $this->
logger->debug(sprintf(
'START - Fetch currently active certificate template for object: "%s"',
$objId));
198SELECT * FROM il_cert_template
199WHERE obj_id = ' . $this->database->quote(
$objId,
'integer') .
'
201AND currently_active = 1
204 $query = $this->database->query($sql);
206 while ($row = $this->database->fetchAssoc(
$query)) {
207 $this->
logger->debug(sprintf(
'END - Found active certificate for: "%s"',
$objId));
212 throw new ilException((sprintf(
'NO active certificate template found for: "%s"',
$objId)));
217 $this->
logger->debug(sprintf(
'START - Fetch previous active certificate template for object: "%s"',
$objId));
223 $this->objectDataCache->lookupType(
$objId),
236 foreach ($templates as $template) {
237 if ($template->getVersion() >
$version) {
239 $resultTemplate = $template;
243 $this->
logger->debug(sprintf(
'Latest version active certificate template for object: "%s"',
$objId));
245 return $resultTemplate;
250 $this->
logger->debug(sprintf(
251 'START - Set deleted flag for certificate template("%s") for object: "%s"',
257UPDATE il_cert_template
258SET deleted = 1, currently_active = 0
259WHERE id = ' . $this->database->quote($templateId,
'integer') .
'
260AND obj_id = ' . $this->database->quote($objectId,
'integer');
262 $this->database->manipulate($sql);
264 $this->
logger->debug(sprintf(
265 'END - Deleted flag set fo certificate template("%s") for object: "%s"',
273 $this->
logger->debug(sprintf(
'START - Activate previous certificate template for object: "%s"',
$objId));
278 $previousCertificate =
null;
279 foreach ($certificates as $certificate) {
280 if (
null === $previousCertificate) {
281 $previousCertificate = $certificate;
282 } elseif ($certificate->getVersion() > $previousCertificate->getVersion()) {
283 $previousCertificate = $certificate;
287 $sql =
'UPDATE il_cert_template
288SET currently_active = 1
289WHERE id = ' . $this->database->quote($previousCertificate->getId(),
'integer');
291 $this->database->manipulate($sql);
293 $this->
logger->debug(sprintf(
'END - Previous certificate updated for object: "%s"',
$objId));
295 return $previousCertificate;
299 bool $isGlobalLpEnabled,
300 ?
int $forRefId =
null
303 'START - Fetch all active course certificate templates with disabled learning progress: "%s"'
306 $joinLpSettings =
'';
307 $whereLpSettings =
'';
308 $onSettingsForRefId =
'';
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)',
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}', '$')) ";
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(
328 [$this->database->quote('cert_subitems_', 'text'), 'text'],
329 ['od.obj_id', 'text']
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(
338 [
'text',
'text',
'integer'],
343 while ($row = $this->database->fetchAssoc(
$query)) {
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)
362 $this->
logger->debug(sprintf(
'START - Fetch first create certificate template for object: "%s"',
$objId));
364 $this->database->setLimit(1, 0);
366 $sql =
'SELECT * FROM il_cert_template
367WHERE obj_id = ' . $this->database->quote(
$objId,
'integer') .
'
370 $query = $this->database->query($sql);
372 while ($row = $this->database->fetchAssoc(
$query)) {
373 $this->
logger->debug(sprintf(
'END - Found first create certificate template for object: "%s"',
$objId));
375 return $this->createCertificateTemplate($row);
378 throw new ilException(
'No matching template found. MAY missing DBUpdate. Please check if the correct version is installed.');
383 $this->
logger->debug(sprintf(
'START - Deactivate previous certificate template for object: "%s"',
$objId));
386UPDATE il_cert_template
387SET currently_active = 0
388WHERE obj_id = ' . $this->database->quote(
$objId,
'integer');
390 $this->database->manipulate($sql);
392 $this->
logger->debug(sprintf(
'END - Certificate template deactivated for object: "%s"',
$objId));
397 $this->
logger->debug(sprintf(
398 'START - Update all default background image paths from "%s" to "%s"',
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 )',
413 '/certificates/default/background.jpg']
416 $this->
logger->debug(sprintf(
417 'END - Updated %s certificate templates using old path',
424 $this->
logger->debug(sprintf(
425 'START - Checking if any certificate template uses background image path "%s"',
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',
432 [$relative_image_path]
435 $exists = (bool) ($this->database->fetchAssoc($result)[
'does_exist'] ??
false);
437 $this->
logger->debug(sprintf(
438 'END - Image path "%s" is ' . $exists ?
"in use" :
"unused",
452 (
int) $row[
'obj_id'],
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
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
save(ilCertificateTemplate $certificateTemplate)
__construct(ilDBInterface $database, ?ilLogger $logger=null, ?ilObjectDataCache $objectDataCache=null)
fetchPreviousCertificate(int $objId)
isBackgroundImageUsed(string $relative_image_path)
fetchCurrentlyUsedCertificate(int $objId)
updateActivity(ilCertificateTemplate $certificateTemplate, bool $currentlyActive)
fetchCertificateTemplatesByObjId(int $objId)
fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(bool $isGlobalLpEnabled, ?int $forRefId=null)
deactivatePreviousTemplates(int $objId)
fetchFirstCreatedTemplate(int $objId)
fetchCurrentlyActiveCertificate(int $objId)
deleteTemplate(int $templateId, int $objectId)
createCertificateTemplate(array $row)
updateDefaultBackgroundImagePaths(string $old_relative_path, string $new_relative_path)
ilObjectDataCache $objectDataCache
fetchTemplate(int $templateId)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const LP_MODE_DEACTIVATED
Component logger with individual log levels by component id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
activatePreviousCertificate(int $objId)