From 0bd343702d830deb455b3cd8d6e00b1be7d26aa5 Mon Sep 17 00:00:00 2001 From: Niels Theen Date: Mon, 17 Sep 2018 17:03:42 +0200 Subject: [PATCH 1/2] Add error message on deactivated ilServer --- .../ilCertificateTemplatePreviewAction.php | 33 ++++++++++++------- .../classes/class.ilCertificateGUI.php | 9 ++++- lang/ilias_de.lang | 1 + lang/ilias_en.lang | 1 + 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Services/Certificate/classes/Template/Action/Preview/ilCertificateTemplatePreviewAction.php b/Services/Certificate/classes/Template/Action/Preview/ilCertificateTemplatePreviewAction.php index cbb9bb616e5c..162de8127ea8 100644 --- a/Services/Certificate/classes/Template/Action/Preview/ilCertificateTemplatePreviewAction.php +++ b/Services/Certificate/classes/Template/Action/Preview/ilCertificateTemplatePreviewAction.php @@ -21,17 +21,26 @@ class ilCertificateTemplatePreviewAction */ private $logger; + /** + * @var ilLanguage|null + */ + private $language; + /** * @param ilCertificateTemplateRepository $templateRepository * @param ilCertificatePlaceholderValues $placeholderValuesObject + * @param ilLogger|null $logger + * @param ilLanguage|null $language */ public function __construct( ilCertificateTemplateRepository $templateRepository, ilCertificatePlaceholderValues $placeholderValuesObject, - ilLogger $logger = null + ilLogger $logger = null, + ilLanguage $language = null ) { $this->templateRepository = $templateRepository; $this->placeholderValuesObject = $placeholderValuesObject; + if (null === $logger) { global $DIC; $logger = $DIC->logger()->cert(); @@ -43,23 +52,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 +79,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. From e767230b8018e221d8268bfd9e94651874f2fe19 Mon Sep 17 00:00:00 2001 From: Niels Theen Date: Mon, 17 Sep 2018 17:05:36 +0200 Subject: [PATCH 2/2] Remove unused variable --- .../Preview/ilCertificateTemplatePreviewAction.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Services/Certificate/classes/Template/Action/Preview/ilCertificateTemplatePreviewAction.php b/Services/Certificate/classes/Template/Action/Preview/ilCertificateTemplatePreviewAction.php index 162de8127ea8..b42c4177f55c 100644 --- a/Services/Certificate/classes/Template/Action/Preview/ilCertificateTemplatePreviewAction.php +++ b/Services/Certificate/classes/Template/Action/Preview/ilCertificateTemplatePreviewAction.php @@ -21,22 +21,15 @@ class ilCertificateTemplatePreviewAction */ private $logger; - /** - * @var ilLanguage|null - */ - private $language; - /** * @param ilCertificateTemplateRepository $templateRepository * @param ilCertificatePlaceholderValues $placeholderValuesObject * @param ilLogger|null $logger - * @param ilLanguage|null $language */ public function __construct( ilCertificateTemplateRepository $templateRepository, ilCertificatePlaceholderValues $placeholderValuesObject, - ilLogger $logger = null, - ilLanguage $language = null + ilLogger $logger = null ) { $this->templateRepository = $templateRepository; $this->placeholderValuesObject = $placeholderValuesObject;