ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCertificateTemplateExportAction.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
5 
10 {
14  private $objectId;
15 
20 
25 
29  private $filesystem;
30 
34  private $objectHelper;
35 
39  private $utilHelper;
40 
49  public function __construct(
50  int $objectId,
51  string $certificatePath,
56  ) {
57  $this->objectId = $objectId;
58  $this->certificatePath = $certificatePath;
59  $this->templateRepository = $templateRepository;
60  $this->filesystem = $filesystem;
61 
62  if (null === $objectHelper) {
64  }
65  $this->objectHelper = $objectHelper;
66 
67  if (null === $utilHelper) {
69  }
70  $this->utilHelper = $utilHelper;
71  }
72 
81  public function export($rootDir = CLIENT_WEB_DIR, $installationId = IL_INST_ID)
82  {
83  $time = time();
84 
85  $type = $this->objectHelper->lookupType($this->objectId);
86  $certificateId = $this->objectId;
87 
88  $exportPath = $this->certificatePath . $time . '__' . $installationId . '__' . $type . '__' . $certificateId . '__certificate/';
89 
90  $this->filesystem->createDir($exportPath, \ILIAS\Filesystem\Visibility::PUBLIC_ACCESS);
91 
92  $template = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
93 
94  $xslContent = $template->getCertificateContent();
95 
96  $this->filesystem->put($exportPath . 'certificate.xml', $xslContent);
97 
98  $backgroundImagePath = $template->getBackgroundImagePath();
99  if ($backgroundImagePath !== '') {
100  if (true === $this->filesystem->has($backgroundImagePath)) {
101  $this->filesystem->copy($backgroundImagePath, $exportPath . 'background.jpg');
102  }
103  }
104 
105  $thumbnailImagePath = $template->getThumbnailImagePath();
106  if ($thumbnailImagePath !== '') {
107  if (true === $this->filesystem->has($backgroundImagePath)) {
108  $this->filesystem->copy($thumbnailImagePath, $exportPath . 'thumbnail.svg');
109  }
110  }
111 
112  $objectType = $this->objectHelper->lookupType($this->objectId);
113 
114  $zipFileName = $time . '__' . $installationId . '__' . $objectType . '__' . $this->objectId . '__certificate.zip';
115 
116 
117  $zipPath = $rootDir . $this->certificatePath . $zipFileName;
118  $this->utilHelper->zip($exportPath, $zipPath);
119  $this->filesystem->deleteDir($exportPath);
120 
121  $this->utilHelper->deliverFile($zipPath, $zipFileName, 'application/zip');
122  }
123 }
$template
$type
Class BaseForm.
$time
Definition: cron.php:21
export($rootDir=CLIENT_WEB_DIR, $installationId=IL_INST_ID)
Creates an downloadable file via the browser.
Just a wrapper class to create Unit Test for other classes.
__construct(int $objectId, string $certificatePath, ilCertificateTemplateRepository $templateRepository, Filesystem $filesystem, ilCertificateObjectHelper $objectHelper=null, ilCertificateUtilHelper $utilHelper=null)
Class FlySystemFileAccessTest.