ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCertificateSettingsFormRepository.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 {
12  private $objectId;
13 
17  private $language;
18 
22  private $controller;
23 
27  private $access;
28 
32  private $toolbar;
33 
38 
42  private $pageFormats;
43 
48 
52  private $importAction;
53 
58 
63 
68 
77 
92  public function __construct(
93  int $objectId,
94  string $certificatePath,
104  ilLogger $logger = null,
106  \ILIAS\Filesystem\Filesystem $filesystem = null,
107  ilCertificateBackgroundImageFileService $backgroundImageFileService = null
108  ) {
109  global $DIC;
110 
111  $this->objectId = $objectId;
112  $this->language = $language;
113  $this->controller = $controller;
114  $this->access = $access;
115  $this->toolbar = $toolbar;
116  $this->placeholderDescriptionObject = $placeholderDescriptionObject;
117  $this->certificatePath = $certificatePath;
118  $this->hasAdditionalElements = $hasAdditionalElements;
119  $this->globalCertificateSettings = new ilObjCertificateSettings();
120 
121  $database = $DIC->database();
122 
123 
124  if (null === $logger) {
125  $logger = $logger = $DIC->logger()->cert();
126  }
127 
128  if (null === $pageFormats) {
129  $pageFormats = new ilPageFormats($language);
130  }
131  $this->pageFormats = $pageFormats;
132 
133  if (null === $formFieldParser) {
135  }
136  $this->formFieldParser = $formFieldParser;
137 
138  if (null === $importAction) {
140  (int) $objectId,
141  $certificatePath,
142  $placeholderDescriptionObject,
143  $logger,
144  $DIC->filesystem()->web()
145  );
146  }
147  $this->importAction = $importAction;
148 
149  if (null === $templateRepository) {
150  $templateRepository = new ilCertificateTemplateRepository($database, $logger);
151  }
152  $this->templateRepository = $templateRepository;
153 
154  if (null === $filesystem) {
155  $filesystem = $DIC->filesystem()->web();
156  }
157 
158  if (null === $backgroundImageFileService) {
159  $backgroundImageFileService = new ilCertificateBackgroundImageFileService(
160  $certificatePath,
161  $filesystem
162  );
163  }
164  $this->backGroundImageFileService = $backgroundImageFileService;
165  }
166 
179  public function createForm(ilCertificateGUI $certificateGUI)
180  {
181  $certificateTemplate = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
182 
183  $command = $this->controller->getCmd();
184 
185  $form = new ilPropertyFormGUI();
186  $form->setPreventDoubleSubmission(false);
187  $form->setFormAction($this->controller->getFormAction($certificateGUI));
188  $form->setTitle($this->language->txt("cert_form_sec_availability"));
189  $form->setMultipart(true);
190  $form->setTableWidth("100%");
191  $form->setId("certificate");
192 
193  $active = new ilCheckboxInputGUI($this->language->txt("active"), "active");
194  $form->addItem($active);
195 
196  $import = new ilFileInputGUI($this->language->txt("import"), "certificate_import");
197  $import->setRequired(false);
198  $import->setSuffixes(array("zip"));
199 
200  // handle the certificate import
201  if (strlen($_FILES["certificate_import"]["name"])) {
202  if ($import->checkInput()) {
203  $result = $this->importAction->import($_FILES["certificate_import"]["tmp_name"], $_FILES["certificate_import"]["name"]);
204  if ($result == false) {
205  $import->setAlert($this->language->txt("certificate_error_import"));
206  } else {
207  $this->controller->redirect($certificateGUI, "certificateEditor");
208  }
209  }
210  }
211  $form->addItem($import);
212 
213  $formSection = new \ilFormSectionHeaderGUI();
214  $formSection->setTitle($this->language->txt("cert_form_sec_layout"));
215  $form->addItem($formSection);
216 
217  $pageformat = new ilRadioGroupInputGUI($this->language->txt("certificate_page_format"), "pageformat");
218  $pageformats = $this->pageFormats->fetchPageFormats();
219 
220  foreach ($pageformats as $format) {
221  $option = new ilRadioOption($format["name"], $format["value"]);
222 
223  if (strcmp($format["value"], "custom") == 0) {
224  $pageheight = new ilTextInputGUI($this->language->txt("certificate_pageheight"), "pageheight");
225  $pageheight->setSize(6);
226  $pageheight->setValidationRegexp('/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*)))(cm|mm|in|pt|pc|px|em)$/is');
227  $pageheight->setInfo($this->language->txt("certificate_unit_description"));
228  $pageheight->setRequired(true);
229  $option->addSubitem($pageheight);
230 
231  $pagewidth = new ilTextInputGUI($this->language->txt("certificate_pagewidth"), "pagewidth");
232  $pagewidth->setSize(6);
233  $pagewidth->setValidationRegexp('/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*)))(cm|mm|in|pt|pc|px|em)$/is');
234  $pagewidth->setInfo($this->language->txt("certificate_unit_description"));
235  $pagewidth->setRequired(true);
236  $option->addSubitem($pagewidth);
237  }
238 
239  $pageformat->addOption($option);
240  }
241 
242  $pageformat->setRequired(true);
243 
244  if (strcmp($command, "certificateSave") == 0) {
245  $pageformat->checkInput();
246  }
247 
248  $form->addItem($pageformat);
249 
250  $bgimage = new ilImageFileInputGUI($this->language->txt("certificate_background_image"), "background");
251  $bgimage->setRequired(false);
252  $bgimage->setUseCache(false);
253 
254  $bgimage->setALlowDeletion(true);
255  if (!$this->backGroundImageFileService->hasBackgroundImage($certificateTemplate)) {
256  if ($this->globalCertificateSettings->hasBackgroundImage()) {
258  $imagePath = ilWACSignedPath::signFile($this->globalCertificateSettings->getBackgroundImageThumbPathWeb());
259  $bgimage->setImage($imagePath);
260  $bgimage->setALlowDeletion(false);
261  }
262  } else {
264 
265  $thumbnailPath = $this->backGroundImageFileService->getBackgroundImageThumbPath();
266 
267  if (!is_file($thumbnailPath)) {
268  //Trying if it uses default image path
269  $thumbnailPath = CLIENT_WEB_DIR . $certificateTemplate->getBackgroundImagePath() . '.thumb.jpg';
270  if (!is_file($thumbnailPath)) {
271  //Trying to use global default image
272  $thumbnailPath = $this->globalCertificateSettings->getDefaultBackgroundImageThumbPath();
273  if (!is_file($thumbnailPath)) {
274  //No image global default configured
275  $thumbnailPath = '';
276  }
277  }
278  $bgimage->setALlowDeletion(false);
279  }
280  $imagePath = ilWACSignedPath::signFile($thumbnailPath);
281  $bgimage->setImage($imagePath);
282  }
283 
284  $form->addItem($bgimage);
285 
286  $thumbnailImage = new ilImageFileInputGUI($this->language->txt('certificate_card_thumbnail_image'), 'certificate_card_thumbnail_image');
287  $thumbnailImage->setRequired(false);
288  $thumbnailImage->setUseCache(false);
289  $thumbnailImage->setSuffixes(array('svg'));
290 
291  $allowThumbnailDeletion = false;
292 
293  $cardThumbnailImagePath = $certificateTemplate->getThumbnailImagePath();
294  if ('' !== $cardThumbnailImagePath) {
295  $presentationThumbnailImagePath = CLIENT_WEB_DIR . $cardThumbnailImagePath;
296  $thumbnailImage->setImage(ilWACSignedPath::signFile($presentationThumbnailImagePath));
297  $allowThumbnailDeletion = true;
298  }
299 
300  $thumbnailImage->setAllowDeletion($allowThumbnailDeletion);
301 
302  $form->addItem($thumbnailImage);
303 
304  $rect = new ilCSSRectInputGUI($this->language->txt("certificate_margin_body"), "margin_body");
305  $rect->setRequired(true);
306  $rect->setUseUnits(true);
307  $rect->setInfo($this->language->txt("certificate_unit_description"));
308 
309  if (strcmp($command, "certificateSave") == 0) {
310  $rect->checkInput();
311  }
312 
313  $form->addItem($rect);
314 
315  $certificate = new ilTextAreaInputGUI($this->language->txt("certificate_text"), "certificate_text");
316  $certificate->removePlugin('ilimgupload');
317  $certificate->setRequired(true);
318  $certificate->setRows(20);
319  $certificate->setCols(80);
320 
321  $placeholderHtmlDescription = $this->placeholderDescriptionObject->createPlaceholderHtmlDescription();
322 
323  $placeholderDescriptionInHtml = $placeholderHtmlDescription;
324 
325  $certificate->setInfo($placeholderDescriptionInHtml);
326 
327  $certificate->setUseRte(true, '3.4.7');
328 
329  $tags = array(
330  "br",
331  "em",
332  "font",
333  "li",
334  "ol",
335  "p",
336  "span",
337  "strong",
338  "u",
339  "ul"
340  );
341 
342  $certificate->setRteTags($tags);
343 
344  if (strcmp($command, "certificateSave") == 0) {
345  $certificate->checkInput();
346  }
347 
348  $form->addItem($certificate);
349 
350  if (true === $this->hasAdditionalElements) {
351  $formSection = new \ilFormSectionHeaderGUI();
352  $formSection->setTitle($this->language->txt("cert_form_sec_add_features"));
353  $form->addItem($formSection);
354  }
355 
356  if ($this->access->checkAccess("write", "", $_GET["ref_id"])) {
357  if ($certificateTemplate->isCurrentlyActive()) {
358  $this->toolbar->setFormAction($this->controller->getFormAction($certificateGUI));
359 
361  $preview->setCaption('certificate_preview');
362  $preview->setCommand('certificatePreview');
363  $this->toolbar->addStickyItem($preview);
364 
365  $export = ilSubmitButton::getInstance();
366  $export->setCaption('certificate_export');
367  $export->setCommand('certificateExportFO');
368  $this->toolbar->addButtonInstance($export);
369 
370  $delete = ilSubmitButton::getInstance();
371  $delete->setCaption('delete');
372  $delete->setCommand('certificateDelete');
373  $this->toolbar->addButtonInstance($delete);
374  }
375  $form->addCommandButton("certificateSave", $this->language->txt("save"));
376  }
377 
378  return $form;
379  }
380 
385  public function save(array $formFields)
386  {
387  }
388 
393  public function fetchFormFieldData(string $content)
394  {
395  return $this->formFieldParser->fetchDefaultFormFields($content);
396  }
397 }
__construct(int $objectId, string $certificatePath, bool $hasAdditionalElements, ilLanguage $language, ilCtrl $controller, ilAccess $access, ilToolbarGUI $toolbar, ilCertificatePlaceholderDescription $placeholderDescriptionObject, ilPageFormats $pageFormats=null, ilFormFieldParser $formFieldParser=null, ilCertificateTemplateImportAction $importAction=null, ilLogger $logger=null, ilCertificateTemplateRepository $templateRepository=null, \ILIAS\Filesystem\Filesystem $filesystem=null, ilCertificateBackgroundImageFileService $backgroundImageFileService=null)
This class represents an option in a radio group.
This class provides processing control methods.
$result
This class represents a property form user interface.
$_GET["client_id"]
This class represents a file property in a property form.
Class ChatMainBarProvider .
This class represents a checkbox property in a property form.
This class represents a text property in a property form.
removePlugin($a_plugin)
Remove RTE plugin.
Class ilObjCertificateSettings.
This class represents a property in a property form.
$preview
Definition: imgupload.php:55
global $DIC
Definition: goto.php:24
$format
Definition: metadata.php:218
GUI class to create PDF certificates.
const CLIENT_WEB_DIR
Definition: constants.php:45
static signFile($path_to_file)
This class represents an image file property in a property form.
This class represents a text area property in a property form.
static setTokenMaxLifetimeInSeconds($token_max_lifetime_in_seconds)
Component logger with individual log levels by component id.
language()
Definition: language.php:2
setRequired($a_required)
Set Required.
Class FlySystemFileAccessTest disabled disabled disabled.