19 declare(strict_types=1);
73 string $certificatePath,
90 $this->httpWrapper = $DIC->http()->wrapper();
92 $this->
lng = $DIC[
'lng'];
93 $this->tpl = $DIC[
'tpl'];
94 $this->
ctrl = $DIC[
'ilCtrl'];
95 $this->
ilias = $DIC[
'ilias'];
97 $this->tree = $DIC[
'tree'];
98 $this->
access = $DIC[
'ilAccess'];
99 $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());
113 $this->
logger = $DIC->logger()->cert();
115 if (null === $settingsFormFactory) {
124 $placeholderDescriptionObject
129 if (null === $templateRepository) {
134 if (null === $deleteAction) {
139 if (null === $pageFormats) {
144 if (null === $xlsFoParser) {
149 if (null === $upload) {
157 $this->backgroundImageUpload = $upload;
159 if (null === $exportAction) {
163 $this->templateRepository,
164 $DIC->filesystem()->web()
169 if (null === $previewAction) {
174 if (null === $fileUpload) {
176 $fileUpload = $DIC->upload();
182 if (null === $settings) {
183 $settings =
new ilSetting(
'certificate');
187 if (null === $fileSystem) {
188 $fileSystem = $DIC->filesystem()->web();
192 if (null === $imageFileService) {
194 $this->certificatePath,
199 if (null === $backgroundImageDelete) {
201 $this->certificatePath,
207 if (null === $tmp_file_system) {
208 $tmp_file_system = $DIC->filesystem()->temp();
225 $cmd = $this->
ctrl->getCmd();
226 $next_class = $this->
ctrl->getNextClass($this);
231 switch ($next_class) {
232 case 'ilpropertyformgui':
234 $this->
ctrl->forwardCommand($form);
238 $ret = $this->$cmd();
251 $this->certificateEditor();
257 $this->previewAction->createPreviewPdf($this->objectId);
259 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'error_creating_certificate_pdf'));
260 $this->certificateEditor();
272 $this->exportAction->export();
286 $this->backgroundImageDelete->deleteBackgroundImage(null);
287 $this->certificateEditor();
294 $cgui->setFormAction($this->
ctrl->getFormAction($this,
"certificateEditor"));
295 $cgui->setHeaderText($this->
lng->txt(
"certificate_confirm_deletion_text"));
296 $cgui->setCancel($this->
lng->txt(
"no"),
"certificateEditor");
297 $cgui->setConfirm($this->
lng->txt(
"yes"),
"certificateDeleteConfirm");
299 $this->tpl->setContent($cgui->getHTML());
307 $template = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
308 $templateId = $template->getId();
310 $this->deleteAction->delete($templateId, $this->objectId);
311 $this->
ctrl->redirect($this,
"certificateEditor");
327 $form = $this->settingsFormFactory->createForm(
331 $form->setValuesByPost();
333 $request = $DIC->http()->request();
335 $formFields = $request->getParsedBody();
337 $this->tpl->setVariable(
'ADM_CONTENT', $form->getHTML());
339 $this->saveCertificate($form, $formFields, $this->objectId);
353 $this->certificateEditor();
367 $certificateTemplate = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
369 $form = $this->settingsFormFactory->createForm(
375 $formFields[
'active'] = $certificateTemplate->isCurrentlyActive();
377 $form->setValuesByArray($formFields);
392 public function certificateEditor():
void 397 $messageBoxHtml =
'';
398 if ($enabledGlobalLearningProgress) {
399 $objectLearningProgressSettings =
new ilLPObjSettings($this->objectId);
400 $mode = $objectLearningProgressSettings->getMode();
407 $renderer = $DIC->ui()->renderer();
408 $messageBox = $DIC->ui()
411 ->info($this->
lng->txt(
'learning_progress_deactivated'));
413 $messageBoxHtml = $renderer->render($messageBox);
414 $form->clearCommandButtons();
418 $formHtml = $form->getHTML();
420 $this->tpl->setVariable(
"ADM_CONTENT", $messageBoxHtml . $formHtml);
425 $previousCertificateTemplate = $this->templateRepository->fetchPreviousCertificate(
$objId);
426 $currentVersion = $previousCertificateTemplate->getVersion();
427 $nextVersion = $currentVersion + 1;
429 $backgroundDelete = $this->httpWrapper->post()->has(
"background_delete") && $this->httpWrapper->post()->retrieve(
433 $certificateCardThumbnailImageDelete = $this->httpWrapper->post()->has(
"certificate_card_thumbnail_image_delete") && $this->httpWrapper->post()->retrieve(
434 "certificate_card_thumbnail_image_delete",
438 if ($backgroundDelete) {
439 $this->backgroundImageDelete->deleteBackgroundImage($currentVersion);
444 $this->settingsFormFactory->save($form_fields);
446 $templateValues = $this->placeholderDescriptionObject->getPlaceholderDescriptions();
449 $backgroundImagePath =
'';
450 $temporaryFileName = $_FILES[
'background'][
'tmp_name'];
451 if ($temporaryFileName !==
'') {
453 $backgroundImagePath = $this->backgroundImageUpload->uploadBackgroundImage(
459 $form->
getItemByPostVar(
'background')->setAlert($this->
lng->txt(
"certificate_error_upload_bgimage"));
461 if (
false === $this->fileSystem->has($backgroundImagePath)) {
462 $form->
getItemByPostVar(
'background')->setAlert($this->
lng->txt(
"certificate_error_upload_bgimage"));
463 $backgroundImagePath =
'';
466 if ($backgroundImagePath ===
'') {
467 if ($backgroundDelete || $previousCertificateTemplate->getBackgroundImagePath() ===
'') {
468 $backgroundImagePath = $this->global_certificate_settings->getDefaultBackgroundImagePath(
true);
471 $backgroundImagePath = $previousCertificateTemplate->getBackgroundImagePath();
476 $cardThumbnailImagePath =
'';
477 $temporaryFileName = $_FILES[
'certificate_card_thumbnail_image'][
'tmp_name'];
478 if ($temporaryFileName !==
'' && $this->fileUpload->hasUploads()) {
480 if (
false === $this->fileUpload->hasBeenProcessed()) {
481 $this->fileUpload->process();
484 $uploadResults = $this->fileUpload->getResults();
485 $pending_card_file = $form->
getInput(
'certificate_card_thumbnail_image');
486 $cardThumbnailFileName =
'card_thumbnail_image_' . $nextVersion .
'.svg';
487 if (isset($uploadResults[$temporaryFileName])) {
489 $result = $uploadResults[$temporaryFileName];
490 if ($result->isOK()) {
491 $this->fileUpload->moveOneFileTo(
493 $this->certificatePath,
495 $cardThumbnailFileName,
499 $cardThumbnailImagePath = $this->certificatePath . $cardThumbnailFileName;
501 } elseif (!empty($pending_card_file)) {
502 $stream = $this->tmp_file_system->readStream(basename($pending_card_file[
'tmp_name']));
503 $this->fileSystem->writeStream(
504 $this->certificatePath .
'/' . $cardThumbnailFileName,
507 $cardThumbnailImagePath = $this->certificatePath . $cardThumbnailFileName;
509 throw new ilException($this->
lng->txt(
'upload_error_file_not_found'));
512 $form->
getItemByPostVar(
'certificate_card_thumbnail_image')->setAlert($this->
lng->txt(
"certificate_error_upload_ctimage"));
514 if (
false === $this->fileSystem->has($cardThumbnailImagePath)) {
515 $form->
getItemByPostVar(
'certificate_card_thumbnail_image')->setAlert($this->
lng->txt(
"certificate_error_upload_ctimage"));
516 $cardThumbnailImagePath =
'';
519 if ($cardThumbnailImagePath ===
'' && !$certificateCardThumbnailImageDelete) {
520 $cardThumbnailImagePath = $previousCertificateTemplate->getThumbnailImagePath();
523 $jsonEncodedTemplateValues = json_encode($templateValues, JSON_THROW_ON_ERROR);
525 $xslfo = $this->xlsFoParser->parse($form_fields);
527 $newHashValue =
hash(
531 $backgroundImagePath,
532 $jsonEncodedTemplateValues,
533 $cardThumbnailImagePath
537 $active = (bool) ($form_fields[
'active'] ??
false);
539 if ($newHashValue !== $previousCertificateTemplate->getCertificateHash()) {
545 $jsonEncodedTemplateValues,
550 $backgroundImagePath,
551 $cardThumbnailImagePath
554 $this->templateRepository->save($certificateTemplate);
555 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"saved_successfully"),
true);
556 $this->
ctrl->redirect($this,
"certificateEditor");
559 if ($previousCertificateTemplate->getId() !== null && $previousCertificateTemplate->isCurrentlyActive() !== $active) {
560 $this->templateRepository->updateActivity($previousCertificateTemplate, $active);
561 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'certificate_change_active_status'),
true);
562 $this->
ctrl->redirect($this,
"certificateEditor");
565 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'certificate_same_not_saved'),
true);
566 $this->
ctrl->redirect($this,
"certificateEditor");
568 $this->tpl->setOnScreenMessage(
572 $this->
logger->error($e->getTraceAsString());
578 $this->tpl->setVariable(
"ADM_CONTENT", $form->
getHTML());
583 $form_fields = $this->settingsFormFactory->fetchFormFieldData($certificate->
getCertificateContent());
588 $this->tpl->setVariable(
"ADM_CONTENT", $form->
getHTML());
595 $formats = $this->pageFormats->fetchPageFormats();
599 'pagewidth' =>
$formats[
'width'] ??
'',
600 'pageheight' =>
$formats[
'height'] ??
'',
608 return $this->settingsFormFactory->fetchFormFieldData($certificateTemplate->
getCertificateContent());
certificateSave()
Saves the certificate.
ilCertificateTemplateRepository $templateRepository
const ILIAS_VERSION_NUMERIC
ilPageFormats $pageFormats
const DEFAULT_MARGIN_BODY_TOP
Class ChatMainBarProvider .
const DEFAULT_MARGIN_BODY_LEFT
createFormatArray(ilCertificateTemplate $certificateTemplate)
Filesystem $tmp_file_system
certificateDeleteConfirm()
Deletes the certificate and all its data.
Class ilObjCertificateSettings.
ilCertificateBackgroundImageUpload $backgroundImageUpload
static _enabledLearningProgress()
certificateExportFO()
Exports the certificate.
ilCertificateTemplatePreviewAction $previewAction
WrapperFactory $httpWrapper
__construct(ilCertificatePlaceholderDescription $placeholderDescriptionObject, ilCertificatePlaceholderValues $placeholderValuesObject, 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, ?ilSetting $settings=null, ?ilCertificateBackgroundImageDelete $backgroundImageDelete=null, ?Filesystem $fileSystem=null, ?ilCertificateBackgroundImageFileService $imageFileService=null, ?Filesystem $tmp_file_system=null)
ilCertificateFormRepository $settingsFormFactory
GUI class to create PDF certificates.
header include for all ilias files.
ilXlsFoParser $xlsFoParser
certificateRemoveBackground()
const DEFAULT_MARGIN_BODY_BOTTOM
ilObjCertificateSettings $global_certificate_settings
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
ilCertificateDeleteAction $deleteAction
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const LP_MODE_DEACTIVATED
ilCertificateTemplateExportAction $exportAction
ilCertificateBackgroundImageDelete $backgroundImageDelete
setTemplateContent(ilCertificateTemplate $certificate, ilPropertyFormGUI $form)
const DEFAULT_MARGIN_BODY_RIGHT
ilCertificatePlaceholderDescription $placeholderDescriptionObject
static _lookupType(int $id, bool $reference=false)
ilGlobalPageTemplate $tpl
Class FlySystemFileAccessTest disabled disabled disabled.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...