ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilCertificateTemplatePreviewAction.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8{
13
18
22 private $logger;
23
27 private $user;
28
32 private $utilHelper;
33
38
43
48
53
65 public function __construct(
68 ilLogger $logger = null,
69 ilObjUser $user = null,
74 string $rootDirectory = CLIENT_WEB_DIR
75 ) {
76 $this->templateRepository = $templateRepository;
77 $this->placeholderValuesObject = $placeholderValuesObject;
78
79 if (null === $logger) {
80 global $DIC;
81 $logger = $DIC->logger()->cert();
82 }
83 $this->logger = $logger;
84
85 if (null === $user) {
86 global $DIC;
87 $user = $DIC->user();
88 }
89 $this->user = $user;
90
91 if (null === $utilHelper) {
93 }
94 $this->utilHelper = $utilHelper;
95
96 if (null === $mathJaxHelper) {
98 }
99 $this->mathJaxHelper = $mathJaxHelper;
100
101 if (null === $userDefinedFieldsHelper) {
103 }
104 $this->userDefinedFieldsHelper = $userDefinedFieldsHelper;
105
106 if (null === $rpcClientFactoryHelper) {
108 }
109 $this->rpcClientFactoryHelper = $rpcClientFactoryHelper;
110
111 $this->rootDirectory = $rootDirectory;
112 }
113
120 public function createPreviewPdf(int $objectId)
121 {
122 $template = $this->templateRepository->fetchCurrentlyUsedCertificate($objectId);
123
124 $xslfo = $template->getCertificateContent();
125
126 $xslfo = $this->exchangeCertificateVariables($xslfo, $template, $objectId);
127
128 try {
129 // render tex as fo graphics
130 $xlsfo = $this->mathJaxHelper->fillXlsFoContent($xslfo);
131
132 $pdf_base64 = $this->rpcClientFactoryHelper
133 ->ilFO2PDF('RPCTransformationHandler', $xlsfo);
134
135 $this->utilHelper->deliverData(
136 $pdf_base64->scalar,
137 'Certificate.pdf',
138 'application/pdf'
139 );
140 } catch (Exception $e) {
141 throw $e;
142 }
143 }
144
154 string $certificate_text,
156 int $objectId
157 ) {
158 $insert_tags = $this->placeholderValuesObject->getPlaceholderValuesForPreview($this->user->getId(), $objectId);
159
160 foreach ($this->getCustomCertificateFields() as $key => $value) {
161 $insert_tags[$value['ph']] = $this->utilHelper->prepareFormOutput($value['name']);
162 }
163
164 foreach ($insert_tags as $placeholderVariable => $value) {
165 $certificate_text = str_replace('[' . $placeholderVariable . ']', $value, $certificate_text);
166 }
167
168 $certificate_text = str_replace(
169 '[CLIENT_WEB_DIR]',
170 $this->rootDirectory,
171 $certificate_text
172 );
173
174 $backgroundImagePath = $template->getBackgroundImagePath();
175
176 $certificate_text = str_replace(
177 '[BACKGROUND_IMAGE]',
178 $this->rootDirectory . $backgroundImagePath,
179 $certificate_text
180 );
181
182 return $certificate_text;
183 }
184
190 private function getCustomCertificateFields()
191 {
192 $user_field_definitions = $this->userDefinedFieldsHelper->createInstance();
193 $fds = $user_field_definitions->getDefinitions();
194
195 $fields = array();
196 foreach ($fds as $f) {
197 if ($f['certificate']) {
198 $fields[$f['field_id']] = array(
199 'name' => $f['field_name'],
200 'ph' => '[#' . str_replace(' ', '_', strtoupper($f['field_name'])) . ']');
201 }
202 }
203
204 return $fields;
205 }
206}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
exchangeCertificateVariables(string $certificate_text, ilCertificateTemplate $template, int $objectId)
Exchanges the variables in the certificate text with given values.
__construct(ilCertificateTemplateRepository $templateRepository, ilCertificatePlaceholderValues $placeholderValuesObject, ilLogger $logger=null, ilObjUser $user=null, ilCertificateUtilHelper $utilHelper=null, ilCertificateMathJaxHelper $mathJaxHelper=null, ilCertificateUserDefinedFieldsHelper $userDefinedFieldsHelper=null, ilCertificateRpcClientFactoryHelper $rpcClientFactoryHelper=null, string $rootDirectory=CLIENT_WEB_DIR)
getCustomCertificateFields()
Get custom certificate fields.
Just a wrapper class to create Unit Test for other classes.
Component logger with individual log levels by component id.
$template
$key
Definition: croninfo.php:18
global $DIC
Definition: saml.php:7