19declare(strict_types=1);
45 if (
null === $objectDataCache) {
54 $this->
logger->debug(
'START - Save new certificate template');
63 'id' => [
'integer',
$id],
64 'obj_id' => [
'integer',
$objId],
65 'obj_type' => [
'text', $certificateTemplate->
getObjType()],
69 'version' => [
'integer', $certificateTemplate->
getVersion()],
73 'deleted' => [
'integer', (
int) $certificateTemplate->
isDeleted()],
78 $this->
database->insert(self::TABLE_NAME, $columns);
82 'END - certificate template saved with columns: %s',
83 json_encode($columns, JSON_THROW_ON_ERROR)
90 $sql =
'UPDATE ' . self::TABLE_NAME .
' SET currently_active = ' . $this->
database->quote(
96 return $this->
database->manipulate($sql);
101 $this->
logger->debug(sprintf(
'START - Fetch certificate template with id: "%s"', $templateId));
105 ' . self::TABLE_NAME .
'
110 $query = $this->
database->query($sql);
112 while ($row = $this->
database->fetchAssoc($query)) {
124 $this->
logger->debug(sprintf(
'START - Fetch multiple certificate templates for object: "%s"',
$objId));
130 self::TABLE_NAME .
' ' .
133 'ORDER BY version ASC'
136 $query = $this->
database->query($sql);
138 while ($row = $this->
database->fetchAssoc($query)) {
144 'END - Fetching of certificate templates for object: "%s" with "%s" results',
155 $this->
logger->debug(sprintf(
'START - Fetch currently active certificate template for object: "%s"',
$objId));
160 SELECT * FROM ' . self::TABLE_NAME .
'
166 $query = $this->
database->query($sql);
168 while ($row = $this->
database->fetchAssoc($query)) {
169 $this->
logger->debug(sprintf(
'END - Found active certificate for: "%s"',
$objId));
174 $this->
logger->debug(sprintf(
'END - Found NO active certificate for: "%s"',
$objId));
196 $this->
logger->debug(sprintf(
'START - Fetch currently active certificate template for object: "%s"',
$objId));
199 SELECT * FROM ' . self::TABLE_NAME .
'
202 AND currently_active = 1
205 $query = $this->
database->query($sql);
207 while ($row = $this->
database->fetchAssoc($query)) {
208 $this->
logger->debug(sprintf(
'END - Found active certificate for: "%s"',
$objId));
218 $this->
logger->debug(sprintf(
'START - Fetch previous active certificate template for object: "%s"',
$objId));
237 foreach ($templates as $template) {
238 if ($template->getVersion() >
$version) {
240 $resultTemplate = $template;
244 $this->
logger->debug(sprintf(
'Latest version active certificate template for object: "%s"',
$objId));
246 return $resultTemplate;
253 'START - Set deleted flag for certificate template("%s") for object: "%s"',
260 UPDATE ' . self::TABLE_NAME .
'
261 SET deleted = 1, currently_active = 0
269 'END - Deleted flag set fo certificate template("%s") for object: "%s"',
278 $this->
logger->debug(sprintf(
'START - Activate previous certificate template for object: "%s"',
$objId));
283 $previousCertificate =
null;
284 foreach ($certificates as $certificate) {
285 if (
null === $previousCertificate) {
286 $previousCertificate = $certificate;
287 } elseif ($certificate->getVersion() > $previousCertificate->getVersion()) {
288 $previousCertificate = $certificate;
292 $sql =
'UPDATE ' . self::TABLE_NAME .
'
293 SET currently_active = 1
298 $this->
logger->debug(sprintf(
'END - Previous certificate updated for object: "%s"',
$objId));
300 return $previousCertificate;
304 bool $isGlobalLpEnabled,
305 ?
int $forRefId =
null
308 'START - Fetch all active course certificate templates with disabled learning progress: "%s"'
311 $joinLpSettings =
'';
312 $whereLpSettings =
'';
313 $onSettingsForRefId =
'';
315 if ($isGlobalLpEnabled) {
316 $joinLpSettings =
'LEFT JOIN ut_lp_settings uls ON uls.obj_id = od.obj_id';
317 $whereLpSettings = sprintf(
318 'AND (uls.u_mode IS NULL OR uls.u_mode = %s)',
323 if (is_int($forRefId)) {
324 $onSettingsForRefId =
" AND settings.value IS NOT NULL AND (JSON_CONTAINS(settings.value, '\"{$forRefId}\"', '$') = 1 OR JSON_CONTAINS(settings.value, '{$forRefId}', '$')) ";
328 SELECT ' . self::TABLE_NAME .
'.*
329 FROM ' . self::TABLE_NAME .
'
330 INNER JOIN object_data od ON od.obj_id = ' . self::TABLE_NAME .
".obj_id
331 INNER JOIN settings ON settings.module = %s AND settings.keyword = {$this->database->concat(
333 [$this->database->quote('cert_subitems_', 'text'), 'text'],
334 ['od.obj_id', 'text']
337 )} $onSettingsForRefId $joinLpSettings
338 WHERE " . self::TABLE_NAME .
'.obj_type = %s
339 AND ' . self::TABLE_NAME .
'.currently_active = %s
340 ' . $whereLpSettings;
343 [
'text',
'text',
'integer'],
348 while ($row = $this->
database->fetchAssoc($query)) {
354 'END - All active course certificate templates with disabled learning progress: "%s"',
355 json_encode($result, JSON_THROW_ON_ERROR)
367 $this->
logger->debug(sprintf(
'START - Fetch first create certificate template for object: "%s"',
$objId));
372 SELECT * FROM ' . self::TABLE_NAME .
'
377 $query = $this->
database->query($sql);
379 while ($row = $this->
database->fetchAssoc($query)) {
380 $this->
logger->debug(sprintf(
'END - Found first create certificate template for object: "%s"',
$objId));
382 return $this->createCertificateTemplate($row);
390 $this->
logger->debug(sprintf(
'START - Deactivate previous certificate template for object: "%s"',
$objId));
393 UPDATE ' . self::TABLE_NAME .
'
394 SET currently_active = 0
399 $this->
logger->debug(sprintf(
'END - Certificate template deactivated for object: "%s"',
$objId));
406 $this->
logger->debug(sprintf(
407 'START - Update all default background image ResourceIdentifications from "%s" to "%s"',
412 $affected_rows = $this->
database->manipulateF(
413 'UPDATE il_cert_template SET background_image_ident = %s WHERE currently_active = 1 AND background_image_ident = %s',
424 $this->
logger->debug(sprintf(
425 'END - Updated %s certificate templates using old ResourceIdentification',
434 'START - Checking if any certificate template uses resource id "%s"',
435 $relative_image_identification
440 'SELECT EXISTS(SELECT 1 FROM ' . self::TABLE_NAME .
' WHERE
441 (background_image_ident = %s OR tile_image_ident = %s)
442 AND currently_active = 1) AS does_exist',
444 [$relative_image_identification, $relative_image_identification]
447 $exists = (bool) ($this->
database->fetchAssoc($result)[
'does_exist'] ??
false);
451 'END - Image identification "%s" is ' . $exists ?
'in use' :
'unused',
452 $relative_image_identification
465 (
int) $row[
'obj_id'],
467 $row[
'certificate_content'],
468 $row[
'certificate_hash'],
469 $row[
'template_values'],
470 (
int) $row[
'version'],
471 $row[
'ilias_version'],
472 (
int) $row[
'created_timestamp'],
473 (
bool) $row[
'currently_active'],
474 (
string) ($row[
'background_image_ident'] ??
''),
475 (
string) ($row[
'tile_image_ident'] ??
''),
476 isset($row[
'id']) ? (
int) $row[
'id'] :
null
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Class ResourceIdentification.
save(ilCertificateTemplate $certificateTemplate)
fetchPreviousCertificate(int $objId)
readonly ilObjectDataCache $objectDataCache
readonly ilLogger $logger
__construct(private readonly ilDBInterface $database, ?ilLogger $logger=null, ?ilObjectDataCache $objectDataCache=null)
fetchCurrentlyUsedCertificate(int $objId)
updateDefaultBackgroundImagePaths(ResourceIdentification|string $new_rid, ResourceIdentification|string $old_rid)
updateActivity(ilCertificateTemplate $certificateTemplate, bool $currentlyActive)
fetchCertificateTemplatesByObjId(int $objId)
fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(bool $isGlobalLpEnabled, ?int $forRefId=null)
isResourceUsed(string $relative_image_identification)
deactivatePreviousTemplates(int $objId)
fetchFirstCreatedTemplate(int $objId)
fetchCurrentlyActiveCertificate(int $objId)
deleteTemplate(int $templateId, int $objectId)
createCertificateTemplate(array $row)
fetchTemplate(int $templateId)
getTileImageIdentification()
getBackgroundImageIdentification()
const LP_MODE_DEACTIVATED
Component logger with individual log levels by component id.
activatePreviousCertificate(int $objId)