19declare(strict_types=1);
43 if (
null === $objectDataCache) {
52 $this->
logger->debug(
'START - Save new certificate template');
61 'id' => [
'integer',
$id],
62 'obj_id' => [
'integer',
$objId],
63 'obj_type' => [
'text', $certificateTemplate->
getObjType()],
67 'version' => [
'integer', $certificateTemplate->
getVersion()],
71 'deleted' => [
'integer', (
int) $certificateTemplate->
isDeleted()],
76 $this->
database->insert(self::TABLE_NAME, $columns);
80 'END - certificate template saved with columns: %s',
81 json_encode($columns, JSON_THROW_ON_ERROR)
88 $sql =
'UPDATE ' . self::TABLE_NAME .
' SET currently_active = ' . $this->
database->quote(
94 return $this->
database->manipulate($sql);
99 $this->
logger->debug(sprintf(
'START - Fetch certificate template with id: "%s"', $templateId));
103 ' . self::TABLE_NAME .
'
108 $query = $this->
database->query($sql);
110 while ($row = $this->
database->fetchAssoc($query)) {
122 $this->
logger->debug(sprintf(
'START - Fetch multiple certificate templates for object: "%s"',
$objId));
128 self::TABLE_NAME .
' ' .
131 'ORDER BY version ASC'
134 $query = $this->
database->query($sql);
136 while ($row = $this->
database->fetchAssoc($query)) {
142 'END - Fetching of certificate templates for object: "%s" with "%s" results',
153 $this->
logger->debug(sprintf(
'START - Fetch currently active certificate template for object: "%s"',
$objId));
158 SELECT * FROM ' . self::TABLE_NAME .
'
164 $query = $this->
database->query($sql);
166 while ($row = $this->
database->fetchAssoc($query)) {
167 $this->
logger->debug(sprintf(
'END - Found active certificate for: "%s"',
$objId));
172 $this->
logger->debug(sprintf(
'END - Found NO active certificate for: "%s"',
$objId));
194 $this->
logger->debug(sprintf(
'START - Fetch currently active certificate template for object: "%s"',
$objId));
197 SELECT * FROM ' . self::TABLE_NAME .
'
200 AND currently_active = 1
203 $query = $this->
database->query($sql);
205 while ($row = $this->
database->fetchAssoc($query)) {
206 $this->
logger->debug(sprintf(
'END - Found active certificate for: "%s"',
$objId));
216 $this->
logger->debug(sprintf(
'START - Fetch previous active certificate template for object: "%s"',
$objId));
235 foreach ($templates as $template) {
236 if ($template->getVersion() >
$version) {
238 $resultTemplate = $template;
242 $this->
logger->debug(sprintf(
'Latest version active certificate template for object: "%s"',
$objId));
244 return $resultTemplate;
251 'START - Set deleted flag for certificate template("%s") for object: "%s"',
258 UPDATE ' . self::TABLE_NAME .
'
259 SET deleted = 1, currently_active = 0
267 'END - Deleted flag set fo certificate template("%s") for object: "%s"',
276 $this->
logger->debug(sprintf(
'START - Activate previous certificate template for object: "%s"',
$objId));
281 $previousCertificate =
null;
282 foreach ($certificates as $certificate) {
283 if (
null === $previousCertificate) {
284 $previousCertificate = $certificate;
285 } elseif ($certificate->getVersion() > $previousCertificate->getVersion()) {
286 $previousCertificate = $certificate;
290 $sql =
'UPDATE ' . self::TABLE_NAME .
'
291 SET currently_active = 1
296 $this->
logger->debug(sprintf(
'END - Previous certificate updated for object: "%s"',
$objId));
298 return $previousCertificate;
302 bool $isGlobalLpEnabled,
303 ?
int $forRefId =
null
306 'START - Fetch all active course certificate templates with disabled learning progress: "%s"'
309 $joinLpSettings =
'';
310 $whereLpSettings =
'';
311 $onSettingsForRefId =
'';
313 if ($isGlobalLpEnabled) {
314 $joinLpSettings =
'LEFT JOIN ut_lp_settings uls ON uls.obj_id = od.obj_id';
315 $whereLpSettings = sprintf(
316 'AND (uls.u_mode IS NULL OR uls.u_mode = %s)',
321 if (is_int($forRefId)) {
322 $onSettingsForRefId =
" AND settings.value IS NOT NULL AND (JSON_CONTAINS(settings.value, '\"{$forRefId}\"', '$') = 1 OR JSON_CONTAINS(settings.value, '{$forRefId}', '$')) ";
326 SELECT ' . self::TABLE_NAME .
'.*
327 FROM ' . self::TABLE_NAME .
'
328 INNER JOIN object_data od ON od.obj_id = ' . self::TABLE_NAME .
".obj_id
329 INNER JOIN settings ON settings.module = %s AND settings.keyword = {$this->database->concat(
331 [$this->database->quote('cert_subitems_', 'text'), 'text'],
332 ['od.obj_id', 'text']
335 )} $onSettingsForRefId $joinLpSettings
336 WHERE " . self::TABLE_NAME .
'.obj_type = %s
337 AND ' . self::TABLE_NAME .
'.currently_active = %s
338 ' . $whereLpSettings;
341 [
'text',
'text',
'integer'],
346 while ($row = $this->
database->fetchAssoc($query)) {
352 'END - All active course certificate templates with disabled learning progress: "%s"',
353 json_encode($result, JSON_THROW_ON_ERROR)
365 $this->
logger->debug(sprintf(
'START - Fetch first create certificate template for object: "%s"',
$objId));
370 SELECT * FROM ' . self::TABLE_NAME .
'
375 $query = $this->
database->query($sql);
377 while ($row = $this->
database->fetchAssoc($query)) {
378 $this->
logger->debug(sprintf(
'END - Found first create certificate template for object: "%s"',
$objId));
380 return $this->createCertificateTemplate($row);
388 $this->
logger->debug(sprintf(
'START - Deactivate previous certificate template for object: "%s"',
$objId));
391 UPDATE ' . self::TABLE_NAME .
'
392 SET currently_active = 0
397 $this->
logger->debug(sprintf(
'END - Certificate template deactivated for object: "%s"',
$objId));
404 'START - Checking if any certificate template uses resource id "%s"',
405 $relative_image_identification
410 'SELECT EXISTS(SELECT 1 FROM ' . self::TABLE_NAME .
' WHERE
411 (background_image_ident = %s OR tile_image_ident = %s)
412 AND currently_active = 1) AS does_exist',
414 [$relative_image_identification, $relative_image_identification]
417 $exists = (bool) ($this->
database->fetchAssoc($result)[
'does_exist'] ??
false);
421 'END - Image identification "%s" is ' . $exists ?
'in use' :
'unused',
422 $relative_image_identification
435 (
int) $row[
'obj_id'],
437 $row[
'certificate_content'],
438 $row[
'certificate_hash'],
439 $row[
'template_values'],
440 (
int) $row[
'version'],
441 $row[
'ilias_version'],
442 (
int) $row[
'created_timestamp'],
443 (
bool) $row[
'currently_active'],
444 (
string) ($row[
'background_image_ident'] ??
''),
445 (
string) ($row[
'tile_image_ident'] ??
''),
446 isset($row[
'id']) ? (
int) $row[
'id'] :
null
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
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)
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)