ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCertificateSettingsFormRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26use ILIAS\Refinery\Factory as Refinery;
29use ILIAS\UI\Factory as UiFactory;
30use ILIAS\UI\Renderer as UiRenderer;
32
37{
38 private readonly UiFactory $ui_factory;
39 private readonly ilPageFormats $pageFormats;
42 private readonly WrapperFactory $httpWrapper;
43 private readonly Refinery $refinery;
45 private IRSS $irss;
49
50 public function __construct(
51 private readonly int $objectId,
52 string $certificatePath,
53 private readonly bool $hasAdditionalElements,
54 private readonly ilLanguage $language,
55 private readonly ilCtrlInterface $ctrl,
56 private readonly ilAccessHandler $access,
57 private readonly ilToolbarGUI $toolbar,
58 private readonly ilCertificatePlaceholderDescription $placeholderDescriptionObject,
59 ?UiFactory $ui_factory = null,
60 ?UiRenderer $ui_renderer = null,
62 private readonly ilFormFieldParser $formFieldParser = new ilFormFieldParser(),
64 ?ilLogger $logger = null,
67 ) {
68 global $DIC;
69
70 $this->httpWrapper = $DIC->http()->wrapper();
71 $this->refinery = $DIC->refinery();
72 $this->page_template = $DIC->ui()->mainTemplate();
73
74 $this->ui_factory = $ui_factory ?? $DIC->ui()->factory();
75
76 $this->irss = $DIC->resourceStorage();
77 $this->filesystem = $filesystem ?? $DIC->filesystem()->web();
78
79 $this->pageFormats = $pageFormats ?? new ilPageFormats($language);
80 $this->importAction = $importAction ?? new ilCertificateTemplateImportAction(
81 $objectId,
82 $certificatePath,
83 $placeholderDescriptionObject,
84 $logger ?? $DIC->logger()->cert(),
85 $this->filesystem,
86 $this->irss
87 );
88 $this->templateRepository = $templateRepository ?? new ilCertificateTemplateDatabaseRepository(
89 $DIC->database(),
90 $logger ?? $DIC->logger()->cert()
91 );
92 $this->tile_image_definition = new FitToSquare(
93 true,
94 100
95 );
96 $this->global_certificate_settings = new ilObjCertificateSettings();
97 }
98
107 public function createForm(ilCertificateGUI $certificateGUI): ilPropertyFormGUI
108 {
109 $certificateTemplate = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
110
111 $command = $this->ctrl->getCmd() ?? '';
112
113 $form = new ilPropertyFormGUI();
114 $form->setPreventDoubleSubmission(false);
115 $form->setFormAction($this->ctrl->getFormAction($certificateGUI, 'certificateEditor'));
116 $form->setTitle($this->language->txt('cert_form_sec_availability'));
117 $form->setMultipart(true);
118 $form->setTableWidth('100%');
119 $form->setId('certificate');
120
121 $active = new ilCheckboxInputGUI($this->language->txt('active'), 'active');
122 $form->addItem($active);
123
124 $import = new ilFileInputGUI($this->language->txt('import'), 'certificate_import');
125 $import->setRequired(false);
126 $import->setSuffixes(['zip']);
127
128 // handle the certificate import
129 if (!empty($_FILES['certificate_import']['name']) && $import->checkInput()) {
130 $result = $this->importAction->import(
131 $_FILES['certificate_import']['tmp_name'],
132 $_FILES['certificate_import']['name']
133 );
134 if ($result) {
135 $this->page_template->setOnScreenMessage(
136 $this->page_template::MESSAGE_TYPE_SUCCESS,
137 $this->language->txt('saved_successfully'),
138 true
139 );
140 $this->ctrl->redirect($certificateGUI, 'certificateEditor');
141 } else {
142 $this->page_template->setOnScreenMessage(
143 $this->page_template::MESSAGE_TYPE_FAILURE,
144 $this->language->txt('certificate_error_import'),
145 true
146 );
147 $this->ctrl->redirect($certificateGUI, 'certificateEditor');
148 }
149 }
150 $form->addItem($import);
151
152 $formSection = new ilFormSectionHeaderGUI();
153 $formSection->setTitle($this->language->txt('cert_form_sec_layout'));
154 $form->addItem($formSection);
155
156 $pageformat = new ilRadioGroupInputGUI($this->language->txt('certificate_page_format'), 'pageformat');
157 $pageformats = $this->pageFormats->fetchPageFormats();
158
159 foreach ($pageformats as $format) {
160 $option = new ilRadioOption($format['name'], $format['value']);
161
162 if (strcmp($format['value'], 'custom') === 0) {
163 $pageheight = new ilTextInputGUI($this->language->txt('certificate_pageheight'), 'pageheight');
164 $pageheight->setSize(6);
165 $pageheight->setValidationRegexp(
166 '/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*)))(cm|mm|in|pt|pc|px|em)$/is'
167 );
168 $pageheight->setInfo($this->language->txt('certificate_unit_description'));
169 $pageheight->setRequired(true);
170 $option->addSubItem($pageheight);
171
172 $pagewidth = new ilTextInputGUI($this->language->txt('certificate_pagewidth'), 'pagewidth');
173 $pagewidth->setSize(6);
174 $pagewidth->setValidationRegexp(
175 '/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*)))(cm|mm|in|pt|pc|px|em)$/is'
176 );
177 $pagewidth->setInfo($this->language->txt('certificate_unit_description'));
178 $pagewidth->setRequired(true);
179 $option->addSubItem($pagewidth);
180 }
181
182 $pageformat->addOption($option);
183 }
184
185 $pageformat->setRequired(true);
186
187 if (strcmp($command, 'certificateSave') === 0) {
188 $pageformat->checkInput();
189 }
190
191 $form->addItem($pageformat);
192
193 $bgimage = new ilImageFileInputGUI($this->language->txt('certificate_background_image'), 'background');
194 $bgimage->setRequired(false);
195 $bgimage->setUseCache(false);
196
197 $bgimage->setAllowDeletion(true);
198 $bg_image_rid = $certificateTemplate->getBackgroundImageIdentification();
199 $bg_image_path = $certificateTemplate->getBackgroundImagePath();
200 if (
201 (
202 $this->global_certificate_settings->getBackgroundImageIdentification() instanceof ResourceIdentification &&
203 $bg_image_rid === $this->global_certificate_settings->getBackgroundImageIdentification()->serialize()
204 ) ||
205 !$certificateTemplate->getBackgroundImageIdentification() ||
206 !$this->irss->manage()->find(
207 $certificateTemplate->getBackgroundImageIdentification()
208 ) instanceof ResourceIdentification
209 ) {
210 $identification = $this->global_certificate_settings->getBackgroundImageIdentification();
211 $bgimage->setAllowDeletion(false);
212 } else {
213 $identification = $this->irss->manage()->find($bg_image_rid);
214 }
215 if ($identification instanceof ResourceIdentification) {
216 $background_flavour = $this->irss->flavours()->get(
217 $identification,
218 $this->tile_image_definition
219 );
220 $flavour_urls = $this->irss->consume()->flavourUrls($background_flavour);
221 foreach ($flavour_urls->getURLs(true) as $url) {
223 $bgimage->setImage($url);
224 }
225 } elseif ($bg_image_path !== '' && $this->filesystem->has($bg_image_path)) {
226 $bgimage->setImage(
228 ILIAS_HTTP_PATH . '/' . ILIAS_WEB_DIR . '/' . CLIENT_ID . $bg_image_path
229 )
230 );
231 }
232
233 $form->addItem($bgimage);
234
235 $tile_image = new ilImageFileInputGUI(
236 $this->language->txt('certificate_card_tile_image'),
237 'certificate_card_tile_image'
238 );
239 $tile_image->setRequired(false);
240 $tile_image->setUseCache(false);
241 $tile_image->setSuffixes(['svg']);
242
243 $allow_tile_image_deletion = false;
244
245 $tile_image_identification = $certificateTemplate->getTileImageIdentification();
246 $old_tile_image_path = $certificateTemplate->getTileImagePath();
247 if ('' !== $tile_image_identification) {
248 $identification = $this->irss->manage()->find($tile_image_identification);
249 if ($identification instanceof ResourceIdentification) {
250 $tile_image->setImage($this->irss->consume()->src($identification)->getSrc(true));
251 $allow_tile_image_deletion = true;
252 }
253 } elseif ($old_tile_image_path !== '' && $this->filesystem->has($old_tile_image_path)) {
254 $tile_image->setImage(
256 ILIAS_HTTP_PATH . '/' . ILIAS_WEB_DIR . '/' . CLIENT_ID . $old_tile_image_path
257 )
258 );
259 $allow_tile_image_deletion = true;
260 }
261
262 $tile_image->setAllowDeletion($allow_tile_image_deletion);
263
264 $form->addItem($tile_image);
265
266 $rect = new ilCSSRectInputGUI($this->language->txt('certificate_margin_body'), 'margin_body');
267 $rect->setRequired(true);
268 $rect->setUseUnits(true);
269 $rect->setInfo($this->language->txt('certificate_unit_description'));
270
271 if (strcmp($command, 'certificateSave') === 0) {
272 $rect->checkInput();
273 }
274
275 $form->addItem($rect);
276
277 $certificate = new ilTextAreaInputGUI($this->language->txt('certificate_text'), 'certificate_text');
278 $certificate->setRequired(true);
279 $certificate->setRows(20);
280 $certificate->setCols(80);
281
282 $certificate->setInfo(
283 $this->language->txt('certificate_text_info') . $this->placeholderDescriptionObject->createPlaceholderHtmlDescription()
284 );
285
286 $certificate->setUseRte(true, '3.4.7');
287
288 $tags = [
289 'br',
290 'em',
291 'font',
292 'li',
293 'ol',
294 'p',
295 'span',
296 'strong',
297 'u',
298 'ul'
299 ];
300
301 $certificate->setRteTags($tags);
302
303 if (strcmp($command, 'certificateSave') === 0) {
304 $certificate->checkInput();
305 }
306
307 $form->addItem($certificate);
308
309 if ($this->hasAdditionalElements) {
310 $formSection = new ilFormSectionHeaderGUI();
311 $formSection->setTitle($this->language->txt('cert_form_sec_add_features'));
312 $form->addItem($formSection);
313 }
314
315 if ($this->access->checkAccess(
316 'write',
317 '',
318 $this->httpWrapper->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int())
319 )) {
320 if ($certificateTemplate->isCurrentlyActive()) {
321 $preview_button = $this->ui_factory->button()->standard(
322 $this->language->txt('certificate_preview'),
323 $this->ctrl->getLinkTarget($certificateGUI, 'certificatePreview')
324 );
325 $export_button = $this->ui_factory->button()->standard(
326 $this->language->txt('certificate_export'),
327 $this->ctrl->getLinkTarget($certificateGUI, 'certificateExportFO')
328 );
329 $delete_button = $this->ui_factory->button()->standard(
330 $this->language->txt('delete'),
331 $this->ctrl->getLinkTarget($certificateGUI, 'certificateDelete')
332 );
333
334 $this->toolbar->addStickyItem($preview_button);
335 $this->toolbar->addComponent($export_button);
336 $this->toolbar->addComponent($delete_button);
337 }
338 $form->addCommandButton('certificateSave', $this->language->txt('save'));
339 }
340
341 return $form;
342 }
343
344 public function save(array $formFields): void
345 {
346 }
347
351 public function fetchFormFieldData(string $content): array
352 {
353 return $this->formFieldParser->fetchDefaultFormFields($content);
354 }
355}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Indicates that a file is missing or not found.
Indicates general problems with the input or output operations.
Definition: IOException.php:28
This class represents a text property in a property form.
GUI class to create PDF certificates.
__construct(private readonly int $objectId, string $certificatePath, private readonly bool $hasAdditionalElements, private readonly ilLanguage $language, private readonly ilCtrlInterface $ctrl, private readonly ilAccessHandler $access, private readonly ilToolbarGUI $toolbar, private readonly ilCertificatePlaceholderDescription $placeholderDescriptionObject, ?UiFactory $ui_factory=null, ?UiRenderer $ui_renderer=null, ?ilPageFormats $pageFormats=null, private readonly ilFormFieldParser $formFieldParser=new ilFormFieldParser(), ?ilCertificateTemplateImportAction $importAction=null, ?ilLogger $logger=null, ?ilCertificateTemplateRepository $templateRepository=null, ?Filesystem $filesystem=null)
readonly ilCertificateTemplateImportAction $importAction
readonly ilCertificateTemplateRepository $templateRepository
This class represents a checkbox property in a property form.
This class represents a file property in a property form.
This class represents a section header in a property form.
This class represents an image file property in a property form.
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 class represents an option in a radio group.
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 signFile(string $path_to_file)
const CLIENT_ID
Definition: constants.php:41
const ILIAS_WEB_DIR
Definition: constants.php:45
The filesystem interface provides the public interface for the Filesystem service API consumer.
Definition: Filesystem.php:37
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
createForm(ilCertificateGUI $certificateGUI)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:68