ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilCertificateTemplateExportAction.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 
31 {
34 
35  public function __construct(
36  private readonly int $objectId,
37  private readonly string $certificatePath,
38  private readonly ilCertificateTemplateRepository $templateRepository,
39  private readonly Filesystem $filesystem,
40  ?ilCertificateObjectHelper $objectHelper = null,
41  ?ilCertificateUtilHelper $utilHelper = null
42  ) {
43  if (null === $objectHelper) {
44  $objectHelper = new ilCertificateObjectHelper();
45  }
46  $this->objectHelper = $objectHelper;
47 
48  if (null === $utilHelper) {
49  $utilHelper = new ilCertificateUtilHelper();
50  }
51  $this->utilHelper = $utilHelper;
52  }
53 
60  public function export(string $rootDir = CLIENT_WEB_DIR, string $installationId = IL_INST_ID): void
61  {
62  $time = time();
63 
64  $type = $this->objectHelper->lookupType($this->objectId);
65  $certificateId = $this->objectId;
66 
67  $exportPath = $this->certificatePath . $time . '__' . $installationId . '__' . $type . '__' . $certificateId . '__certificate/';
68 
69  $streams = [];
70 
71  $template = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
72 
73  $streams['certificate.xml'] = Streams::ofString(
74  $template->getCertificateContent()
75  );
76 
77  $backgroundImagePath = $template->getBackgroundImagePath();
78  if ($backgroundImagePath !== '' && $this->filesystem->has($backgroundImagePath)) {
79  $streams['background.jpg'] = $this->filesystem->readStream($backgroundImagePath);
80  }
81 
82  $thumbnailImagePath = $template->getThumbnailImagePath();
83  if ($thumbnailImagePath !== '' && $this->filesystem->has($backgroundImagePath)) {
84  $streams['thumbnail.svg'] = $this->filesystem->readStream($thumbnailImagePath);
85  }
86 
87  $objectType = $this->objectHelper->lookupType($this->objectId);
88 
89  $zipFileName = $time . '__' . $installationId . '__' . $objectType . '__' . $this->objectId . '__certificate.zip';
90 
91  $this->utilHelper->zipAndDeliver($streams, $zipFileName);
92  }
93 }
const IL_INST_ID
Definition: constants.php:40
export(string $rootDir=CLIENT_WEB_DIR, string $installationId=IL_INST_ID)
Creates a downloadable file via the browser.
const CLIENT_WEB_DIR
Definition: constants.php:47
Just a wrapper class to create Unit Test for other classes.
__construct(private readonly int $objectId, private readonly string $certificatePath, private readonly ilCertificateTemplateRepository $templateRepository, private readonly Filesystem $filesystem, ?ilCertificateObjectHelper $objectHelper=null, ?ilCertificateUtilHelper $utilHelper=null)