19 declare(strict_types=1);
37 private readonly
int $objectId,
38 private readonly
string $certificatePath,
48 if (null === $database) {
50 $database = $DIC->database();
53 if (null === $templateRepository) {
58 if (null === $objectHelper) {
63 if (null === $utilHelper) {
68 if (null === $fileService) {
84 public function import(
93 $clean_up_import_dir =
function () use (&$importPath) {
99 $this->
logger->error(sprintf(
"Can't clean up import directory: %s", $e->getMessage()));
100 $this->
logger->error($e->getTraceAsString());
104 $result = $this->utilHelper->moveUploadedFile($zipFile, $filename, $rootDir . $importPath . $filename);
106 $clean_up_import_dir();
110 $destination_dir = $rootDir . $importPath;
111 $unzip = $this->utilHelper->unzip(
112 $rootDir . $importPath . $filename,
117 $unzipped = $unzip->extract();
123 $clean_up_import_dir();
127 if ($this->
filesystem->has($importPath . $filename)) {
128 $this->
filesystem->delete($importPath . $filename);
132 $contents = $this->
filesystem->listContents($importPath);
133 foreach ($contents as $file) {
134 if ($file->isFile() && str_contains($file->getPath(),
'.xml')) {
139 if (0 === $xmlFiles) {
143 $certificate = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
145 $currentVersion = $certificate->getVersion();
146 $newVersion = $currentVersion + 1;
147 $backgroundImagePath = $certificate->getBackgroundImagePath();
148 $cardThumbnailImagePath = $certificate->getThumbnailImagePath();
149 $xsl = $certificate->getCertificateContent();
151 foreach ($contents as $file) {
152 if (!$file->isFile()) {
156 if (str_contains($file->getPath(),
'.xml')) {
157 $xsl = $this->
filesystem->read($file->getPath());
160 $xsl = preg_replace_callback(
161 "/url\([']{0,1}(.*?)[']{0,1}\)/",
162 function (array $matches) use ($rootDir):
string {
163 $basePath = rtrim(dirname($this->fileService->getBackgroundImageDirectory($rootDir)),
'/');
164 $fileName = basename($matches[1]);
166 if (
'[BACKGROUND_IMAGE]' === $fileName) {
168 } elseif ($basePath !==
'') {
172 return 'url(' . $basePath . $fileName .
')';
176 } elseif (str_contains($file->getPath(),
'.jpg')) {
177 $newBackgroundImageName =
'background_' . $newVersion .
'.jpg';
178 $newPath = $this->certificatePath . $newBackgroundImageName;
179 $this->
filesystem->copy($file->getPath(), $newPath);
181 $backgroundImagePath = $this->certificatePath . $newBackgroundImageName;
186 $thumbnailImagePath = $rootDir . $backgroundImageThumbPath;
188 $originalImagePath = $rootDir . $newPath;
189 $this->utilHelper->convertImage(
194 } elseif (str_contains($file->getPath(),
'.svg')) {
195 $newCardThumbnailName =
'thumbnail_' . $newVersion .
'.svg';
196 $newPath = $this->certificatePath . $newCardThumbnailName;
198 $this->
filesystem->copy($file->getPath(), $newPath);
200 $cardThumbnailImagePath = $this->certificatePath . $newCardThumbnailName;
204 $jsonEncodedTemplateValues = json_encode(
205 $this->placeholderDescriptionObject->getPlaceholderDescriptions(),
209 $newHashValue =
hash(
213 $backgroundImagePath,
214 $jsonEncodedTemplateValues,
215 $cardThumbnailImagePath
221 $this->objectHelper->lookupType($this->objectId),
224 $jsonEncodedTemplateValues,
229 $backgroundImagePath,
230 $cardThumbnailImagePath
233 $this->templateRepository->save($template);
235 $clean_up_import_dir();
247 $type = $this->objectHelper->lookupType($this->objectId);
248 $certificateId = $this->objectId;
250 $dir = $this->certificatePath . time() .
'__' . $installationID .
'__' . $type .
'__' . $certificateId .
'__certificate/';
261 return $this->certificatePath .
'background.jpg.thumb.jpg';
const ILIAS_VERSION_NUMERIC
__construct(private readonly int $objectId, private readonly string $certificatePath, private readonly ilCertificatePlaceholderDescription $placeholderDescriptionObject, private readonly ilLogger $logger, private readonly Filesystem $filesystem, ?ilCertificateTemplateRepository $templateRepository=null, ?ilCertificateObjectHelper $objectHelper=null, ?ilCertificateUtilHelper $utilHelper=null, ?ilDBInterface $database=null, ?ilCertificateBackgroundImageFileService $fileService=null)
readonly ilCertificateBackgroundImageFileService $fileService
readonly ilCertificateObjectHelper $objectHelper
readonly ilCertificateUtilHelper $utilHelper
getBackgroundImageThumbnailPath()
readonly ilCertificateTemplateRepository $templateRepository
Just a wrapper class to create Unit Test for other classes.
createArchiveDirectory(string $installationID)
Creates a directory for a zip archive containing multiple certificates.