19 declare(strict_types=1);
72 private readonly
int $objectId,
73 string $certificatePath,
88 $this->httpWrapper = $DIC->http()->wrapper();
90 $this->
lng = $DIC[
'lng'];
91 $this->tpl = $DIC[
'tpl'];
92 $this->
ctrl = $DIC[
'ilCtrl'];
93 $this->
ilias = $DIC[
'ilias'];
95 $this->irss = $DIC->resourceStorage();
98 $this->tree = $DIC[
'tree'];
99 $this->
access = $DIC[
'ilAccess'];
100 $this->
toolbar = $DIC[
'ilToolbar'];
103 $this->
lng->loadLanguageModule(
'certificate');
104 $this->
lng->loadLanguageModule(
'cert');
105 $this->
lng->loadLanguageModule(
'trac');
107 $this->ref_id = (
int) $DIC->http()->wrapper()->query()->retrieve(
'ref_id', $DIC->refinery()->kindlyTo()->int());
109 $this->
logger = $DIC->logger()->cert();
119 $placeholderDescriptionObject,
120 $DIC->ui()->factory(),
121 $DIC->ui()->renderer()
128 $this->pageFormats = $pageFormats ??
new ilPageFormats($DIC->language());
133 $this->templateRepository,
137 $this->templateRepository,
138 $placeholderValuesObject,
141 $this->fileUpload = $fileUpload ?? $DIC->upload();
142 $this->file_system = $file_system ?? $DIC->filesystem()->web();
143 $this->database = $DIC->database();
158 $cmd = $this->
ctrl->getCmd();
159 $next_class = $this->
ctrl->getNextClass($this);
164 switch ($next_class) {
165 case 'ilpropertyformgui':
167 $this->
ctrl->forwardCommand($form);
171 $ret = $this->$cmd();
186 $this->certificateEditor();
192 $this->previewAction->createPreviewPdf($this->objectId);
194 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'error_creating_certificate_pdf'));
195 $this->certificateEditor();
207 $this->exportAction->export();
214 $cgui->setFormAction($this->
ctrl->getFormAction($this,
'certificateEditor'));
215 $cgui->setHeaderText($this->
lng->txt(
'certificate_confirm_deletion_text'));
216 $cgui->setCancel($this->
lng->txt(
'no'),
'certificateEditor');
217 $cgui->setConfirm($this->
lng->txt(
'yes'),
'certificateDeleteConfirm');
219 $this->tpl->setContent($cgui->getHTML());
227 $template = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
228 $templateId = $template->getId();
230 $this->deleteAction->delete($templateId, $this->objectId);
231 $this->
ctrl->redirect($this,
'certificateEditor');
247 $form = $this->settingsFormFactory->createForm(
251 $form->setValuesByPost();
253 $request = $DIC->http()->request();
255 $formFields = $request->getParsedBody();
257 $this->tpl->setVariable(
'ADM_CONTENT', $form->getHTML());
273 $this->certificateEditor();
286 public function certificateEditor():
void 291 $messageBoxHtml =
'';
292 if ($enabledGlobalLearningProgress) {
293 $objectLearningProgressSettings =
new ilLPObjSettings($this->objectId);
294 $mode = $objectLearningProgressSettings->getMode();
302 $messageBox = $DIC->ui()
305 ->info($this->
lng->txt(
'learning_progress_deactivated'))
308 $messageBoxHtml =
$renderer->render($messageBox);
309 $form->clearCommandButtons();
313 $formHtml = $form->getHTML();
315 $this->tpl->setVariable(
'ADM_CONTENT', $messageBoxHtml . $formHtml);
328 $certificateTemplate = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
330 $form = $this->settingsFormFactory->createForm(
336 $formFields[
'active'] = $certificateTemplate->isCurrentlyActive();
338 $form->setValuesByArray($formFields);
349 $this->global_certificate_settings,
352 $current_template = $this->templateRepository->fetchPreviousCertificate($objId);
353 $currentVersion = $current_template->getVersion();
354 $nextVersion = $currentVersion + 1;
355 $current_background_rid = $this->irss->manageContainer()->find(
356 $current_template->getBackgroundImageIdentification()
358 $current_tile_image_rid = $this->irss->manageContainer()->find(
359 $current_template->getTileImageIdentification()
361 $old_background_image = $current_background_rid ===
null 362 ? $current_template->getBackgroundImagePath() :
364 $old_tile_image = $current_tile_image_rid ===
null 365 ? $current_template->getTileImagePath() :
368 $should_delete_background =
369 $this->httpWrapper->post()->retrieve(
372 $this->refinery->kindlyTo()->bool(),
376 $should_delete_tile_image =
377 $this->httpWrapper->post()->retrieve(
378 'certificate_card_tile_image_delete',
380 $this->refinery->kindlyTo()->bool(),
385 $new_background_rid = $current_background_rid && !$should_delete_background ? $current_background_rid :
386 $this->global_certificate_settings->getBackgroundImageIdentification();
388 is_string($new_background_rid) &&
389 is_string($this->global_certificate_settings->getBackgroundImageIdentification()) &&
390 $new_background_rid === $this->global_certificate_settings->getBackgroundImageIdentification()
392 if ($this->file_system->has($new_background_rid)) {
393 $new_background_rid = $this->irss->manage()->stream(
394 $this->file_system->readStream($new_background_rid),
398 $old_background_image = $new_background_rid;
399 $new_background_rid =
null;
403 $new_tile_rid = !$should_delete_tile_image ? $current_tile_image_rid :
null;
406 $this->settingsFormFactory->save($form_fields);
408 $templateValues = $this->placeholderDescriptionObject->getPlaceholderDescriptions();
410 if ($this->fileUpload->hasUploads()) {
411 if (!$this->fileUpload->hasBeenProcessed()) {
412 $this->fileUpload->process();
414 $new_background = $form->
getInput(
'background')[
'tmp_name'] ??
'';
415 $new_tile_image = $form->
getInput(
'certificate_card_tile_image')[
'tmp_name'] ??
'';
416 $results = $this->fileUpload->getResults();
418 if ($new_background !==
'') {
419 $new_background_rid = $this->irss->manage()->upload(
425 if ($new_tile_image !==
'') {
426 $new_tile_rid = $this->irss->manage()->upload(
433 $jsonEncodedTemplateValues = json_encode($templateValues, JSON_THROW_ON_ERROR);
435 if (isset($new_background_rid)) {
436 $old_background_image =
'';
438 if (isset($new_tile_rid)) {
439 $old_tile_image =
'';
442 $xslfo = $this->xlsFoParser->parse($form_fields);
443 $newHashValue =
hash(
447 isset($new_background_rid) ? $new_background_rid->serialize() :
'',
448 $jsonEncodedTemplateValues,
449 isset($new_tile_rid) ? $new_background_rid->serialize() :
'',
450 $old_background_image, $old_tile_image
454 $active = (bool) ($form_fields[
'active'] ??
false);
456 if ($newHashValue !== $current_template->getCertificateHash()) {
462 $jsonEncodedTemplateValues,
467 $old_background_image,
469 isset($new_background_rid) ? $new_background_rid->serialize() :
'',
470 isset($new_tile_rid) ? $new_tile_rid->serialize() :
'',
472 $this->templateRepository->save($certificateTemplate);
475 $certificate_handler->handleResourceChange($current_background_rid);
477 if ($current_tile_image_rid instanceof ResourceIdentification) {
478 $certificate_handler->handleResourceChange($current_tile_image_rid);
481 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'),
true);
482 $this->
ctrl->redirect($this,
'certificateEditor');
486 $current_template->getId() !==
null &&
487 $current_template->isCurrentlyActive() !== $active
489 $this->templateRepository->updateActivity($current_template, $active);
490 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'certificate_change_active_status'),
true);
491 $this->
ctrl->redirect($this,
'certificateEditor');
494 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'certificate_same_not_saved'),
true);
495 $this->
ctrl->redirect($this,
'certificateEditor');
497 $this->tpl->setOnScreenMessage(
501 $this->
logger->error($e->getTraceAsString());
507 $this->tpl->setVariable(
'ADM_CONTENT', $form->
getHTML());
513 $format = $this->
settings->get(
'pageformat',
'');
514 $formats = $this->pageFormats->fetchPageFormats();
517 'pageformat' => $format,
518 'pagewidth' => $formats[
'width'] ??
'',
519 'pageheight' => $formats[
'height'] ??
'',
528 return $this->settingsFormFactory->fetchFormFieldData($certificateTemplate->
getCertificateContent());
certificateSave()
Saves the certificate.
final const DEFAULT_MARGIN_BODY_TOP
readonly ilPageFormats $pageFormats
final const DEFAULT_MARGIN_BODY_RIGHT
readonly ilDBInterface $database
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilCertificateTemplateStakeholder $stakeholder
Interface Observer Contains several chained tasks and infos about them.
createFormatArray(ilCertificateTemplate $certificateTemplate)
readonly Filesystem $file_system
readonly WrapperFactory $httpWrapper
readonly ilCertificateFormRepository $settingsFormFactory
readonly ilCertificateTemplateExportAction $exportAction
certificateDeleteConfirm()
Deletes the certificate and all its data.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static _enabledLearningProgress()
const ILIAS_VERSION_NUMERIC
readonly FileUpload $fileUpload
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
certificateExportFO()
Exports the certificate.
Class ResourceIdentification.
Class ilObjForumAdministration.
readonly string $certificatePath
readonly ilCertificateTemplatePreviewAction $previewAction
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
readonly ilLogger $logger
const LP_MODE_DEACTIVATED
saveCertificate(ilPropertyFormGUI $form, array $form_fields, int $objId)
ilCertificateTemplateDatabaseRepository $certificate_repo
readonly ilCertificateTemplateRepository $templateRepository
readonly ilXlsFoParser $xlsFoParser
final const DEFAULT_MARGIN_BODY_LEFT
__construct(private readonly ilCertificatePlaceholderDescription $placeholderDescriptionObject, ilCertificatePlaceholderValues $placeholderValuesObject, private readonly int $objectId, string $certificatePath, ?ilCertificateFormRepository $settingsFormFactory=null, ?ilCertificateDeleteAction $deleteAction=null, ?ilCertificateTemplateRepository $templateRepository=null, ?ilPageFormats $pageFormats=null, ?ilXlsFoParser $xlsFoParser=null, ?ilCertificateTemplateExportAction $exportAction=null, ?ilCertificateTemplatePreviewAction $previewAction=null, ?FileUpload $fileUpload=null, private readonly ilSetting $settings=new ilSetting('certificate'), ?Filesystem $file_system=null, ?Filesystem $tmp_file_system=null)
readonly ilCertificateDeleteAction $deleteAction
static _lookupType(int $id, bool $reference=false)
readonly ilObjCertificateSettings $global_certificate_settings
final const DEFAULT_MARGIN_BODY_BOTTOM
readonly Factory $refinery
ilGlobalPageTemplate $tpl