ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCertificateGUI.php
Go to the documentation of this file.
1<?php
2 /*
3 +----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +----------------------------------------------------------------------------+
22*/
23
33{
38
42 private $fileSystem;
43
49 protected $ctrl;
50
56 protected $tree;
57
63 protected $ilias;
64
70 protected $tpl;
71
77 protected $lng;
78
84 protected $ref_id;
85
89 protected $access;
90
94 protected $toolbar;
95
100
105
110
114 private $objectId;
115
120
125
130
135
140
145
150
155
159 private $fileUpload;
160
165
169 private $settings;
170
175
178
183
184 public function __construct(
187 $objectId,
198 \ILIAS\FileUpload\FileUpload $fileUpload = null,
199 ilSetting $settings = null,
202 ilCertificateBackgroundImageFileService $imageFileService = null,
204 ) {
205 global $DIC;
206
207 $this->lng = $DIC['lng'];
208 $this->tpl = $DIC['tpl'];
209 $this->ctrl = $DIC['ilCtrl'];
210 $this->ilias = $DIC['ilias'];
211 $this->tree = $DIC['tree'];
212 $this->access = $DIC['ilAccess'];
213 $this->toolbar = $DIC['ilToolbar'];
214
215 $this->globalCertificateSettings = new ilObjCertificateSettings();
216
217 $this->lng->loadLanguageModule('certificate');
218 $this->lng->loadLanguageModule('cert');
219 $this->lng->loadLanguageModule("trac");
220
221 $this->ref_id = (int) $_GET['ref_id'];
222
223 $this->placeholderDescriptionObject = $placeholderDescriptionObject;
224
225 $this->placeholderValuesObject = $placeholderValuesObject;
226
227 $this->objectId = $objectId;
228
229 $logger = $DIC->logger()->cert();
230
231 if (null === $settingsFormFactory) {
233 $this->objectId,
235 $this->lng,
236 $this->tpl,
237 $this->ctrl,
238 $this->access,
239 $this->toolbar,
241 );
242 }
243 $this->settingsFormFactory = $settingsFormFactory;
244
245 if (null === $templateRepository) {
246 $templateRepository = new ilCertificateTemplateRepository($DIC->database(), $logger);
247 }
248 $this->templateRepository = $templateRepository;
249
250 if (null === $deleteAction) {
252 }
253 $this->deleteAction = $deleteAction;
254
255 if (null === $formFieldParser) {
257 }
258 $this->formFieldParser = $formFieldParser;
259
260 if (null === $pageFormats) {
261 $pageFormats = new ilPageFormats($DIC->language());
262 }
263 $this->pageFormats = $pageFormats;
264
265 if (null === $xlsFoParser) {
266 $xlsFoParser = new ilXlsFoParser($DIC->settings(), $pageFormats);
267 }
268 $this->xlsFoParser = $xlsFoParser;
269
270 if (null === $upload) {
272 $DIC->upload(),
274 $DIC->language(),
275 $logger
276 );
277 }
278 $this->backgroundImageUpload = $upload;
279
280 if (null === $exportAction) {
282 $this->objectId,
284 $this->templateRepository,
285 $DIC->filesystem()->web()
286 );
287 }
288 $this->exportAction = $exportAction;
289
290 if (null === $previewAction) {
292 }
293 $this->previewAction = $previewAction;
294
295 if (null === $fileUpload) {
296 global $DIC;
297 $fileUpload = $DIC->upload();
298 }
299 $this->fileUpload = $fileUpload;
300
301 $this->certificatePath = $certificatePath;
302
303 if (null === $settings) {
304 $settings = new ilSetting('certificate');
305 }
306 $this->settings = $settings;
307
308 if (null === $fileSystem) {
309 $fileSystem = $DIC->filesystem()->web();
310 }
311 $this->fileSystem = $fileSystem;
312
313 if (null === $imageFileService) {
314 $imageFileService = new ilCertificateBackgroundImageFileService(
315 $this->certificatePath,
316 $this->fileSystem
317 );
318 }
319
320 if (null === $backgroundImageDelete) {
322 $this->certificatePath,
323 $imageFileService
324 );
325 }
326 $this->backgroundImageDelete = $backgroundImageDelete;
327
328 if (null === $tmp_file_system) {
329 $tmp_file_system = $DIC->filesystem()->temp();
330 }
331 $this->tmp_file_system = $tmp_file_system;
332 }
333
337 public function executeCommand()
338 {
339 $cmd = $this->ctrl->getCmd();
340 $next_class = $this->ctrl->getNextClass($this);
341
342 $cmd = $this->getCommand($cmd);
343 switch ($next_class) {
344 case 'ilpropertyformgui':
345 $form = $this->getEditorForm();
346 $this->ctrl->forwardCommand($form);
347 break;
348
349 default:
350 $ret = $this->$cmd();
351 break;
352 }
353 return $ret;
354 }
355
359 public function getCommand($cmd)
360 {
361 return $cmd;
362 }
363
367 public function certificateImport()
368 {
369 $this->certificateEditor();
370 }
371
375 public function certificatePreview()
376 {
377 try {
378 $this->previewAction->createPreviewPdf($this->objectId);
379 } catch (Exception $exception) {
380 ilUtil::sendFailure($this->lng->txt('error_creating_certificate_pdf', true));
381 $this->certificateEditor();
382 }
383 }
384
388 public function certificateExportFO()
389 {
390 $this->exportAction->export();
391 }
392
397 {
398 $this->backgroundImageDelete->deleteBackgroundImage('');
399 $this->certificateEditor();
400 }
401
405 public function certificateDelete()
406 {
407 // display confirmation message
408 $cgui = new ilConfirmationGUI();
409 $cgui->setFormAction($this->ctrl->getFormAction($this, "certificateEditor"));
410 $cgui->setHeaderText($this->lng->txt("certificate_confirm_deletion_text"));
411 $cgui->setCancel($this->lng->txt("no"), "certificateEditor");
412 $cgui->setConfirm($this->lng->txt("yes"), "certificateDeleteConfirm");
413
414 $this->tpl->setContent($cgui->getHTML());
415 }
416
420 public function certificateDeleteConfirm()
421 {
422 $template = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
423 $templateId = $template->getId();
424
425 $this->deleteAction->delete($templateId, $this->objectId);
426 $this->ctrl->redirect($this, "certificateEditor");
427 }
428
432 public function certificateSave()
433 {
434 global $DIC;
435
436 $form = $this->settingsFormFactory->createForm(
437 $this
438 );
439
440 $form->setValuesByPost();
441
442 $request = $DIC->http()->request();
443
444 $formFields = $request->getParsedBody();
445
446 $this->tpl->setVariable('ADM_CONTENT', $form->getHTML());
447
448 $this->saveCertificate($form, $formFields, $this->objectId);
449 }
450
454 public function certificateUpload()
455 {
456 $this->certificateEditor();
457 }
458
468 private function getEditorForm() : \ilPropertyFormGUI
469 {
470 $certificateTemplate = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
471
472 $form = $this->settingsFormFactory->createForm(
473 $this
474 );
475
476 $formFields = $this->createFormatArray($certificateTemplate);
477
478 $formFields['active'] = $certificateTemplate->isCurrentlyActive();
479
480 $form->setValuesByArray($formFields);
481
482 return $form;
483 }
484
488 public function certificateEditor()
489 {
490 $form = $this->getEditorForm();
491 $enabledGlobalLearningProgress = \ilObjUserTracking::_enabledLearningProgress();
492
493 $messageBoxHtml = '';
494 if ($enabledGlobalLearningProgress) {
495 $objectLearningProgressSettings = new ilLPObjSettings($this->objectId);
496 $mode = $objectLearningProgressSettings->getMode();
497
499 $object = ilObjectFactory::getInstanceByObjId($this->objectId);
500 if (ilLPObjSettings::LP_MODE_DEACTIVATED == $mode && $object->getType() !== 'crs') {
501 global $DIC;
502
503 $renderer = $DIC->ui()->renderer();
504 $messageBox = $DIC->ui()
505 ->factory()
506 ->messageBox()
507 ->info($this->lng->txt('learning_progress_deactivated'));
508
509 $messageBoxHtml = $renderer->render($messageBox);
510 $form->clearCommandButtons();
511 }
512 }
513
514 $formHtml = $form->getHTML();
515
516 $this->tpl->setVariable("ADM_CONTENT", $messageBoxHtml . $formHtml);
517 }
518
524 private function saveCertificate(ilPropertyFormGUI $form, array $form_fields, $objId)
525 {
526 $previousCertificateTemplate = $this->templateRepository->fetchPreviousCertificate($objId);
527 $currentVersion = $previousCertificateTemplate->getVersion();
528 $nextVersion = $currentVersion + 1;
529
530 if ($_POST["background_delete"]) {
531 $this->backgroundImageDelete->deleteBackgroundImage($currentVersion);
532 }
533
534 if ($form->checkInput()) {
535 try {
536 $this->settingsFormFactory->save($form_fields);
537
538 $templateValues = $this->placeholderDescriptionObject->getPlaceholderDescriptions();
539
540 // handle the background upload
541 $backgroundImagePath = '';
542 $temporaryFileName = $_FILES['background']['tmp_name'];
543 if (strlen($temporaryFileName)) {
544 try {
545 $backgroundImagePath = $this->backgroundImageUpload->uploadBackgroundImage(
546 $temporaryFileName,
547 $nextVersion,
548 $form->getInput('background')
549 );
550 } catch (ilException $exception) {
551 $form->getItemByPostVar('background')->setAlert($this->lng->txt("certificate_error_upload_bgimage"));
552 }
553 if (false === $this->fileSystem->has($backgroundImagePath)) {
554 $form->getItemByPostVar('background')->setAlert($this->lng->txt("certificate_error_upload_bgimage"));
555 $backgroundImagePath = '';
556 }
557 }
558 if ($backgroundImagePath === '') {
559 if ($_POST['background_delete'] || $previousCertificateTemplate->getBackgroundImagePath() === '') {
560 $backgroundImagePath = $this->globalCertificateSettings->getDefaultBackgroundImagePath(true);
561 } else {
562 $backgroundImagePath = $previousCertificateTemplate->getBackgroundImagePath();
563 }
564 }
565
566 // handle the card thumbnail upload
567 $cardThumbnailImagePath = '';
568 $temporaryFileName = $_FILES['certificate_card_thumbnail_image']['tmp_name'];
569 if (strlen($temporaryFileName) && $this->fileUpload->hasUploads()) {
570 try {
571 if (false === $this->fileUpload->hasBeenProcessed()) {
572 $this->fileUpload->process();
573 }
574
576 $uploadResults = $this->fileUpload->getResults();
577 $pending_card_file = $form->getInput('certificate_card_thumbnail_image');
578 $cardThumbnailFileName = 'card_thumbnail_image_' . $nextVersion . '.svg';
579 if (isset($uploadResults[$temporaryFileName])) {
580 $result = $uploadResults[$temporaryFileName];
581 if ($result->getStatus() == \ILIAS\FileUpload\DTO\ProcessingStatus::OK) {
582 $this->fileUpload->moveOneFileTo(
583 $result,
584 $this->certificatePath,
585 \ILIAS\FileUpload\Location::WEB,
586 $cardThumbnailFileName,
587 true
588 );
589
590 $cardThumbnailImagePath = $this->certificatePath . $cardThumbnailFileName;
591 }
592 } elseif ($pending_card_file !== null && !empty($pending_card_file)) {
593 $stream = $this->tmp_file_system->readStream(basename($pending_card_file['tmp_name']));
594 $this->fileSystem->writeStream($this->certificatePath . '/' . $cardThumbnailFileName, $stream);
595 $cardThumbnailImagePath = $this->certificatePath . $cardThumbnailFileName;
596 } else {
597 throw new ilException($this->lng->txt('upload_error_file_not_found'));
598 }
599 } catch (ilException $exception) {
600 $form->getItemByPostVar('certificate_card_thumbnail_image')->setAlert($this->lng->txt("certificate_error_upload_ctimage"));
601 }
602 if (false === $this->fileSystem->has($cardThumbnailImagePath)) {
603 $form->getItemByPostVar('certificate_card_thumbnail_image')->setAlert($this->lng->txt("certificate_error_upload_ctimage"));
604 $cardThumbnailImagePath = '';
605 }
606 }
607 if ($cardThumbnailImagePath === '' && !$_POST['certificate_card_thumbnail_image_delete']) {
608 $cardThumbnailImagePath = $previousCertificateTemplate->getThumbnailImagePath();
609 }
610
611 $jsonEncodedTemplateValues = json_encode($templateValues);
612
613 $xslfo = $this->xlsFoParser->parse($form_fields);
614
615 $newHashValue = hash(
616 'sha256',
617 implode('', array(
618 $xslfo,
619 $backgroundImagePath,
620 $jsonEncodedTemplateValues,
621 $cardThumbnailImagePath
622 ))
623 );
624
625 $active = (bool) $form_fields['active'];
626
627 if ($newHashValue !== $previousCertificateTemplate->getCertificateHash()) {
628 $certificateTemplate = new ilCertificateTemplate(
629 $objId,
631 $xslfo,
632 $newHashValue,
633 $jsonEncodedTemplateValues,
634 $nextVersion,
636 time(),
637 $active,
638 $backgroundImagePath,
639 $cardThumbnailImagePath
640 );
641
642 $this->templateRepository->save($certificateTemplate);
643 ilUtil::sendSuccess($this->lng->txt("saved_successfully"), true);
644 $this->ctrl->redirect($this, "certificateEditor");
645 }
646
647 if ($previousCertificateTemplate->getId() !== null && $previousCertificateTemplate->isCurrentlyActive() !== $active) {
648 $this->templateRepository->updateActivity($previousCertificateTemplate, $active);
649 ilUtil::sendInfo($this->lng->txt('certificate_change_active_status'), true);
650 $this->ctrl->redirect($this, "certificateEditor");
651 }
652
653 ilUtil::sendInfo($this->lng->txt('certificate_same_not_saved'), true);
654 $this->ctrl->redirect($this, "certificateEditor");
655 } catch (Exception $e) {
656 ilUtil::sendFailure($e->getMessage());
657 }
658 }
659
660 $form->setValuesByPost();
661
662 $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
663 }
664
670 private function setTemplateContent(ilCertificateTemplate $certificate, ilPropertyFormGUI $form)
671 {
672 $form_fields = $this->settingsFormFactory->fetchFormFieldData($certificate->getCertificateContent());
673 $form_fields['active'] = $certificate->isCurrentlyActive();
674
675 $form->setValuesByArray($form_fields);
676
677 $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
678 }
679
684 private function createFormatArray(ilCertificateTemplate $certificateTemplate)
685 {
686 if ('' === $certificateTemplate->getCertificateHash()) {
687 $format = $this->settings->get('pageformat');
688 $formats = $this->pageFormats->fetchPageFormats();
689
690 $formFieldArray = array(
691 'pageformat' => $format,
692 'pagewidth' => $formats['width'],
693 'pageheight' => $formats['height'],
694 'margin_body_top' => ilPageFormats::DEFAULT_MARGIN_BODY_TOP,
695 'margin_body_right' => ilPageFormats::DEFAULT_MARGIN_BODY_RIGHT,
696 'margin_body_bottom' => ilPageFormats::DEFAULT_MARGIN_BODY_BOTTOM,
697 'margin_body_left' => ilPageFormats::DEFAULT_MARGIN_BODY_LEFT,
698 'certificate_text' => $certificateTemplate->getCertificateContent()
699 );
700
701 return $formFieldArray;
702 }
703 return $this->settingsFormFactory->fetchFormFieldData($certificateTemplate->getCertificateContent());
704 }
705}
$result
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
GUI class to create PDF certificates.
certificateExportFO()
Exports the certificate.
createFormatArray(ilCertificateTemplate $certificateTemplate)
certificatePreview()
Creates a certificate preview.
__construct(ilCertificatePlaceholderDescription $placeholderDescriptionObject, ilCertificatePlaceholderValues $placeholderValuesObject, $objectId, $certificatePath, ilCertificateFormRepository $settingsFormFactory=null, ilCertificateDeleteAction $deleteAction=null, ilCertificateTemplateRepository $templateRepository=null, ilPageFormats $pageFormats=null, ilXlsFoParser $xlsFoParser=null, ilFormFieldParser $formFieldParser=null, ilCertificateTemplateExportAction $exportAction=null, ilCertificateBackgroundImageUpload $upload=null, ilCertificateTemplatePreviewAction $previewAction=null, \ILIAS\FileUpload\FileUpload $fileUpload=null, ilSetting $settings=null, ilCertificateBackgroundImageDelete $backgroundImageDelete=null, \ILIAS\Filesystem\Filesystem $fileSystem=null, ilCertificateBackgroundImageFileService $imageFileService=null, \ILIAS\Filesystem\Filesystem $tmp_file_system=null)
certificateImport()
Import a certificate from a ZIP archive.
setTemplateContent(ilCertificateTemplate $certificate, ilPropertyFormGUI $form)
certificateDelete()
Deletes the certificate and all its data.
getCommand($cmd)
Retrieves the ilCtrl command.
executeCommand()
execute command
certificateUpload()
Uploads the certificate.
certificateSave()
Saves the certificate.
certificateDeleteConfirm()
Deletes the certificate and all its data.
certificateRemoveBackground()
Removes the background image of a certificate.
Confirmation screen class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjCertificateSettings.
static _enabledLearningProgress()
check wether learing progress is enabled or not
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupType($a_id, $a_reference=false)
lookup object type
const DEFAULT_MARGIN_BODY_BOTTOM
This class represents a property form user interface.
setValuesByArray($a_values, $a_restrict_to_value_keys=false)
Set form values from an array.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
checkInput()
Check Post Input.
setValuesByPost()
Set form values from POST values.
getItemByPostVar($a_post_var)
Get Item by POST variable.
ILIAS Setting Class.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$formats
Definition: date.php:77
global $DIC
Definition: goto.php:24
const ILIAS_VERSION_NUMERIC
$format
Definition: metadata.php:218
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...
Class ChatMainBarProvider \MainMenu\Provider.
redirection script todo: (a better solution should control the processing via a xml file)
$ret
Definition: parser.php:6
settings()
Definition: settings.php:2
$objId
Definition: xapitoken.php:39