ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $template;
23 
27  private $controller;
28 
32  private $access;
33 
37  private $toolbar;
38 
43 
47  private $pageFormats;
48 
53 
57  private $importAction;
58 
63 
79  public function __construct(
80  int $objectId,
81  string $certificatePath,
91  ilLogger $logger = null,
93  ) {
94  global $DIC;
95 
96  $this->objectId = $objectId;
97  $this->language = $language;
98  $this->template = $template;
99  $this->controller = $controller;
100  $this->access = $access;
101  $this->toolbar = $toolbar;
102  $this->placeholderDescriptionObject = $placeholderDescriptionObject;
103 
104  $database = $DIC->database();
105 
106 
107  if (null === $logger) {
108  $logger = $logger = $DIC->logger()->cert();
109  }
110 
111  if (null === $pageFormats) {
112  $pageFormats = new ilPageFormats($language);
113  }
114  $this->pageFormats = $pageFormats;
115 
116  if (null === $formFieldParser) {
118  }
119  $this->formFieldParser = $formFieldParser;
120 
121  if (null === $importAction) {
123  (int) $objectId,
124  $certificatePath,
125  $placeholderDescriptionObject,
126  $logger,
127  $DIC->filesystem()->web()
128  );
129  }
130  $this->importAction = $importAction;
131 
132  if (null === $templateRepository) {
133  $templateRepository = new ilCertificateTemplateRepository($database, $logger);
134  }
135  $this->templateRepository = $templateRepository;
136  }
137 
149  public function createForm(ilCertificateGUI $certificateGUI, ilCertificate $certificateObject)
150  {
151  $certificateTemplate = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
152 
153  $command = $this->controller->getCmd();
154 
155  $form = new ilPropertyFormGUI();
156  $form->setPreventDoubleSubmission(false);
157  $form->setFormAction($this->controller->getFormAction($certificateGUI));
158  $form->setTitle($this->language->txt("cert_form_sec_availability"));
159  $form->setMultipart(true);
160  $form->setTableWidth("100%");
161  $form->setId("certificate");
162 
163  $active = new ilCheckboxInputGUI($this->language->txt("active"), "active");
164  $form->addItem($active);
165 
166  $import = new ilFileInputGUI($this->language->txt("import"), "certificate_import");
167  $import->setRequired(false);
168  $import->setSuffixes(array("zip"));
169 
170  // handle the certificate import
171  if (strlen($_FILES["certificate_import"]["name"])) {
172  if ($import->checkInput()) {
173  $result = $this->importAction->import($_FILES["certificate_import"]["tmp_name"], $_FILES["certificate_import"]["name"]);
174  if ($result == false) {
175  $import->setAlert($this->language->txt("certificate_error_import"));
176  } else {
177  $this->controller->redirect($certificateGUI, "certificateEditor");
178  }
179  }
180  }
181  $form->addItem($import);
182 
183  $formSection = new \ilFormSectionHeaderGUI();
184  $formSection->setTitle($this->language->txt("cert_form_sec_layout"));
185  $form->addItem($formSection);
186 
187  $pageformat = new ilRadioGroupInputGUI($this->language->txt("certificate_page_format"), "pageformat");
188  $pageformats = $this->pageFormats->fetchPageFormats();
189 
190  foreach ($pageformats as $format) {
191  $option = new ilRadioOption($format["name"], $format["value"]);
192 
193  if (strcmp($format["value"], "custom") == 0) {
194  $pageheight = new ilTextInputGUI($this->language->txt("certificate_pageheight"), "pageheight");
195  $pageheight->setSize(6);
196  $pageheight->setValidationRegexp('/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*)))(cm|mm|in|pt|pc|px|em)$/is');
197  $pageheight->setInfo($this->language->txt("certificate_unit_description"));
198  $pageheight->setRequired(true);
199  $option->addSubitem($pageheight);
200 
201  $pagewidth = new ilTextInputGUI($this->language->txt("certificate_pagewidth"), "pagewidth");
202  $pagewidth->setSize(6);
203  $pagewidth->setValidationRegexp('/^(([1-9]+|([1-9]+[0]*[\.,]{0,1}[\d]+))|(0[\.,](0*[1-9]+[\d]*)))(cm|mm|in|pt|pc|px|em)$/is');
204  $pagewidth->setInfo($this->language->txt("certificate_unit_description"));
205  $pagewidth->setRequired(true);
206  $option->addSubitem($pagewidth);
207  }
208 
209  $pageformat->addOption($option);
210  }
211 
212  $pageformat->setRequired(true);
213 
214  if (strcmp($command, "certificateSave") == 0) {
215  $pageformat->checkInput();
216  }
217 
218  $form->addItem($pageformat);
219 
220  $bgimage = new ilImageFileInputGUI($this->language->txt("certificate_background_image"), "background");
221  $bgimage->setRequired(false);
222  $bgimage->setUseCache(false);
223 
224  $bgimage->setALlowDeletion(true);
225  if (!$certificateObject->hasBackgroundImage()) {
229  $bgimage->setImage($imagePath);
230  $bgimage->setALlowDeletion(false);
231  }
232  } else {
234 
235  $thumbnailPath = $certificateObject->getBackgroundImageThumbPath();
236 
237  if (!file_exists($thumbnailPath)) {
239  $bgimage->setALlowDeletion(false);
240  }
241  $imagePath = ilWACSignedPath::signFile($thumbnailPath);
242  $bgimage->setImage($imagePath);
243  }
244 
245  $form->addItem($bgimage);
246 
247  $thumbnailImage = new ilImageFileInputGUI($this->language->txt('certificate_card_thumbnail_image'), 'certificate_card_thumbnail_image');
248  $thumbnailImage->setRequired(false);
249  $thumbnailImage->setUseCache(false);
250  $thumbnailImage->setSuffixes(array('svg'));
251 
252  $allowThumbnailDeletion = false;
253 
254  $cardThumbnailImagePath = $certificateTemplate->getThumbnailImagePath();
255  if ('' !== $cardThumbnailImagePath) {
256  $presentationThumbnailImagePath = CLIENT_WEB_DIR . $cardThumbnailImagePath;
257  $thumbnailImage->setImage(ilWACSignedPath::signFile($presentationThumbnailImagePath));
258  $allowThumbnailDeletion = true;
259  }
260 
261  $thumbnailImage->setAllowDeletion($allowThumbnailDeletion);
262 
263  $form->addItem($thumbnailImage);
264 
265  $rect = new ilCSSRectInputGUI($this->language->txt("certificate_margin_body"), "margin_body");
266  $rect->setRequired(true);
267  $rect->setUseUnits(true);
268  $rect->setInfo($this->language->txt("certificate_unit_description"));
269 
270  if (strcmp($command, "certificateSave") == 0) {
271  $rect->checkInput();
272  }
273 
274  $form->addItem($rect);
275 
276  $certificate = new ilTextAreaInputGUI($this->language->txt("certificate_text"), "certificate_text");
277  $certificate->removePlugin('ilimgupload');
278  $certificate->setRequired(true);
279  $certificate->setRows(20);
280  $certificate->setCols(80);
281 
282 
283  $placeholderHtmlDescription = $this->placeholderDescriptionObject->createPlaceholderHtmlDescription();
284 
285  $placeholderDescriptionInHtml = $placeholderHtmlDescription;
286 
287  $certificate->setInfo($placeholderDescriptionInHtml);
288 
289  $certificate->setUseRte(true, '3.4.7');
290 
291  $tags = array(
292  "br",
293  "em",
294  "font",
295  "li",
296  "ol",
297  "p",
298  "span",
299  "strong",
300  "u",
301  "ul"
302  );
303 
304  $certificate->setRteTags($tags);
305 
306  if (strcmp($command, "certificateSave") == 0) {
307  $certificate->checkInput();
308  }
309 
310  $form->addItem($certificate);
311 
312  if ($certificateObject->getAdapter()->hasAdditionalFormElements()) {
313  $formSection = new \ilFormSectionHeaderGUI();
314  $formSection->setTitle($this->language->txt("cert_form_sec_add_features"));
315  $form->addItem($formSection);
316  }
317 
318  if ($this->access->checkAccess("write", "", $_GET["ref_id"])) {
319  if ($certificateTemplate->isCurrentlyActive()) {
320  $this->toolbar->setFormAction($this->controller->getFormAction($certificateGUI));
321 
323  $preview->setCaption('certificate_preview');
324  $preview->setCommand('certificatePreview');
325  $this->toolbar->addStickyItem($preview);
326 
327  $export = ilSubmitButton::getInstance();
328  $export->setCaption('certificate_export');
329  $export->setCommand('certificateExportFO');
330  $this->toolbar->addButtonInstance($export);
331 
332  $delete = ilSubmitButton::getInstance();
333  $delete->setCaption('delete');
334  $delete->setCommand('certificateDelete');
335  $this->toolbar->addButtonInstance($delete);
336  }
337  $form->addCommandButton("certificateSave", $this->language->txt("save"));
338  }
339 
340  return $form;
341  }
342 
347  public function save(array $formFields)
348  {
349  }
350 
355  public function fetchFormFieldData(string $content)
356  {
357  return $this->formFieldParser->fetchDefaultFormFields($content);
358  }
359 }
This class represents an option in a radio group.
This class provides processing control methods.
static getBackgroundImageThumbPath()
Returns the filesystem path of the background image thumbnail.
$format
Definition: metadata.php:141
$result
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
This class represents a file property in a property form.
$preview
This class represents a checkbox property in a property form.
This class represents a text property in a property form.
Class ilAccessHandler.
hasBackgroundImage()
Checks for the background image of the certificate.
getBackgroundImageThumbPath()
Returns the filesystem path of the background image thumbnail.
if(@file_exists(dirname(__FILE__).'/lang/eng.php')) $certificate
Definition: example_052.php:77
This class represents a property in a property form.
getAdapter()
Gets the adapter.
if(isset($_POST['submit'])) $form
$tags
Definition: croninfo.php:19
special template class to simplify handling of ITX/PEAR
setSize($a_size)
Set Size.
This class represents a text property in a property form.
GUI class to create PDF certificates.
static getBackgroundImageThumbPathWeb()
Returns the web path of the background image thumbnail.
static signFile($path_to_file)
static hasBackgroundImage()
Returns wheather or not a default background image exists.
This class represents an image file property in a property form.
This class represents a text area property in a property form.
__construct(int $objectId, string $certificatePath, ilLanguage $language, ilTemplate $template, ilCtrl $controller, ilAccess $access, ilToolbarGUI $toolbar, ilCertificatePlaceholderDescription $placeholderDescriptionObject, ilPageFormats $pageFormats=null, ilFormFieldParser $formFieldParser=null, ilCertificateTemplateImportAction $importAction=null, ilLogger $logger=null, ilCertificateTemplateRepository $templateRepository=null)
Create PDF certificates.
language handling
static setTokenMaxLifetimeInSeconds($token_max_lifetime_in_seconds)
Component logger with individual log levels by component id.
createForm(ilCertificateGUI $certificateGUI, ilCertificate $certificateObject)
setRequired($a_required)
Set Required.