19 declare(strict_types=1);
36 if (null === $logger) {
38 $logger = $DIC->logger()->cert();
42 if (null === $objectDataCache) {
44 $objectDataCache = $DIC[
'ilObjDataCache'];
51 $this->
logger->debug(
'START - Save new certificate template');
55 $id = $this->database->nextId(
'il_cert_template');
60 'id' => [
'integer',
$id],
61 'obj_id' => [
'integer',
$objId],
62 'obj_type' => [
'text', $certificateTemplate->
getObjType()],
66 'version' => [
'integer', $certificateTemplate->
getVersion()],
71 'deleted' => [
'integer', (
int) $certificateTemplate->
isDeleted()],
75 $this->database->insert(
'il_cert_template', $columns);
77 $this->
logger->debug(sprintf(
78 'END - certificate template saved with columns: %s',
79 json_encode($columns, JSON_THROW_ON_ERROR)
85 $sql =
'UPDATE il_cert_template SET currently_active = ' . $this->database->quote($currentlyActive,
'integer') .
86 ' WHERE id = ' . $this->database->quote($certificateTemplate->
getId(),
'integer');
88 return $this->database->manipulate($sql);
93 $this->
logger->debug(sprintf(
'START - Fetch certificate template with id: "%s"', $templateId));
98 WHERE id = ' . $this->database->quote($templateId,
'integer') .
' 99 ORDER BY version ASC';
101 $query = $this->database->query($sql);
103 while ($row = $this->database->fetchAssoc($query)) {
115 $this->
logger->debug(sprintf(
'START - Fetch multiple certificate templates for object: "%s"', $objId));
122 WHERE obj_id = ' . $this->database->quote($objId,
'integer') .
' 124 ORDER BY version ASC';
126 $query = $this->database->query($sql);
128 while ($row = $this->database->fetchAssoc($query)) {
132 $this->
logger->debug(sprintf(
133 'END - Fetching of certificate templates for object: "%s" with "%s" results',
143 $this->
logger->debug(sprintf(
'START - Fetch currently active certificate template for object: "%s"', $objId));
145 $this->database->setLimit(1);
148 SELECT * FROM il_cert_template 149 WHERE obj_id = ' . $this->database->quote($objId,
'integer') .
' 154 $query = $this->database->query($sql);
156 while ($row = $this->database->fetchAssoc($query)) {
157 $this->
logger->debug(sprintf(
'END - Found active certificate for: "%s"', $objId));
162 $this->
logger->debug(sprintf(
'END - Found NO active certificate for: "%s"', $objId));
184 $this->
logger->debug(sprintf(
'START - Fetch currently active certificate template for object: "%s"', $objId));
187 SELECT * FROM il_cert_template 188 WHERE obj_id = ' . $this->database->quote($objId,
'integer') .
' 190 AND currently_active = 1 193 $query = $this->database->query($sql);
195 while ($row = $this->database->fetchAssoc($query)) {
196 $this->
logger->debug(sprintf(
'END - Found active certificate for: "%s"', $objId));
206 $this->
logger->debug(sprintf(
'START - Fetch previous active certificate template for object: "%s"', $objId));
225 foreach ($templates as $template) {
226 if ($template->getVersion() >
$version) {
228 $resultTemplate = $template;
232 $this->
logger->debug(sprintf(
'Latest version active certificate template for object: "%s"', $objId));
234 return $resultTemplate;
239 $this->
logger->debug(sprintf(
240 'START - Set deleted flag for certificate template("%s") for object: "%s"',
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');
251 $this->database->manipulate($sql);
253 $this->
logger->debug(sprintf(
254 'END - Deleted flag set fo certificate template("%s") for object: "%s"',
262 $this->
logger->debug(sprintf(
'START - Activate previous certificate template for object: "%s"', $objId));
267 $previousCertificate = null;
268 foreach ($certificates as $certificate) {
269 if (null === $previousCertificate) {
270 $previousCertificate = $certificate;
271 } elseif ($certificate->getVersion() > $previousCertificate->getVersion()) {
272 $previousCertificate = $certificate;
276 $sql =
'UPDATE il_cert_template 277 SET currently_active = 1 278 WHERE id = ' . $this->database->quote($previousCertificate->getId(),
'integer');
280 $this->database->manipulate($sql);
282 $this->
logger->debug(sprintf(
'END - Previous certificate updated for object: "%s"', $objId));
284 return $previousCertificate;
288 bool $isGlobalLpEnabled,
289 ?
int $forRefId = null
292 'START - Fetch all active course certificate templates with disabled learning progress: "%s"' 295 $joinLpSettings =
'';
296 $whereLpSettings =
'';
297 $onSettingsForRefId =
'';
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)',
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}', '$')) ";
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( 317 [$this->database->quote('cert_subitems_', 'text'), 'text'], 318 ['od.obj_id', 'text'] 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(
327 [
'text',
'text',
'integer'],
332 while ($row = $this->database->fetchAssoc($query)) {
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)
349 $this->
logger->debug(sprintf(
'START - Fetch first create certificate template for object: "%s"', $objId));
351 $this->database->setLimit(1, 0);
353 $sql =
'SELECT * FROM il_cert_template 354 WHERE obj_id = ' . $this->database->quote($objId,
'integer') .
' 357 $query = $this->database->query($sql);
359 while ($row = $this->database->fetchAssoc($query)) {
360 $this->
logger->debug(sprintf(
'END - Found first create certificate template for object: "%s"', $objId));
370 $this->
logger->debug(sprintf(
'START - Deactivate previous certificate template for object: "%s"', $objId));
373 UPDATE il_cert_template 374 SET currently_active = 0 375 WHERE obj_id = ' . $this->database->quote($objId,
'integer');
377 $this->database->manipulate($sql);
379 $this->
logger->debug(sprintf(
'END - Certificate template deactivated for object: "%s"', $objId));
384 $this->
logger->debug(sprintf(
385 'START - Update all default background image paths from "%s" to "%s"',
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 )',
400 '/certificates/default/background.jpg']
403 $this->
logger->debug(sprintf(
404 'END - Updated %s certificate templates using old path',
411 $this->
logger->debug(sprintf(
412 'START - Checking if any certificate template uses background image path "%s"',
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',
419 [$relative_image_path]
422 $exists = (bool) ($this->database->fetchAssoc($result)[
'does_exist'] ??
false);
424 $this->
logger->debug(sprintf(
425 'END - Image path "%s" is ' . $exists ?
"in use" :
"unused",
438 (
int) $row[
'obj_id'],
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
fetchCertificateTemplatesByObjId(int $objId)
isBackgroundImageUsed(string $relative_image_path)
fetchTemplate(int $templateId)
fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(bool $isGlobalLpEnabled, ?int $forRefId=null)
updateActivity(ilCertificateTemplate $certificateTemplate, bool $currentlyActive)
readonly ilLogger $logger
createCertificateTemplate(array $row)
readonly ilObjectDataCache $objectDataCache
fetchPreviousCertificate(int $objId)
const LP_MODE_DEACTIVATED
deactivatePreviousTemplates(int $objId)
fetchCurrentlyActiveCertificate(int $objId)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
fetchFirstCreatedTemplate(int $objId)
updateDefaultBackgroundImagePaths(string $old_relative_path, string $new_relative_path)
deleteTemplate(int $templateId, int $objectId)
save(ilCertificateTemplate $certificateTemplate)
__construct(private readonly ilDBInterface $database, ?ilLogger $logger=null, ?ilObjectDataCache $objectDataCache=null)
activatePreviousCertificate(int $objId)
fetchCurrentlyUsedCertificate(int $objId)