Skip to content

Commit

Permalink
Merge branch 'preview-error-message' into 'trunk'
Browse files Browse the repository at this point in the history
Preview error message

Closes ILIAS-eLearning#24

See merge request ntheen/ilias-certificates!153
  • Loading branch information
mjansenDatabay committed Sep 17, 2018
2 parents 9d0121e + e767230 commit 9d42442
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ilCertificateTemplatePreviewAction
/**
* @param ilCertificateTemplateRepository $templateRepository
* @param ilCertificatePlaceholderValues $placeholderValuesObject
* @param ilLogger|null $logger
*/
public function __construct(
ilCertificateTemplateRepository $templateRepository,
Expand All @@ -32,6 +33,7 @@ public function __construct(
) {
$this->templateRepository = $templateRepository;
$this->placeholderValuesObject = $placeholderValuesObject;

if (null === $logger) {
global $DIC;
$logger = $DIC->logger()->cert();
Expand All @@ -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);
Expand All @@ -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);
}

/**
Expand Down
9 changes: 8 additions & 1 deletion Services/Certificate/classes/class.ilCertificateGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 9d42442

Please sign in to comment.