58 $this->logger->info(
'START - Save new certificate template');
62 $id = $this->database->nextId(
'il_cert_template');
67 'id' => array(
'integer', $id),
68 'obj_id' => array(
'integer',
$objId),
69 'obj_type' => array(
'text', $certificateTemplate->
getObjType()),
73 'version' => array(
'integer', $certificateTemplate->
getVersion()),
74 'ilias_version' => array(
'text', $certificateTemplate->
getIliasVersion()),
76 'currently_active' => array(
'integer', (integer) $certificateTemplate->
isCurrentlyActive()),
78 'deleted' => array(
'integer', (integer) $certificateTemplate->
isDeleted()),
82 $this->database->insert(
'il_cert_template',
$columns);
84 $this->logger->info(
'END - certificate template saved with columns: ', json_encode(
$columns));
90 $sql =
'UPDATE il_cert_template SET currently_active = ' . $this->database->quote($currentlyActive,
'integer') .
91 ' WHERE id = ' . $this->database->quote($certificateTemplate->
getId(),
'integer');
93 return $this->database->manipulate($sql);
98 $this->logger->info(sprintf(
'START - Fetch certificate template with id: "%s"', $templateId));
103WHERE id = ' . $this->database->quote($templateId,
'integer') .
'
104ORDER BY version ASC';
106 $query = $this->database->query($sql);
108 while ($row = $this->database->fetchAssoc(
$query)) {
112 throw new ilException(sprintf(
'No template with id "%s" found', $templateId));
121 $this->logger->info(sprintf(
'START - Fetch multiple certificate templates for object: "%s"',
$objId));
128WHERE obj_id = ' . $this->database->quote(
$objId,
'integer') .
'
130ORDER BY version ASC';
132 $query = $this->database->query($sql);
134 while ($row = $this->database->fetchAssoc(
$query)) {
138 $this->logger->info(sprintf(
'END - Fetching of certificate templates for object: "%s" with "%s" results',
$objId, count(
$result)));
149 $this->logger->info(sprintf(
'START - Fetch currently active certificate template for object: "%s"',
$objId));
151 $this->database->setLimit(1);
154SELECT * FROM il_cert_template
155WHERE obj_id = ' . $this->database->quote(
$objId,
'integer') .
'
160 $query = $this->database->query($sql);
162 while ($row = $this->database->fetchAssoc(
$query)) {
163 $this->logger->info(sprintf(
'END - Found active certificate for: "%s"',
$objId));
168 $this->logger->info(sprintf(
'END - Found NO active certificate for: "%s"',
$objId));
172 $this->objectDataCache->lookUpType(
$objId),
192 $this->logger->info(sprintf(
'START - Fetch currently active certificate template for object: "%s"',
$objId));
195SELECT * FROM il_cert_template
196WHERE obj_id = ' . $this->database->quote(
$objId,
'integer') .
'
198AND currently_active = 1
201 $query = $this->database->query($sql);
203 while ($row = $this->database->fetchAssoc(
$query)) {
204 $this->logger->info(sprintf(
'END - Found active certificate for: "%s"',
$objId));
209 throw new ilException((sprintf(
'NO active certificate template found for: "%s"',
$objId)));
220 $this->logger->info(sprintf(
'START - Fetch previous active certificate template for object: "%s"',
$objId));
226 $this->objectDataCache->lookUpType(
$objId),
239 foreach ($templates as $template) {
240 if ($template->getVersion() > $version) {
241 $version = $template->getVersion();
242 $resultTemplate = $template;
246 $this->logger->info(sprintf(
'Latest version active certificate template for object: "%s"',
$objId));
248 return $resultTemplate;
258 $this->logger->info(sprintf(
'START - Set deleted flag for certificate template("%s") for object: "%s"', $templateId, $objectId));
261UPDATE il_cert_template
262SET deleted = 1, currently_active = 0
263WHERE id = ' . $this->database->quote($templateId,
'integer') .
'
264AND obj_id = ' . $this->database->quote($objectId,
'integer');
266 $this->database->manipulate($sql);
268 $this->logger->info(sprintf(
'END - Deleted flag set fo certificate template("%s") for object: "%s"', $templateId, $objectId));
278 $this->logger->info(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 ((
int) $certificate->getVersion() > (
int) $previousCertificate->getVersion()) {
288 $previousCertificate = $certificate;
292 $sql =
'UPDATE il_cert_template
293SET currently_active = 1
294WHERE id = ' . $this->database->quote($previousCertificate->getId(),
'integer');
296 $this->database->manipulate($sql);
298 $this->logger->info(sprintf(
'END - Previous certificate updated for object: "%s"',
$objId));
300 return $previousCertificate;
309 $this->logger->info(sprintf(
'START - Fetch all active certificate templates for object type: "%s"',
$type));
312 SELECT il_cert_template.* FROM il_cert_template
313 INNER JOIN object_data od ON od.obj_id = il_cert_template.obj_id
314 WHERE obj_type = ' . $this->database->quote(
$type,
'text') .
'
315 AND currently_active = 1
317 $query = $this->database->query($sql);
320 while ($row = $this->database->fetchAssoc(
$query)) {
324 $this->logger->info(sprintf(
'END - All certificate templates for object type: "%s": "%s"',
$type, json_encode(
$result)));
336 $this->logger->info(sprintf(
'START - Fetch first create certificate template for object: "%s"',
$objId));
338 $this->database->setLimit(1, 0);
340 $sql =
'SELECT * FROM il_cert_template
341WHERE obj_id = ' . $this->database->quote(
$objId,
'integer') .
'
344 $query = $this->database->query($sql);
346 while ($row = $this->database->fetchAssoc(
$query)) {
347 $this->logger->info(sprintf(
'END - Found first create certificate template for object: "%s"',
$objId));
352 throw new ilException(
'No matching template found. MAY missing DBUpdate. Please check if the correct version is installed.');
361 $this->logger->info(sprintf(
'START - Deactivate previous certificate template for object: "%s"',
$objId));
364UPDATE il_cert_template
365SET currently_active = 0
366WHERE obj_id = ' . $this->database->quote(
$objId,
'integer');
368 $this->database->manipulate($sql);
370 $this->logger->info(sprintf(
'END - Certificate template deactivated for object: "%s"',
$objId));
382 $row[
'certificate_content'],
383 $row[
'certificate_hash'],
384 $row[
'template_values'],
386 $row[
'ilias_version'],
387 $row[
'created_timestamp'],
388 (
boolean) $row[
'currently_active'],
389 $row[
'background_image_path'],
390 $row[
'thumbnail_image_path'],
An exception for terminatinating execution or to throw for unit testing.
fetchCurrentlyActiveCertificate(int $objId)
deleteTemplate(int $templateId, int $objectId)
fetchCurrentlyUsedCertificate(int $objId)
fetchPreviousCertificate(int $objId)
Fetch latest created certificate EVEN IF it is deleted.
fetchFirstCreatedTemplate(int $objId)
fetchActiveTemplatesByType(string $type)
__construct(\ilDBInterface $database, \ilLogger $logger=null, \ilObjectDataCache $objectDataCache=null)
fetchCertificateTemplatesByObjId(int $objId)
createCertificateTemplate(array $row)
save(ilCertificateTemplate $certificateTemplate)
deactivatePreviousTemplates(int $objId)
updateActivity(ilCertificateTemplate $certificateTemplate, bool $currentlyActive)
fetchTemplate(int $templateId)
Base class for ILIAS Exception handling.
Component logger with individual log levels by component id.