ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilCertificateSettingsFormRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 
34 {
35  private readonly UiFactory $ui_factory;
36  private readonly UiRenderer $ui_renderer;
37  private readonly ilPageFormats $pageFormats;
41  private readonly WrapperFactory $httpWrapper;
42  private readonly Refinery $refinery;
45 
46  public function __construct(
47  private readonly int $objectId,
48  string $certificatePath,
49  private readonly bool $hasAdditionalElements,
50  private readonly ilLanguage $language,
51  private readonly ilCtrlInterface $ctrl,
52  private readonly ilAccessHandler $access,
53  private readonly ilToolbarGUI $toolbar,
54  private readonly ilCertificatePlaceholderDescription $placeholderDescriptionObject,
55  ?UiFactory $ui_factory = null,
56  ?UiRenderer $ui_renderer = null,
57  ?ilPageFormats $pageFormats = null,
58  private readonly ilFormFieldParser $formFieldParser = new ilFormFieldParser(),
59  ?ilCertificateTemplateImportAction $importAction = null,
60  ?ilLogger $logger = null,
61  ?ilCertificateTemplateRepository $templateRepository = null,
62  ?Filesystem $filesystem = null,
63  ?ilCertificateBackgroundImageFileService $backgroundImageFileService = null
64  ) {
65  global $DIC;
66 
67  $this->httpWrapper = $DIC->http()->wrapper();
68  $this->refinery = $DIC->refinery();
69  $this->page_template = $DIC->ui()->mainTemplate();
70 
71  $this->ui_factory = $ui_factory ?? $DIC->ui()->factory();
72  $this->ui_renderer = $ui_renderer ?? $DIC->ui()->renderer();
73  $this->pageFormats = $pageFormats ?? new ilPageFormats($language);
74  $this->importAction = $importAction ?? new ilCertificateTemplateImportAction(
75  $objectId,
76  $certificatePath,
77  $placeholderDescriptionObject,
78  ($logger ?? $DIC->logger()->cert()),
79  $DIC->filesystem()->web()
80  );
81  $this->templateRepository = $templateRepository ?? new ilCertificateTemplateDatabaseRepository(
82  $DIC->database(),
83  ($logger ?? $DIC->logger()->cert())
84  );
85  $this->backGroundImageFileService = $backgroundImageFileService ?? new ilCertificateBackgroundImageFileService(
86  $certificatePath,
87  ($filesystem ?? $DIC->filesystem()->web())
88  );
89 
90  $this->global_certificate_settings = new ilObjCertificateSettings();
91  }
92 
101  public function createForm(ilCertificateGUI $certificateGUI): ilPropertyFormGUI
102  {
103  $certificateTemplate = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
104 
105  $command = $this->ctrl->getCmd();
106 
107  $form = new ilPropertyFormGUI();
108  $form->setPreventDoubleSubmission(false);
109  $form->setFormAction($this->ctrl->getFormAction($certificateGUI));
110  $form->setTitle($this->language->txt('cert_form_sec_availability'));
111  $form->setMultipart(true);
112  $form->setTableWidth('100%');
113  $form->setId('certificate');
114 
115  $active = new ilCheckboxInputGUI($this->language->txt('active'), 'active');
116  $form->addItem($active);
117 
118  $import = new ilFileInputGUI($this->language->txt('import'), 'certificate_import');
119  $import->setRequired(false);
120  $import->setSuffixes(['zip']);
121 
122  // handle the certificate import
123  if (!empty($_FILES['certificate_import']['name']) && $import->checkInput()) {
124  $result = $this->importAction->import(
125  $_FILES['certificate_import']['tmp_name'],
126  $_FILES['certificate_import']['name']
127  );
128  if ($result) {
129  $this->page_template->setOnScreenMessage(
130  $this->page_template::MESSAGE_TYPE_SUCCESS,
131  $this->language->txt('saved_successfully'),
132  true
133  );
134  $this->ctrl->redirect($certificateGUI, 'certificateEditor');
135  } else {
136  $this->page_template->setOnScreenMessage(
137  $this->page_template::MESSAGE_TYPE_FAILURE,
138  $this->language->txt('certificate_error_import'),
139  true
140  );
141  $this->ctrl->redirect($certificateGUI, 'certificateEditor');
142  }
143  }
144  $form->addItem($import);
145 
146  $formSection = new ilFormSectionHeaderGUI();
147  $formSection->setTitle($this->language->txt('cert_form_sec_layout'));
148  $form->addItem($formSection);
149 
150  $pageformat = new ilRadioGroupInputGUI($this->language->txt("certificate_page_format"), "pageformat");
151  $pageformats = $this->pageFormats->fetchPageFormats();
152 
153  foreach ($pageformats as $format) {
154  $option = new ilRadioOption($format["name"], $format["value"]);
155 
156  if (strcmp($format["value"], "custom") === 0) {
157  $pageheight = new ilTextInputGUI($this->language->txt("certificate_pageheight"), "pageheight");
158  $pageheight->setSize(6);
159  $pageheight->setValidationRegexp('/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*)))(cm|mm|in|pt|pc|px|em)$/is');
160  $pageheight->setInfo($this->language->txt("certificate_unit_description"));
161  $pageheight->setRequired(true);
162  $option->addSubItem($pageheight);
163 
164  $pagewidth = new ilTextInputGUI($this->language->txt("certificate_pagewidth"), "pagewidth");
165  $pagewidth->setSize(6);
166  $pagewidth->setValidationRegexp('/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*)))(cm|mm|in|pt|pc|px|em)$/is');
167  $pagewidth->setInfo($this->language->txt("certificate_unit_description"));
168  $pagewidth->setRequired(true);
169  $option->addSubItem($pagewidth);
170  }
171 
172  $pageformat->addOption($option);
173  }
174 
175  $pageformat->setRequired(true);
176 
177  if (strcmp($command, 'certificateSave') === 0) {
178  $pageformat->checkInput();
179  }
180 
181  $form->addItem($pageformat);
182 
183  $bgimage = new ilImageFileInputGUI($this->language->txt('certificate_background_image'), 'background');
184  $bgimage->setRequired(false);
185  $bgimage->setUseCache(false);
186 
187  $bgimage->setAllowDeletion(true);
188  if (!$this->backGroundImageFileService->hasBackgroundImage($certificateTemplate)) {
189  if ($this->global_certificate_settings->hasBackgroundImage()) {
191  $imagePath = ilWACSignedPath::signFile($this->global_certificate_settings->getBackgroundImageThumbPathWeb());
192  $bgimage->setImage($imagePath);
193  $bgimage->setAllowDeletion(false);
194  }
195  } else {
197 
198  $thumbnail_path = $this->backGroundImageFileService->getBackgroundImageThumbPath();
199 
200  if (!is_file($thumbnail_path)) {
201  //Trying if it uses default image path
202  $thumbnail_path = CLIENT_WEB_DIR . $certificateTemplate->getBackgroundImagePath() . '.thumb.jpg';
203  if (!is_file($thumbnail_path)) {
204  //Trying to use global default image
205  $thumbnail_path = $this->global_certificate_settings->getDefaultBackgroundImageThumbPath();
206  if (!is_file($thumbnail_path)) {
207  //No image global default configured
208  $thumbnail_path = '';
209  }
210  }
211  $bgimage->setALlowDeletion(false);
212  }
213  $imagePath = ilWACSignedPath::signFile($thumbnail_path);
214  $bgimage->setImage($imagePath);
215  }
216 
217  $form->addItem($bgimage);
218 
219  $thumbnailImage = new ilImageFileInputGUI(
220  $this->language->txt('certificate_card_thumbnail_image'),
221  'certificate_card_thumbnail_image'
222  );
223  $thumbnailImage->setRequired(false);
224  $thumbnailImage->setUseCache(false);
225  $thumbnailImage->setSuffixes(['svg']);
226 
227  $allowThumbnailDeletion = false;
228 
229  $cardThumbnailImagePath = $certificateTemplate->getThumbnailImagePath();
230  if ('' !== $cardThumbnailImagePath) {
231  $presentationThumbnailImagePath = CLIENT_WEB_DIR . $cardThumbnailImagePath;
232  $thumbnailImage->setImage(ilWACSignedPath::signFile($presentationThumbnailImagePath));
233  $allowThumbnailDeletion = true;
234  }
235 
236  $thumbnailImage->setAllowDeletion($allowThumbnailDeletion);
237 
238  $form->addItem($thumbnailImage);
239 
240  $rect = new ilCSSRectInputGUI($this->language->txt('certificate_margin_body'), 'margin_body');
241  $rect->setRequired(true);
242  $rect->setUseUnits(true);
243  $rect->setInfo($this->language->txt('certificate_unit_description'));
244 
245  if (strcmp($command, 'certificateSave') === 0) {
246  $rect->checkInput();
247  }
248 
249  $form->addItem($rect);
250 
251  $certificate = new ilTextAreaInputGUI($this->language->txt('certificate_text'), 'certificate_text');
252  $certificate->removePlugin('ilimgupload');
253  $certificate->setRequired(true);
254  $certificate->setRows(20);
255  $certificate->setCols(80);
256 
257  $certificate->setInfo(
258  $this->language->txt('certificate_text_info') . $this->placeholderDescriptionObject->createPlaceholderHtmlDescription()
259  );
260 
261  $certificate->setUseRte(true, '3.4.7');
262 
263  $tags = [
264  'br',
265  'em',
266  'font',
267  'li',
268  'ol',
269  'p',
270  'span',
271  'strong',
272  'u',
273  'ul'
274  ];
275 
276  $certificate->setRteTags($tags);
277 
278  if (strcmp($command, 'certificateSave') === 0) {
279  $certificate->checkInput();
280  }
281 
282  $form->addItem($certificate);
283 
284  if ($this->hasAdditionalElements) {
285  $formSection = new ilFormSectionHeaderGUI();
286  $formSection->setTitle($this->language->txt('cert_form_sec_add_features'));
287  $form->addItem($formSection);
288  }
289 
290  if ($this->access->checkAccess(
291  'write',
292  '',
293  $this->httpWrapper->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int())
294  )) {
295  if ($certificateTemplate->isCurrentlyActive()) {
296  $preview_button = $this->ui_factory->button()->standard(
297  $this->language->txt('certificate_preview'),
298  $this->ctrl->getLinkTarget($certificateGUI, 'certificatePreview')
299  );
300  $export_button = $this->ui_factory->button()->standard(
301  $this->language->txt('certificate_export'),
302  $this->ctrl->getLinkTarget($certificateGUI, 'certificateExportFO')
303  );
304  $delete_button = $this->ui_factory->button()->standard(
305  $this->language->txt('delete'),
306  $this->ctrl->getLinkTarget($certificateGUI, 'certificateDelete')
307  );
308 
309  $this->toolbar->addStickyItem($preview_button);
310  $this->toolbar->addComponent($export_button);
311  $this->toolbar->addComponent($delete_button);
312  }
313  $form->addCommandButton("certificateSave", $this->language->txt("save"));
314  }
315 
316  return $form;
317  }
318 
319  public function save(array $formFields): void
320  {
321  }
322 
326  public function fetchFormFieldData(string $content): array
327  {
328  return $this->formFieldParser->fetchDefaultFormFields($content);
329  }
330 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
removePlugin(string $a_plugin)
__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, ?ilCertificateBackgroundImageFileService $backgroundImageFileService=null)
This class represents a file property in a property form.
readonly ilCertificateTemplateRepository $templateRepository
readonly ilCertificateTemplateImportAction $importAction
readonly ilCertificateBackgroundImageFileService $backGroundImageFileService
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)
global $DIC
Definition: feed.php:28
Class ilObjCertificateSettings.
This class represents a property in a property form.
GUI class to create PDF certificates.
const CLIENT_WEB_DIR
Definition: constants.php:47
setRequired(bool $a_required)
This class represents an image 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 class represents a text area property in a property form.
static signFile(string $path_to_file)