ILIAS  release_7 Revision v7.30-3-g800a261c036
ilCertificateTemplateImportAction Class Reference
+ Collaboration diagram for ilCertificateTemplateImportAction:

Public Member Functions

 __construct (int $objectId, string $certificatePath, ilCertificatePlaceholderDescription $placeholderDescriptionObject, ilLogger $logger, Filesystem $filesystem, ilCertificateTemplateRepository $templateRepository=null, ilCertificateObjectHelper $objectHelper=null, ilCertificateUtilHelper $utilHelper=null, ilDBInterface $database=null, ilCertificateBackgroundImageFileService $fileService=null)
 
 import (string $zipFile, string $filename, string $rootDir=CLIENT_WEB_DIR, string $iliasVerision=ILIAS_VERSION_NUMERIC, string $installationID=IL_INST_ID)
 

Private Member Functions

 createArchiveDirectory (string $installationID)
 Creates a directory for a zip archive containing multiple certificates. More...
 
 getBackgroundImageThumbnailPath ()
 

Private Attributes

 $objectId
 
 $certificatePath
 
 $templateRepository
 
 $placeholderDescriptionObject
 
 $logger
 
 $filesystem
 
 $objectHelper
 
 $utilHelper
 
 $installationID
 
 $fileService
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCertificateTemplateImportAction::__construct ( int  $objectId,
string  $certificatePath,
ilCertificatePlaceholderDescription  $placeholderDescriptionObject,
ilLogger  $logger,
Filesystem  $filesystem,
ilCertificateTemplateRepository  $templateRepository = null,
ilCertificateObjectHelper  $objectHelper = null,
ilCertificateUtilHelper  $utilHelper = null,
ilDBInterface  $database = null,
ilCertificateBackgroundImageFileService  $fileService = null 
)
Parameters
integer$objectId
string$certificatePath
ilCertificatePlaceholderDescription$placeholderDescriptionObject
ilLogger$logger
Filesystem | null$filesystem
ilCertificateTemplateRepository | null$templateRepository
ilCertificateObjectHelper | null$objectHelper
ilCertificateUtilHelper | null$utilHelper
ilDBInterface | null$database
string$installationID

Definition at line 74 of file class.ilCertificateTemplateImportAction.php.

85 {
86 $this->objectId = $objectId;
87 $this->certificatePath = $certificatePath;
88
89 $this->logger = $logger;
90 if (null === $database) {
91 global $DIC;
92 $database = $DIC->database();
93 }
94
95 $this->filesystem = $filesystem;
96
97 $this->placeholderDescriptionObject = $placeholderDescriptionObject;
98
99 if (null === $templateRepository) {
101 }
102 $this->templateRepository = $templateRepository;
103
104 if (null === $objectHelper) {
106 }
107 $this->objectHelper = $objectHelper;
108
109 if (null === $utilHelper) {
111 }
112 $this->utilHelper = $utilHelper;
113
114 if (null === $fileService) {
118 );
119 }
120 $this->fileService = $fileService;
121 }
Just a wrapper class to create Unit Test for other classes.
global $DIC
Definition: goto.php:24

References $certificatePath, $DIC, $fileService, $filesystem, $logger, $objectHelper, $objectId, $placeholderDescriptionObject, $templateRepository, and $utilHelper.

Member Function Documentation

◆ createArchiveDirectory()

ilCertificateTemplateImportAction::createArchiveDirectory ( string  $installationID)
private

Creates a directory for a zip archive containing multiple certificates.

Parameters
string$installationID
Returns
string The created archive directory
Exceptions

ILIAS\Filesystem\Exception\IOException

Definition at line 279 of file class.ilCertificateTemplateImportAction.php.

279 : string
280 {
281 $type = $this->objectHelper->lookupType($this->objectId);
282 $certificateId = $this->objectId;
283
284 $dir = $this->certificatePath . time() . '__' . $installationID . '__' . $type . '__' . $certificateId . '__certificate/';
285 $this->filesystem->createDir($dir);
286
287 return $dir;
288 }
$type

References $installationID, $objectId, and $type.

Referenced by import().

+ Here is the caller graph for this function:

◆ getBackgroundImageThumbnailPath()

ilCertificateTemplateImportAction::getBackgroundImageThumbnailPath ( )
private
Returns
string

Definition at line 294 of file class.ilCertificateTemplateImportAction.php.

294 : string
295 {
296 return $this->certificatePath . 'background.jpg.thumb.jpg';
297 }

Referenced by import().

+ Here is the caller graph for this function:

◆ import()

ilCertificateTemplateImportAction::import ( string  $zipFile,
string  $filename,
string  $rootDir = CLIENT_WEB_DIR,
string  $iliasVerision = ILIAS_VERSION_NUMERIC,
string  $installationID = IL_INST_ID 
)
Parameters
string$zipFile
string$filename
string$rootDir
string$iliasVerision
string$installationID
Returns
bool
Exceptions

ILIAS\Filesystem\Exception\FileAlreadyExistsException

Exceptions

ILIAS\Filesystem\Exception\FileNotFoundException

Exceptions

ILIAS\Filesystem\Exception\IOException

Exceptions
ilDatabaseException
ilException

Definition at line 136 of file class.ilCertificateTemplateImportAction.php.

142 {
143 $importPath = $this->createArchiveDirectory($installationID);
144
145 $result = $this->utilHelper->moveUploadedFile($zipFile, $filename, $rootDir . $importPath . $filename);
146
147 if (!$result) {
148 $this->filesystem->deleteDir($importPath);
149 return false;
150 }
151
152 $this->utilHelper->unzip(
153 $rootDir . $importPath . $filename,
154 true
155 );
156
157 $subDirectoryName = str_replace('.zip', '', strtolower($filename)) . '/';
158 $subDirectoryAbsolutePath = $rootDir . $importPath . $subDirectoryName;
159
160 $copyDirectory = $importPath;
161 if (is_dir($subDirectoryAbsolutePath)) {
162 $copyDirectory = $subDirectoryAbsolutePath;
163 }
164
165 $directoryInformation = $this->utilHelper->getDir($copyDirectory);
166
167 $xmlFiles = 0;
168 foreach ($directoryInformation as $file) {
169 if (strcmp($file['type'], 'file') == 0) {
170 if (strpos($file['entry'], '.xml') !== false) {
171 $xmlFiles++;
172 }
173 }
174 }
175
176 if (0 === $xmlFiles) {
177 $this->filesystem->deleteDir($importPath);
178 return false;
179 }
180
181 $certificate = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
182
183 $currentVersion = (int) $certificate->getVersion();
184 $newVersion = $currentVersion + 1;
185 $backgroundImagePath = $certificate->getBackgroundImagePath();
186 $cardThumbnailImagePath = $certificate->getThumbnailImagePath();
187
188 $xsl = $certificate->getCertificateContent();
189
190 foreach ($directoryInformation as $file) {
191 if (strcmp($file['type'], 'file') == 0) {
192 $filePath = $importPath . $subDirectoryName . $file['entry'];
193 if (strpos($file['entry'], '.xml') !== false) {
194 $xsl = $this->filesystem->read($filePath);
195 // as long as we cannot make RPC calls in a given directory, we have
196 // to add the complete path to every url
197 $xsl = preg_replace_callback("/url\‍([']{0,1}(.*?)[']{0,1}\‍)/", function (array $matches) use ($rootDir) {
198 $basePath = rtrim(dirname($this->fileService->getBackgroundImageDirectory($rootDir)), '/');
199 $fileName = basename($matches[1]);
200
201 if ('[BACKGROUND_IMAGE]' === $fileName) {
202 $basePath = '';
203 } elseif (strlen($basePath) > 0) {
204 $basePath .= '/';
205 }
206
207 return 'url(' . $basePath . $fileName . ')';
208 }, $xsl);
209 } elseif (strpos($file['entry'], '.jpg') !== false) {
210 $newBackgroundImageName = 'background_' . $newVersion . '.jpg';
211 $newPath = $this->certificatePath . $newBackgroundImageName;
212 $this->filesystem->copy($filePath, $newPath);
213
214 $backgroundImagePath = $this->certificatePath . $newBackgroundImageName;
215 // upload of the background image, create a thumbnail
216
217 $backgroundImageThumbPath = $this->getBackgroundImageThumbnailPath();
218
219 $thumbnailImagePath = $rootDir . $backgroundImageThumbPath;
220
221 $originalImagePath = $rootDir . $newPath;
222 $this->utilHelper->convertImage(
223 $originalImagePath,
224 $thumbnailImagePath,
225 'JPEG',
226 100
227 );
228 } elseif (strpos($file['entry'], '.svg') !== false) {
229 $newCardThumbnailName = 'thumbnail_' . $newVersion . '.svg';
230 $newPath = $this->certificatePath . $newCardThumbnailName;
231
232 $this->filesystem->copy($filePath, $newPath);
233
234 $cardThumbnailImagePath = $this->certificatePath . $newCardThumbnailName;
235 }
236 }
237 }
238
239 $jsonEncodedTemplateValues = json_encode($this->placeholderDescriptionObject->getPlaceholderDescriptions());
240
241 $newHashValue = hash(
242 'sha256',
243 implode('', array(
244 $xsl,
245 $backgroundImagePath,
246 $jsonEncodedTemplateValues,
247 $cardThumbnailImagePath
248 ))
249 );
250
251 $template = new ilCertificateTemplate(
252 $this->objectId,
253 $this->objectHelper->lookupType($this->objectId),
254 $xsl,
255 $newHashValue,
256 $jsonEncodedTemplateValues,
257 $newVersion,
258 $iliasVerision,
259 time(),
260 true,
261 $backgroundImagePath,
262 $cardThumbnailImagePath
263 );
264
265 $this->templateRepository->save($template);
266
267 $this->filesystem->deleteDir($importPath);
268
269 return true;
270 }
$result
$filename
Definition: buildRTE.php:89
createArchiveDirectory(string $installationID)
Creates a directory for a zip archive containing multiple certificates.

References $filename, $result, createArchiveDirectory(), and getBackgroundImageThumbnailPath().

+ Here is the call graph for this function:

Field Documentation

◆ $certificatePath

ilCertificateTemplateImportAction::$certificatePath
private

Definition at line 20 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().

◆ $fileService

ilCertificateTemplateImportAction::$fileService
private

Definition at line 60 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().

◆ $filesystem

ilCertificateTemplateImportAction::$filesystem
private

Definition at line 40 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().

◆ $installationID

ilCertificateTemplateImportAction::$installationID
private

Definition at line 55 of file class.ilCertificateTemplateImportAction.php.

Referenced by createArchiveDirectory().

◆ $logger

ilCertificateTemplateImportAction::$logger
private

Definition at line 35 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().

◆ $objectHelper

ilCertificateTemplateImportAction::$objectHelper
private

Definition at line 45 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().

◆ $objectId

ilCertificateTemplateImportAction::$objectId
private

◆ $placeholderDescriptionObject

ilCertificateTemplateImportAction::$placeholderDescriptionObject
private

Definition at line 30 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().

◆ $templateRepository

ilCertificateTemplateImportAction::$templateRepository
private

Definition at line 25 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().

◆ $utilHelper

ilCertificateTemplateImportAction::$utilHelper
private

Definition at line 50 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().


The documentation for this class was generated from the following file: