ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCertificateTemplateExportAction.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27
32{
35
36 public function __construct(
37 private readonly int $objectId,
38 private readonly string $certificatePath,
39 private readonly ilCertificateTemplateRepository $templateRepository,
40 private readonly IRSS $irss,
43 ) {
44 if (null === $objectHelper) {
46 }
47 $this->objectHelper = $objectHelper;
48
49 if (null === $utilHelper) {
51 }
52 $this->utilHelper = $utilHelper;
53 }
54
58 public function export(string $rootDir = CLIENT_WEB_DIR, string $installationId = IL_INST_ID): void
59 {
60 $time = time();
61
62 $type = $this->objectHelper->lookupType($this->objectId);
63 $certificateId = $this->objectId;
64
65 $exportPath = $this->certificatePath . $time . '__' . $installationId . '__' . $type . '__' . $certificateId . '__certificate/';
66
67 $streams = [];
68
69 $template = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
70
71 $streams['certificate.xml'] = Streams::ofString(
72 $template->getCertificateContent()
73 );
74
75 $background_rid = $this->irss->manage()->find($template->getBackgroundImageIdentification());
76 if ($background_rid instanceof ResourceIdentification) {
77 $streams['background.jpg'] = $this->irss->consume()->stream($background_rid)->getStream();
78 }
79
80 $tile_image_rid = $this->irss->manage()->find($template->getTileImageIdentification());
81 if ($tile_image_rid instanceof ResourceIdentification) {
82 $streams['tile_image.svg'] = $this->irss->consume()->stream($tile_image_rid)->getStream();
83 }
84
85 $objectType = $this->objectHelper->lookupType($this->objectId);
86
87 $zipFileName = $time . '__' . $installationId . '__' . $objectType . '__' . $this->objectId . '__certificate.zip';
88
89 $this->utilHelper->zipAndDeliver($streams, $zipFileName);
90 }
91}
Indicates that a file is missing or not found.
Indicates general problems with the input or output operations.
Definition: IOException.php:28
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
export(string $rootDir=CLIENT_WEB_DIR, string $installationId=IL_INST_ID)
Creates a downloadable file via the browser.
__construct(private readonly int $objectId, private readonly string $certificatePath, private readonly ilCertificateTemplateRepository $templateRepository, private readonly IRSS $irss, ?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