diff --git a/Services/Certificate/classes/Template/Action/Preview/ilCertificateTemplatePreviewAction.php b/Services/Certificate/classes/Template/Action/Preview/ilCertificateTemplatePreviewAction.php index cbb9bb616e5c..b42c4177f55c 100644 --- a/Services/Certificate/classes/Template/Action/Preview/ilCertificateTemplatePreviewAction.php +++ b/Services/Certificate/classes/Template/Action/Preview/ilCertificateTemplatePreviewAction.php @@ -24,6 +24,7 @@ class ilCertificateTemplatePreviewAction /** * @param ilCertificateTemplateRepository $templateRepository * @param ilCertificatePlaceholderValues $placeholderValuesObject + * @param ilLogger|null $logger */ public function __construct( ilCertificateTemplateRepository $templateRepository, @@ -32,6 +33,7 @@ public function __construct( ) { $this->templateRepository = $templateRepository; $this->placeholderValuesObject = $placeholderValuesObject; + if (null === $logger) { global $DIC; $logger = $DIC->logger()->cert(); @@ -43,23 +45,24 @@ public function __construct( * @param int $objectId * @return bool * @throws ilException + * @throws Exception */ public function createPreviewPdf(int $objectId) { + $oldDatePresentationValue = ilDatePresentation::useRelativeDates(); ilDatePresentation::setUseRelativeDates(false); $template = $this->templateRepository->fetchCurrentlyActiveCertificate($objectId); $xslfo = $template->getCertificateContent(); - // render tex as fo graphics - $xslfo = ilMathJax::getInstance() - ->init(ilMathJax::PURPOSE_PDF) - ->setRendering(ilMathJax::RENDER_PNG_AS_FO_FILE) - ->insertLatexImages($xslfo); - try { - $xlsfo = $this->exchangeCertificateVariables($xslfo, $template); + // render tex as fo graphics + $xlsfo = ilMathJax::getInstance() + ->init(ilMathJax::PURPOSE_PDF) + ->setRendering(ilMathJax::RENDER_PNG_AS_FO_FILE) + ->insertLatexImages($xslfo); + $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler') ->ilFO2PDF($xlsfo); @@ -69,14 +72,13 @@ public function createPreviewPdf(int $objectId) 'Certificate.pdf', 'application/pdf' ); - } catch(Exception $e) { - $this->logger->write(__METHOD__.': '.$e->getMessage()); - return false; + ilDatePresentation::setUseRelativeDates($oldDatePresentationValue); + throw $e; } - ilDatePresentation::setUseRelativeDates(true); + ilDatePresentation::setUseRelativeDates($oldDatePresentationValue); } /** diff --git a/Services/Certificate/classes/class.ilCertificateGUI.php b/Services/Certificate/classes/class.ilCertificateGUI.php index eb3075f44408..7724b7f15c99 100644 --- a/Services/Certificate/classes/class.ilCertificateGUI.php +++ b/Services/Certificate/classes/class.ilCertificateGUI.php @@ -200,6 +200,8 @@ public function __construct( $this->access = $DIC['ilAccess']; $this->toolbar = $DIC['ilToolbar']; + $this->lng->loadLanguageModule('cert'); + $this->ref_id = (int)$_GET['ref_id']; $this->placeholderDescriptionObject = $placeholderDescriptionObject; @@ -315,7 +317,12 @@ public function certificateImport() */ public function certificatePreview() { - $this->previewAction->createPreviewPdf($this->objectId); + try { + $this->previewAction->createPreviewPdf($this->objectId); + } catch (Exception $exception) { + ilUtil::sendFailure($this->lng->txt('error_creating_certificate_pdf', true)); + $this->certificateEditor(); + } } /** diff --git a/lang/ilias_de.lang b/lang/ilias_de.lang index d59ebcfc13d3..60101c3d290b 100644 --- a/lang/ilias_de.lang +++ b/lang/ilias_de.lang @@ -14293,3 +14293,4 @@ cert#:#certificate_migration_lastrun_failed#:#Die Migration der Zertifikate ist cert#:#certificate_migration_confirm_started#:#Die Migration wurde gestartet. cert#:#certificate_migration_go#:#Starte Migration badge#:#user_certificates#:#Zertifikate +cert#:#error_creating_certificate_pdf#:#Das Zertifikat konnte nicht erstellt werden. Bitte lassen Sie den Zertifikats-Server durch einen Administrator prüfen. diff --git a/lang/ilias_en.lang b/lang/ilias_en.lang index 17fb7f27c788..e41e1af92821 100644 --- a/lang/ilias_en.lang +++ b/lang/ilias_en.lang @@ -14295,3 +14295,4 @@ cert#:#certificate_migration_lastrun_failed#:#The migration of the certificates cert#:#certificate_migration_confirm_started#:#The migration was started. cert#:#certificate_migration_go#:#Start Migration badge#:#user_certificates#:#Certificates +cert#:#error_creating_certificate_pdf#:#The certificate could not be created. Please contact the administrator to check the certificate server.