ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 if (
200 (
201 $this->global_certificate_settings->getBackgroundImageIdentification() instanceof ResourceIdentification &&
202 $bg_image_rid === $this->global_certificate_settings->getBackgroundImageIdentification()->serialize()
203 ) ||
204 !$certificateTemplate->getBackgroundImageIdentification() ||
205 !$this->irss->manage()->find(
206 $certificateTemplate->getBackgroundImageIdentification()
207 ) instanceof ResourceIdentification
208 ) {
209 $identification = $this->global_certificate_settings->getBackgroundImageIdentification();
210 $bgimage->setAllowDeletion(false);
211 } else {
212 $identification = $this->irss->manage()->find($bg_image_rid);
213 }
214 if ($identification instanceof ResourceIdentification) {
215 $background_flavour = $this->irss->flavours()->get(
216 $identification,
217 $this->tile_image_definition
218 );
219 $flavour_urls = $this->irss->consume()->flavourUrls($background_flavour);
220 foreach ($flavour_urls->getURLs(true) as $url) {
222 $bgimage->setImage($url);
223 }
224 }
225
226 $form->addItem($bgimage);
227
228 $tile_image = new ilImageFileInputGUI(
229 $this->language->txt('certificate_card_tile_image'),
230 'certificate_card_tile_image'
231 );
232 $tile_image->setRequired(false);
233 $tile_image->setUseCache(false);
234 $tile_image->setSuffixes(['svg']);
235
236 $allow_tile_image_deletion = false;
237
238 $tile_image_identification = $certificateTemplate->getTileImageIdentification();
239 if ('' !== $tile_image_identification) {
240 $identification = $this->irss->manage()->find($tile_image_identification);
241 if ($identification instanceof ResourceIdentification) {
242 $tile_image->setImage($this->irss->consume()->src($identification)->getSrc(true));
243 $allow_tile_image_deletion = true;
244 }
245 }
246
247 $tile_image->setAllowDeletion($allow_tile_image_deletion);
248
249 $form->addItem($tile_image);
250
251 $rect = new ilCSSRectInputGUI($this->language->txt('certificate_margin_body'), 'margin_body');
252 $rect->setRequired(true);
253 $rect->setUseUnits(true);
254 $rect->setInfo($this->language->txt('certificate_unit_description'));
255
256 if (strcmp($command, 'certificateSave') === 0) {
257 $rect->checkInput();
258 }
259
260 $form->addItem($rect);
261
262 $certificate = new ilTextAreaInputGUI($this->language->txt('certificate_text'), 'certificate_text');
263 $certificate->setRequired(true);
264 $certificate->setRows(20);
265 $certificate->setCols(80);
266
267 $certificate->setInfo(
268 $this->language->txt('certificate_text_info') . $this->placeholderDescriptionObject->createPlaceholderHtmlDescription()
269 );
270
271 $certificate->setUseRte(true, '3.4.7');
272
273 $tags = [
274 'br',
275 'em',
276 'font',
277 'li',
278 'ol',
279 'p',
280 'span',
281 'strong',
282 'u',
283 'ul'
284 ];
285
286 $certificate->setRteTags($tags);
287
288 if (strcmp($command, 'certificateSave') === 0) {
289 $certificate->checkInput();
290 }
291
292 $form->addItem($certificate);
293
294 if ($this->hasAdditionalElements) {
295 $formSection = new ilFormSectionHeaderGUI();
296 $formSection->setTitle($this->language->txt('cert_form_sec_add_features'));
297 $form->addItem($formSection);
298 }
299
300 if ($this->access->checkAccess(
301 'write',
302 '',
303 $this->httpWrapper->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int())
304 )) {
305 if ($certificateTemplate->isCurrentlyActive()) {
306 $preview_button = $this->ui_factory->button()->standard(
307 $this->language->txt('certificate_preview'),
308 $this->ctrl->getLinkTarget($certificateGUI, 'certificatePreview')
309 );
310 $export_button = $this->ui_factory->button()->standard(
311 $this->language->txt('certificate_export'),
312 $this->ctrl->getLinkTarget($certificateGUI, 'certificateExportFO')
313 );
314 $delete_button = $this->ui_factory->button()->standard(
315 $this->language->txt('delete'),
316 $this->ctrl->getLinkTarget($certificateGUI, 'certificateDelete')
317 );
318
319 $this->toolbar->addStickyItem($preview_button);
320 $this->toolbar->addComponent($export_button);
321 $this->toolbar->addComponent($delete_button);
322 }
323 $form->addCommandButton('certificateSave', $this->language->txt('save'));
324 }
325
326 return $form;
327 }
328
329 public function save(array $formFields): void
330 {
331 }
332
336 public function fetchFormFieldData(string $content): array
337 {
338 return $this->formFieldParser->fetchDefaultFormFields($content);
339 }
340}
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...
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