19 declare(strict_types=1);
69 private readonly
int $objectId,
70 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->tree = $DIC[
'tree'];
96 $this->
access = $DIC[
'ilAccess'];
97 $this->
toolbar = $DIC[
'ilToolbar'];
101 $this->
lng->loadLanguageModule(
'cert');
102 $this->
lng->loadLanguageModule(
"trac");
104 $this->ref_id = (
int) $DIC->http()->wrapper()->query()->retrieve(
"ref_id", $DIC->refinery()->kindlyTo()->int());
106 $this->
logger = $DIC->logger()->cert();
116 $placeholderDescriptionObject,
117 $DIC->ui()->factory(),
118 $DIC->ui()->renderer()
125 $this->pageFormats = $pageFormats ??
new ilPageFormats($DIC->language());
135 $this->templateRepository,
136 $DIC->filesystem()->web()
139 $this->templateRepository,
140 $placeholderValuesObject
142 $this->fileUpload = $fileUpload ?? $DIC->upload();
144 $this->fileSystem = $fileSystem ?? $DIC->filesystem()->web();
146 $this->certificatePath,
150 $this->certificatePath,
153 $this->tmp_file_system = $tmp_file_system ?? $DIC->filesystem()->temp();
169 $cmd = $this->
ctrl->getCmd();
170 $next_class = $this->
ctrl->getNextClass($this);
175 switch ($next_class) {
176 case 'ilpropertyformgui':
178 $this->
ctrl->forwardCommand($form);
182 $ret = $this->$cmd();
195 $this->certificateEditor();
201 $this->previewAction->createPreviewPdf($this->objectId);
203 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'error_creating_certificate_pdf'));
204 $this->certificateEditor();
216 $this->exportAction->export();
230 $this->backgroundImageDelete->deleteBackgroundImage(null);
231 $this->certificateEditor();
238 $cgui->setFormAction($this->
ctrl->getFormAction($this,
"certificateEditor"));
239 $cgui->setHeaderText($this->
lng->txt(
"certificate_confirm_deletion_text"));
240 $cgui->setCancel($this->
lng->txt(
"no"),
"certificateEditor");
241 $cgui->setConfirm($this->
lng->txt(
"yes"),
"certificateDeleteConfirm");
243 $this->tpl->setContent($cgui->getHTML());
251 $template = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
252 $templateId = $template->getId();
254 $this->deleteAction->delete($templateId, $this->objectId);
255 $this->
ctrl->redirect($this,
"certificateEditor");
271 $form = $this->settingsFormFactory->createForm(
275 $form->setValuesByPost();
277 $request = $DIC->http()->request();
279 $formFields = $request->getParsedBody();
281 $this->tpl->setVariable(
'ADM_CONTENT', $form->getHTML());
283 $this->saveCertificate($form, $formFields, $this->objectId);
297 $this->certificateEditor();
310 $certificateTemplate = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
312 $form = $this->settingsFormFactory->createForm(
318 $formFields[
'active'] = $certificateTemplate->isCurrentlyActive();
320 $form->setValuesByArray($formFields);
335 public function certificateEditor():
void 340 $messageBoxHtml =
'';
341 if ($enabledGlobalLearningProgress) {
342 $objectLearningProgressSettings =
new ilLPObjSettings($this->objectId);
343 $mode = $objectLearningProgressSettings->getMode();
350 $renderer = $DIC->ui()->renderer();
351 $messageBox = $DIC->ui()
354 ->info($this->
lng->txt(
'learning_progress_deactivated'));
356 $messageBoxHtml = $renderer->render($messageBox);
357 $form->clearCommandButtons();
361 $formHtml = $form->getHTML();
363 $this->tpl->setVariable(
"ADM_CONTENT", $messageBoxHtml . $formHtml);
368 $previousCertificateTemplate = $this->templateRepository->fetchPreviousCertificate($objId);
369 $currentVersion = $previousCertificateTemplate->getVersion();
370 $nextVersion = $currentVersion + 1;
372 $backgroundDelete = $this->httpWrapper->post()->has(
"background_delete") && $this->httpWrapper->post()->retrieve(
376 $certificateCardThumbnailImageDelete = $this->httpWrapper->post()->has(
"certificate_card_thumbnail_image_delete") && $this->httpWrapper->post()->retrieve(
377 "certificate_card_thumbnail_image_delete",
381 if ($backgroundDelete) {
382 $this->backgroundImageDelete->deleteBackgroundImage($currentVersion);
387 $this->settingsFormFactory->save($form_fields);
389 $templateValues = $this->placeholderDescriptionObject->getPlaceholderDescriptions();
392 $backgroundImagePath =
'';
393 $temporaryFileName = $_FILES[
'background'][
'tmp_name'];
394 if ($temporaryFileName !==
'') {
396 $backgroundImagePath = $this->backgroundImageUpload->uploadBackgroundImage(
402 $form->
getItemByPostVar(
'background')->setAlert($this->
lng->txt(
"certificate_error_upload_bgimage"));
404 if (!$this->fileSystem->has($backgroundImagePath)) {
405 $form->
getItemByPostVar(
'background')->setAlert($this->
lng->txt(
"certificate_error_upload_bgimage"));
406 $backgroundImagePath =
'';
409 if ($backgroundImagePath ===
'') {
410 if ($backgroundDelete || $previousCertificateTemplate->getBackgroundImagePath() ===
'') {
411 $backgroundImagePath = $this->global_certificate_settings->getDefaultBackgroundImagePath(
true);
413 $backgroundImagePath = $previousCertificateTemplate->getBackgroundImagePath();
418 $cardThumbnailImagePath =
'';
419 $temporaryFileName = $_FILES[
'certificate_card_thumbnail_image'][
'tmp_name'];
420 if ($temporaryFileName !==
'' && $this->fileUpload->hasUploads()) {
422 if (!$this->fileUpload->hasBeenProcessed()) {
423 $this->fileUpload->process();
426 $uploadResults = $this->fileUpload->getResults();
427 $pending_card_file = $form->
getInput(
'certificate_card_thumbnail_image');
428 $cardThumbnailFileName =
'card_thumbnail_image_' . $nextVersion .
'.svg';
429 if (isset($uploadResults[$temporaryFileName])) {
431 $result = $uploadResults[$temporaryFileName];
432 if ($result->isOK()) {
433 $this->fileUpload->moveOneFileTo(
435 $this->certificatePath,
437 $cardThumbnailFileName,
441 $cardThumbnailImagePath = $this->certificatePath . $cardThumbnailFileName;
443 } elseif (!empty($pending_card_file)) {
444 $stream = $this->tmp_file_system->readStream(basename($pending_card_file[
'tmp_name']));
445 $this->fileSystem->writeStream(
446 $this->certificatePath .
'/' . $cardThumbnailFileName,
449 $cardThumbnailImagePath = $this->certificatePath . $cardThumbnailFileName;
451 throw new ilException($this->
lng->txt(
'upload_error_file_not_found'));
454 $form->
getItemByPostVar(
'certificate_card_thumbnail_image')->setAlert($this->
lng->txt(
"certificate_error_upload_ctimage"));
456 if (!$this->fileSystem->has($cardThumbnailImagePath)) {
457 $form->
getItemByPostVar(
'certificate_card_thumbnail_image')->setAlert($this->
lng->txt(
"certificate_error_upload_ctimage"));
458 $cardThumbnailImagePath =
'';
461 if ($cardThumbnailImagePath ===
'' && !$certificateCardThumbnailImageDelete) {
462 $cardThumbnailImagePath = $previousCertificateTemplate->getThumbnailImagePath();
465 $jsonEncodedTemplateValues = json_encode($templateValues, JSON_THROW_ON_ERROR);
467 $xslfo = $this->xlsFoParser->parse($form_fields);
469 $newHashValue =
hash(
473 $backgroundImagePath,
474 $jsonEncodedTemplateValues,
475 $cardThumbnailImagePath
479 $active = (bool) ($form_fields[
'active'] ??
false);
481 if ($newHashValue !== $previousCertificateTemplate->getCertificateHash()) {
487 $jsonEncodedTemplateValues,
492 $backgroundImagePath,
493 $cardThumbnailImagePath
496 $this->templateRepository->save($certificateTemplate);
497 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"saved_successfully"),
true);
498 $this->
ctrl->redirect($this,
"certificateEditor");
501 if ($previousCertificateTemplate->getId() !== null && $previousCertificateTemplate->isCurrentlyActive() !== $active) {
502 $this->templateRepository->updateActivity($previousCertificateTemplate, $active);
503 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'certificate_change_active_status'),
true);
504 $this->
ctrl->redirect($this,
"certificateEditor");
507 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'certificate_same_not_saved'),
true);
508 $this->
ctrl->redirect($this,
"certificateEditor");
510 $this->tpl->setOnScreenMessage(
514 $this->
logger->error($e->getTraceAsString());
520 $this->tpl->setVariable(
"ADM_CONTENT", $form->
getHTML());
526 $format = $this->
settings->get(
'pageformat',
'');
527 $formats = $this->pageFormats->fetchPageFormats();
530 'pageformat' => $format,
531 'pagewidth' => $formats[
'width'] ??
'',
532 'pageheight' => $formats[
'height'] ??
'',
540 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
const ILIAS_VERSION_NUMERIC
Class ChatMainBarProvider .
createFormatArray(ilCertificateTemplate $certificateTemplate)
readonly WrapperFactory $httpWrapper
readonly ilCertificateFormRepository $settingsFormFactory
readonly Filesystem $fileSystem
readonly ilCertificateBackgroundImageDelete $backgroundImageDelete
readonly ilCertificateTemplateExportAction $exportAction
certificateDeleteConfirm()
Deletes the certificate and all its data.
Class ilObjCertificateSettings.
__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, ?ilCertificateBackgroundImageUpload $upload=null, ?ilCertificateTemplatePreviewAction $previewAction=null, ?FileUpload $fileUpload=null, private readonly ilSetting $settings=new ilSetting('certificate'), ?ilCertificateBackgroundImageDelete $backgroundImageDelete=null, ?Filesystem $fileSystem=null, ?ilCertificateBackgroundImageFileService $imageFileService=null, ?Filesystem $tmp_file_system=null)
static _enabledLearningProgress()
readonly FileUpload $fileUpload
certificateExportFO()
Exports the certificate.
GUI class to create PDF certificates.
header include for all ilias files.
readonly string $certificatePath
readonly ilCertificateTemplatePreviewAction $previewAction
certificateRemoveBackground()
readonly Filesystem $tmp_file_system
readonly ilCertificateBackgroundImageUpload $backgroundImageUpload
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
readonly ilLogger $logger
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const LP_MODE_DEACTIVATED
readonly ilCertificateTemplateRepository $templateRepository
readonly ilXlsFoParser $xlsFoParser
final const DEFAULT_MARGIN_BODY_LEFT
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