ILIAS  release_8 Revision v8.24
class.ilCertificateSettingsFormRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27
32{
33 private int $objectId;
49
50 public function __construct(
51 int $objectId,
52 string $certificatePath,
62 ?ilLogger $logger = null,
64 ?Filesystem $filesystem = null,
65 ?ilCertificateBackgroundImageFileService $backgroundImageFileService = null
66 ) {
67 global $DIC;
68 $this->httpWrapper = $DIC->http()->wrapper();
69 $this->page_template = $DIC->ui()->mainTemplate();
70 $this->refinery = $DIC->refinery();
71 $this->objectId = $objectId;
72 $this->language = $language;
73 $this->ctrl = $ctrl;
74 $this->access = $access;
75 $this->toolbar = $toolbar;
76 $this->placeholderDescriptionObject = $placeholderDescriptionObject;
77 $this->hasAdditionalElements = $hasAdditionalElements;
78 $this->global_certificate_settings = new ilObjCertificateSettings();
79
80 $database = $DIC->database();
81
82 if (null === $logger) {
83 $logger = $logger = $DIC->logger()->cert();
84 }
85
86 if (null === $pageFormats) {
88 }
89 $this->pageFormats = $pageFormats;
90
91 if (null === $formFieldParser) {
93 }
94 $this->formFieldParser = $formFieldParser;
95
96 if (null === $importAction) {
99 $certificatePath,
101 $logger,
102 $DIC->filesystem()->web()
103 );
104 }
105 $this->importAction = $importAction;
106
107 if (null === $templateRepository) {
109 }
110 $this->templateRepository = $templateRepository;
111
112 if (null === $filesystem) {
113 $filesystem = $DIC->filesystem()->web();
114 }
115
116 if (null === $backgroundImageFileService) {
117 $backgroundImageFileService = new ilCertificateBackgroundImageFileService(
118 $certificatePath,
119 $filesystem
120 );
121 }
122 $this->backGroundImageFileService = $backgroundImageFileService;
123 }
124
135 public function createForm(ilCertificateGUI $certificateGUI): ilPropertyFormGUI
136 {
137 $certificateTemplate = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
138
139 $command = $this->ctrl->getCmd();
140
141 $form = new ilPropertyFormGUI();
142 $form->setPreventDoubleSubmission(false);
143 $form->setFormAction($this->ctrl->getFormAction($certificateGUI));
144 $form->setTitle($this->language->txt("cert_form_sec_availability"));
145 $form->setMultipart(true);
146 $form->setTableWidth("100%");
147 $form->setId("certificate");
148
149 $active = new ilCheckboxInputGUI($this->language->txt("active"), "active");
150 $form->addItem($active);
151
152 $import = new ilFileInputGUI($this->language->txt("import"), "certificate_import");
153 $import->setRequired(false);
154 $import->setSuffixes(["zip"]);
155
156 // handle the certificate import
157 if (!empty($_FILES["certificate_import"]["name"]) && $import->checkInput()) {
158 $result = $this->importAction->import(
159 $_FILES["certificate_import"]["tmp_name"],
160 $_FILES["certificate_import"]["name"]
161 );
162 if ($result === false) {
163 $this->page_template->setOnScreenMessage(
164 $this->page_template::MESSAGE_TYPE_FAILURE,
165 $this->language->txt('certificate_error_import'),
166 true
167 );
168 $this->ctrl->redirect($certificateGUI, 'certificateEditor');
169 } else {
170 $this->page_template->setOnScreenMessage(
171 $this->page_template::MESSAGE_TYPE_SUCCESS,
172 $this->language->txt('saved_successfully'),
173 true
174 );
175 $this->ctrl->redirect($certificateGUI, 'certificateEditor');
176 }
177 }
178 $form->addItem($import);
179
180 $formSection = new ilFormSectionHeaderGUI();
181 $formSection->setTitle($this->language->txt("cert_form_sec_layout"));
182 $form->addItem($formSection);
183
184 $pageformat = new ilRadioGroupInputGUI($this->language->txt("certificate_page_format"), "pageformat");
185 $pageformats = $this->pageFormats->fetchPageFormats();
186
187 foreach ($pageformats as $format) {
188 $option = new ilRadioOption($format["name"], $format["value"]);
189
190 if (strcmp($format["value"], "custom") === 0) {
191 $pageheight = new ilTextInputGUI($this->language->txt("certificate_pageheight"), "pageheight");
192 $pageheight->setSize(6);
193 $pageheight->setValidationRegexp('/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*)))(cm|mm|in|pt|pc|px|em)$/is');
194 $pageheight->setInfo($this->language->txt("certificate_unit_description"));
195 $pageheight->setRequired(true);
196 $option->addSubItem($pageheight);
197
198 $pagewidth = new ilTextInputGUI($this->language->txt("certificate_pagewidth"), "pagewidth");
199 $pagewidth->setSize(6);
200 $pagewidth->setValidationRegexp('/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*)))(cm|mm|in|pt|pc|px|em)$/is');
201 $pagewidth->setInfo($this->language->txt("certificate_unit_description"));
202 $pagewidth->setRequired(true);
203 $option->addSubItem($pagewidth);
204 }
205
206 $pageformat->addOption($option);
207 }
208
209 $pageformat->setRequired(true);
210
211 if (strcmp($command, "certificateSave") === 0) {
212 $pageformat->checkInput();
213 }
214
215 $form->addItem($pageformat);
216
217 $bgimage = new ilImageFileInputGUI($this->language->txt("certificate_background_image"), "background");
218 $bgimage->setRequired(false);
219 $bgimage->setUseCache(false);
220
221 $bgimage->setAllowDeletion(true);
222 if (!$this->backGroundImageFileService->hasBackgroundImage($certificateTemplate)) {
223 if ($this->global_certificate_settings->hasBackgroundImage()) {
225 $imagePath = ilWACSignedPath::signFile($this->global_certificate_settings->getBackgroundImageThumbPathWeb());
226 $bgimage->setImage($imagePath);
227 $bgimage->setAllowDeletion(false);
228 }
229 } else {
231
232 $thumbnail_path = $this->backGroundImageFileService->getBackgroundImageThumbPath();
233
234 if (!is_file($thumbnail_path)) {
235 //Trying if it uses default image path
236 $thumbnail_path = CLIENT_WEB_DIR . $certificateTemplate->getBackgroundImagePath() . '.thumb.jpg';
237 if (!is_file($thumbnail_path)) {
238 //Trying to use global default image
239 $thumbnail_path = $this->global_certificate_settings->getDefaultBackgroundImageThumbPath();
240 if (!is_file($thumbnail_path)) {
241 //No image global default configured
242 $thumbnail_path = '';
243 }
244 }
245 $bgimage->setALlowDeletion(false);
246 }
247 $imagePath = ilWACSignedPath::signFile($thumbnail_path);
248 $bgimage->setImage($imagePath);
249 }
250
251 $form->addItem($bgimage);
252
253 $thumbnailImage = new ilImageFileInputGUI(
254 $this->language->txt('certificate_card_thumbnail_image'),
255 'certificate_card_thumbnail_image'
256 );
257 $thumbnailImage->setRequired(false);
258 $thumbnailImage->setUseCache(false);
259 $thumbnailImage->setSuffixes(['svg']);
260
261 $allowThumbnailDeletion = false;
262
263 $cardThumbnailImagePath = $certificateTemplate->getThumbnailImagePath();
264 if ('' !== $cardThumbnailImagePath) {
265 $presentationThumbnailImagePath = CLIENT_WEB_DIR . $cardThumbnailImagePath;
266 $thumbnailImage->setImage(ilWACSignedPath::signFile($presentationThumbnailImagePath));
267 $allowThumbnailDeletion = true;
268 }
269
270 $thumbnailImage->setAllowDeletion($allowThumbnailDeletion);
271
272 $form->addItem($thumbnailImage);
273
274 $rect = new ilCSSRectInputGUI($this->language->txt("certificate_margin_body"), "margin_body");
275 $rect->setRequired(true);
276 $rect->setUseUnits(true);
277 $rect->setInfo($this->language->txt("certificate_unit_description"));
278
279 if (strcmp($command, "certificateSave") === 0) {
280 $rect->checkInput();
281 }
282
283 $form->addItem($rect);
284
285 $certificate = new ilTextAreaInputGUI($this->language->txt("certificate_text"), "certificate_text");
286 $certificate->setInfo($this->language->txt('certificate_text_info'));
287 $certificate->removePlugin('ilimgupload');
288 $certificate->setRequired(true);
289 $certificate->setRows(20);
290 $certificate->setCols(80);
291
292 $placeholderHtmlDescription = $this->placeholderDescriptionObject->createPlaceholderHtmlDescription();
293
294 $placeholderDescriptionInHtml = $placeholderHtmlDescription;
295
296 $certificate->setInfo($placeholderDescriptionInHtml);
297
298 $certificate->setUseRte(true, '3.4.7');
299
300 $tags = [
301 "br",
302 "em",
303 "font",
304 "li",
305 "ol",
306 "p",
307 "span",
308 "strong",
309 "u",
310 "ul"
311 ];
312
313 $certificate->setRteTags($tags);
314
315 if (strcmp($command, "certificateSave") === 0) {
316 $certificate->checkInput();
317 }
318
319 $form->addItem($certificate);
320
321 if (true === $this->hasAdditionalElements) {
322 $formSection = new ilFormSectionHeaderGUI();
323 $formSection->setTitle($this->language->txt("cert_form_sec_add_features"));
324 $form->addItem($formSection);
325 }
326
327 if ($this->access->checkAccess(
328 "write",
329 "",
330 $this->httpWrapper->query()->retrieve("ref_id", $this->refinery->kindlyTo()->int())
331 )) {
332 if ($certificateTemplate->isCurrentlyActive()) {
333 $this->toolbar->setFormAction($this->ctrl->getFormAction($certificateGUI));
334
336 $preview->setCaption('certificate_preview');
337 $preview->setCommand('certificatePreview');
338 $this->toolbar->addStickyItem($preview);
339
340 $export = ilSubmitButton::getInstance();
341 $export->setCaption('certificate_export');
342 $export->setCommand('certificateExportFO');
343 $this->toolbar->addButtonInstance($export);
344
345 $delete = ilSubmitButton::getInstance();
346 $delete->setCaption('delete');
347 $delete->setCommand('certificateDelete');
348 $this->toolbar->addButtonInstance($delete);
349 }
350 $form->addCommandButton("certificateSave", $this->language->txt("save"));
351 }
352
353 return $form;
354 }
355
356 public function save(array $formFields): void
357 {
358 }
359
364 public function fetchFormFieldData(string $content): array
365 {
366 return $this->formFieldParser->fetchDefaultFormFields($content);
367 }
368}
Builds data types.
Definition: Factory.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
GUI class to create PDF certificates.
__construct(int $objectId, string $certificatePath, bool $hasAdditionalElements, ilLanguage $language, ilCtrlInterface $ctrl, ilAccess $access, ilToolbarGUI $toolbar, ilCertificatePlaceholderDescription $placeholderDescriptionObject, ?ilPageFormats $pageFormats=null, ?ilFormFieldParser $formFieldParser=null, ?ilCertificateTemplateImportAction $importAction=null, ?ilLogger $logger=null, ?ilCertificateTemplateRepository $templateRepository=null, ?Filesystem $filesystem=null, ?ilCertificateBackgroundImageFileService $backgroundImageFileService=null)
ilCertificatePlaceholderDescription $placeholderDescriptionObject
ilCertificateBackgroundImageFileService $backGroundImageFileService
This class represents a checkbox property in a property form.
This class represents a file property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
Component logger with individual log levels by component id.
Class ilObjCertificateSettings.
This class represents a property form user interface.
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a text area property in a property form.
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static setTokenMaxLifetimeInSeconds(int $token_max_lifetime_in_seconds)
static signFile(string $path_to_file)
const CLIENT_WEB_DIR
Definition: constants.php:47
global $DIC
Definition: feed.php:28
$preview
Definition: imgupload.php:81
Interface Filesystem.
Definition: Filesystem.php:40
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$format
Definition: metadata.php:235
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...