ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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)
 
 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...
 
 getBackgroundImageDirectory (string $rootDir)
 
 getBackgroundImageThumbnailPath ()
 

Private Attributes

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

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 
)
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 69 of file class.ilCertificateTemplateImportAction.php.

79 {
80 $this->objectId = $objectId;
81 $this->certificatePath = $certificatePath;
82
83 $this->logger = $logger;
84 if (null === $database) {
85 global $DIC;
86 $database = $DIC->database();
87 }
88
89 $this->filesystem = $filesystem;
90
91 $this->placeholderDescriptionObject = $placeholderDescriptionObject;
92
93 if (null === $templateRepository) {
95 }
96 $this->templateRepository = $templateRepository;
97
98 if (null === $objectHelper) {
100 }
101 $this->objectHelper = $objectHelper;
102
103 if (null === $utilHelper) {
105 }
106 $this->utilHelper = $utilHelper;
107 }
Just a wrapper class to create Unit Test for other classes.
global $DIC
Definition: saml.php:7

References $certificatePath, $DIC, $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 265 of file class.ilCertificateTemplateImportAction.php.

265 : string
266 {
267 $type = $this->objectHelper->lookupType($this->objectId);
268 $certificateId = $this->objectId;
269
270 $dir = $this->certificatePath . time() . '__' . $installationID . '__' . $type . '__' . $certificateId . '__certificate/';
271 $this->filesystem->createDir($dir);
272
273 return $dir;
274 }
$type

References $installationID, $objectId, and $type.

Referenced by import().

+ Here is the caller graph for this function:

◆ getBackgroundImageDirectory()

ilCertificateTemplateImportAction::getBackgroundImageDirectory ( string  $rootDir)
private
Parameters
string$rootDir
Returns
mixed|string

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

281 : string
282 {
283 return str_replace(
284 array($rootDir, '//'),
285 array('[CLIENT_WEB_DIR]', '/'),
286 ''
287 );
288 }

Referenced by import().

+ Here is the caller graph for this function:

◆ getBackgroundImageThumbnailPath()

ilCertificateTemplateImportAction::getBackgroundImageThumbnailPath ( )
private
Returns
string

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

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

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 122 of file class.ilCertificateTemplateImportAction.php.

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

References $certificate, $filename, $result, $template, createArchiveDirectory(), getBackgroundImageDirectory(), getBackgroundImageThumbnailPath(), and GuzzleHttp\Psr7\hash().

+ 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().

◆ $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: