ILIAS  release_8 Revision v8.24
class.ilCertificateTemplateExportAction.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25
30{
31 private int $objectId;
32 private string $certificatePath;
37
38 public function __construct(
39 int $objectId,
40 string $certificatePath,
45 ) {
46 $this->objectId = $objectId;
47 $this->certificatePath = $certificatePath;
48 $this->templateRepository = $templateRepository;
49 $this->filesystem = $filesystem;
50
51 if (null === $objectHelper) {
53 }
54 $this->objectHelper = $objectHelper;
55
56 if (null === $utilHelper) {
58 }
59 $this->utilHelper = $utilHelper;
60 }
61
70 public function export(string $rootDir = CLIENT_WEB_DIR, string $installationId = IL_INST_ID): void
71 {
72 $time = time();
73
74 $type = $this->objectHelper->lookupType($this->objectId);
75 $certificateId = $this->objectId;
76
77 $exportPath = $this->certificatePath . $time . '__' . $installationId . '__' . $type . '__' . $certificateId . '__certificate/';
78
79 $this->filesystem->createDir($exportPath);
80
81 $template = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
82
83 $xslContent = $template->getCertificateContent();
84
85 $this->filesystem->put($exportPath . 'certificate.xml', $xslContent);
86
87 $backgroundImagePath = $template->getBackgroundImagePath();
88 if ($backgroundImagePath !== '' && true === $this->filesystem->has($backgroundImagePath)) {
89 $this->filesystem->copy($backgroundImagePath, $exportPath . 'background.jpg');
90 }
91
92 $thumbnailImagePath = $template->getThumbnailImagePath();
93 if ($thumbnailImagePath !== '' && true === $this->filesystem->has($backgroundImagePath)) {
94 $this->filesystem->copy($thumbnailImagePath, $exportPath . 'thumbnail.svg');
95 }
96
97 $objectType = $this->objectHelper->lookupType($this->objectId);
98
99 $zipFileName = $time . '__' . $installationId . '__' . $objectType . '__' . $this->objectId . '__certificate.zip';
100
101 $zipPath = $rootDir . $this->certificatePath . $zipFileName;
102 $this->utilHelper->zip($exportPath, $zipPath);
103 $this->filesystem->deleteDir($exportPath);
104
105 $this->utilHelper->deliverFile($zipPath, $zipFileName, 'application/zip');
106 }
107}
export(string $rootDir=CLIENT_WEB_DIR, string $installationId=IL_INST_ID)
Creates a downloadable file via the browser.
__construct(int $objectId, string $certificatePath, ilCertificateTemplateRepository $templateRepository, Filesystem $filesystem, ?ilCertificateObjectHelper $objectHelper=null, ?ilCertificateUtilHelper $utilHelper=null)
Just a wrapper class to create Unit Test for other classes.
const CLIENT_WEB_DIR
Definition: constants.php:47
const IL_INST_ID
Definition: constants.php:40
Interface Filesystem.
Definition: Filesystem.php:40
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...
$type