ILIAS  release_8 Revision v8.24
ilCertificateBackgroundImageUpload Class Reference
+ Collaboration diagram for ilCertificateBackgroundImageUpload:

Public Member Functions

 __construct (FileUpload $fileUpload, string $certificatePath, ilLanguage $language, ilLogger $logger, ?Filesystem $fileSystem=null, ?ilCertificateUtilHelper $utilHelper=null, ?ilCertificateFileUtilsHelper $certificateFileUtilsHelper=null, ?LegacyPathHelperHelper $legacyPathHelper=null, string $rootDirectory=CLIENT_WEB_DIR, string $clientID=CLIENT_ID, ?Filesystem $tmp_file_system=null)
 
 uploadBackgroundImage (string $imageTempFilename, int $version, ?array $pending_file=null)
 Uploads a background image for the certificate. More...
 

Private Member Functions

 getTargetFilesystem (string $target)
 
 getTargetDir (string $target)
 
 createBackgroundImageTempfilePath (string $extension)
 Returns the filesystem path of the background image temp file during upload. More...
 
 createBackgroundImageThumbPath ()
 Returns the filesystem path of the background image thumbnail. More...
 

Private Attributes

const BACKGROUND_IMAGE_NAME = 'background.jpg'
 
const BACKGROUND_THUMBNAIL_IMAGE_NAME = 'background.jpg.thumb.jpg'
 
const BACKGROUND_TEMPORARY_FILENAME = 'background_upload_tmp'
 
FileUpload $fileUpload
 
string $certificatePath
 
ilLanguage $language
 
string $rootDirectory
 
Filesystem $fileSystem
 
ilCertificateUtilHelper $utilHelper
 
ilCertificateFileUtilsHelper $fileUtilsHelper
 
string $clientId
 
LegacyPathHelperHelper $legacyPathHelper
 
ilLogger $logger
 
Filesystem $tmp_file_system
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCertificateBackgroundImageUpload::__construct ( FileUpload  $fileUpload,
string  $certificatePath,
ilLanguage  $language,
ilLogger  $logger,
?Filesystem  $fileSystem = null,
?ilCertificateUtilHelper  $utilHelper = null,
?ilCertificateFileUtilsHelper  $certificateFileUtilsHelper = null,
?LegacyPathHelperHelper  $legacyPathHelper = null,
string  $rootDirectory = CLIENT_WEB_DIR,
string  $clientID = CLIENT_ID,
?Filesystem  $tmp_file_system = null 
)

Definition at line 49 of file class.ilCertificateBackgroundImageUpload.php.

61 {
62 $this->fileUpload = $fileUpload;
63 $this->certificatePath = $certificatePath;
64 $this->language = $language;
65 $this->logger = $logger;
66 $this->rootDirectory = $rootDirectory;
67
68 if (null === $fileSystem) {
69 global $DIC;
70 $fileSystem = $DIC->filesystem()->web();
71 }
72 $this->fileSystem = $fileSystem;
73
74 if (null === $utilHelper) {
76 }
77 $this->utilHelper = $utilHelper;
78
79 if (null === $certificateFileUtilsHelper) {
80 $certificateFileUtilsHelper = new ilCertificateFileUtilsHelper();
81 }
82 $this->fileUtilsHelper = $certificateFileUtilsHelper;
83
84 if (null === $legacyPathHelper) {
86 }
87 $this->legacyPathHelper = $legacyPathHelper;
88
89 $this->clientId = $clientID;
90
91 if (null === $tmp_file_system) {
92 global $DIC;
93 $tmp_file_system = $DIC->filesystem()->temp();
94 }
95 $this->tmp_file_system = $tmp_file_system;
96 }
Just a wrapper class to create Unit Test for other classes.
global $DIC
Definition: feed.php:28

References $certificatePath, $DIC, $fileSystem, $fileUpload, $language, $legacyPathHelper, $logger, $rootDirectory, $tmp_file_system, $utilHelper, ILIAS\UI\examples\Symbol\Glyph\Language\language(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

Member Function Documentation

◆ createBackgroundImageTempfilePath()

ilCertificateBackgroundImageUpload::createBackgroundImageTempfilePath ( string  $extension)
private

Returns the filesystem path of the background image temp file during upload.

Returns
string The filesystem path of the background image temp file

Definition at line 259 of file class.ilCertificateBackgroundImageUpload.php.

259 : string
260 {
261 return implode('', [
262 $this->rootDirectory,
263 $this->certificatePath,
264 self::BACKGROUND_TEMPORARY_FILENAME,
265 '.' . $extension
266 ]);
267 }

◆ createBackgroundImageThumbPath()

ilCertificateBackgroundImageUpload::createBackgroundImageThumbPath ( )
private

Returns the filesystem path of the background image thumbnail.

Returns
string The filesystem path of the background image thumbnail

Definition at line 273 of file class.ilCertificateBackgroundImageUpload.php.

273 : string
274 {
275 return $this->rootDirectory . $this->certificatePath . self::BACKGROUND_THUMBNAIL_IMAGE_NAME;
276 }

References BACKGROUND_THUMBNAIL_IMAGE_NAME.

Referenced by uploadBackgroundImage().

+ Here is the caller graph for this function:

◆ getTargetDir()

ilCertificateBackgroundImageUpload::getTargetDir ( string  $target)
private

Definition at line 249 of file class.ilCertificateBackgroundImageUpload.php.

249 : string
250 {
251 $absTargetDir = dirname($target);
252 return $this->legacyPathHelper->createRelativePath($absTargetDir);
253 }

◆ getTargetFilesystem()

ilCertificateBackgroundImageUpload::getTargetFilesystem ( string  $target)
private

Definition at line 225 of file class.ilCertificateBackgroundImageUpload.php.

225 : int
226 {
227 switch (true) {
228 case strpos($target, $this->rootDirectory . '/' . $this->clientId) === 0:
229 case strpos($target, './' . $this->rootDirectory . '/' . $this->clientId) === 0:
230 case strpos($target, $this->rootDirectory) === 0:
231 $targetFilesystem = Location::WEB;
232 break;
233 case strpos($target, CLIENT_DATA_DIR . "/temp") === 0:
234 $targetFilesystem = Location::TEMPORARY;
235 break;
236 case strpos($target, CLIENT_DATA_DIR) === 0:
237 $targetFilesystem = Location::STORAGE;
238 break;
239 case strpos($target, ILIAS_ABSOLUTE_PATH . '/Customizing') === 0:
240 $targetFilesystem = Location::CUSTOMIZING;
241 break;
242 default:
243 throw new InvalidArgumentException("Can not move files to \"$target\" because path can not be mapped to web, storage or customizing location.");
244 }
245
246 return $targetFilesystem;
247 }
const CLIENT_DATA_DIR
Definition: constants.php:46

References CLIENT_DATA_DIR.

◆ uploadBackgroundImage()

ilCertificateBackgroundImageUpload::uploadBackgroundImage ( string  $imageTempFilename,
int  $version,
?array  $pending_file = null 
)

Uploads a background image for the certificate.

Creates a new directory for the certificate if needed. Removes an existing certificate image if necessary

Parameters
string$imageTempFilenameName of the temporary uploaded image file
int$version- Version of the current certifcate template
array | null$pending_file
Returns
string An errorcode if the image upload fails, 0 otherwise
Exceptions
IllegalStateException
FileNotFoundException
IOException
ilException
ilFileUtilsException

Definition at line 111 of file class.ilCertificateBackgroundImageUpload.php.

111 : string
112 {
113 $imagepath = $this->rootDirectory . $this->certificatePath;
114
115 if (!$this->fileSystem->hasDir($imagepath)) {
116 ilFileUtils::makeDirParents($imagepath);
117 }
118
119 $backgroundImageTempFilePath = $this->uploadFile($imageTempFilename, $pending_file);
120
121 $backgroundImagePath = $this->certificatePath . 'background_' . $version . '.jpg';
122
123 $this->utilHelper->convertImage(
124 $backgroundImageTempFilePath,
125 $this->rootDirectory . $backgroundImagePath,
126 'JPEG'
127 );
128
129 $backgroundImageThumbnailPath = $this->createBackgroundImageThumbPath();
130
131 $this->utilHelper->convertImage(
132 $backgroundImageTempFilePath,
133 $backgroundImageThumbnailPath,
134 'JPEG',
135 "100"
136 );
137
138 $convert_filename = self::BACKGROUND_IMAGE_NAME;
139
140 // something went wrong converting the file. use the original file and hope, that PDF can work with it
141 if (!$this->fileSystem->has($backgroundImagePath) && !ilFileUtils::moveUploadedFile(
142 $backgroundImageTempFilePath,
143 $convert_filename,
144 $this->rootDirectory . $backgroundImagePath
145 )) {
146 throw new ilException('Unable to convert the file and the original file');
147 }
148
149 if ($this->fileSystem->has($backgroundImageTempFilePath)) {
150 $this->fileSystem->delete($backgroundImageTempFilePath);
151 }
152
153 if ($this->fileSystem->has($backgroundImagePath)) {
154 return $this->certificatePath . 'background_' . $version . '.jpg';
155 }
156
157 throw new ilException('The given temporary filename is empty');
158 }
$version
Definition: plugin.php:24
createBackgroundImageThumbPath()
Returns the filesystem path of the background image thumbnail.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file

References $certificatePath, $version, BACKGROUND_IMAGE_NAME, createBackgroundImageThumbPath(), ilFileUtils\makeDirParents(), and ilFileUtils\moveUploadedFile().

+ Here is the call graph for this function:

Field Documentation

◆ $certificatePath

string ilCertificateBackgroundImageUpload::$certificatePath
private

◆ $clientId

string ilCertificateBackgroundImageUpload::$clientId
private

Definition at line 44 of file class.ilCertificateBackgroundImageUpload.php.

◆ $fileSystem

Filesystem ilCertificateBackgroundImageUpload::$fileSystem
private

Definition at line 41 of file class.ilCertificateBackgroundImageUpload.php.

Referenced by __construct().

◆ $fileUpload

FileUpload ilCertificateBackgroundImageUpload::$fileUpload
private

Definition at line 37 of file class.ilCertificateBackgroundImageUpload.php.

Referenced by __construct().

◆ $fileUtilsHelper

ilCertificateFileUtilsHelper ilCertificateBackgroundImageUpload::$fileUtilsHelper
private

Definition at line 43 of file class.ilCertificateBackgroundImageUpload.php.

◆ $language

ilLanguage ilCertificateBackgroundImageUpload::$language
private

Definition at line 39 of file class.ilCertificateBackgroundImageUpload.php.

Referenced by __construct().

◆ $legacyPathHelper

LegacyPathHelperHelper ilCertificateBackgroundImageUpload::$legacyPathHelper
private

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

Referenced by __construct().

◆ $logger

ilLogger ilCertificateBackgroundImageUpload::$logger
private

Definition at line 46 of file class.ilCertificateBackgroundImageUpload.php.

Referenced by __construct().

◆ $rootDirectory

string ilCertificateBackgroundImageUpload::$rootDirectory
private

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

Referenced by __construct().

◆ $tmp_file_system

Filesystem ilCertificateBackgroundImageUpload::$tmp_file_system
private

Definition at line 47 of file class.ilCertificateBackgroundImageUpload.php.

Referenced by __construct().

◆ $utilHelper

ilCertificateUtilHelper ilCertificateBackgroundImageUpload::$utilHelper
private

Definition at line 42 of file class.ilCertificateBackgroundImageUpload.php.

Referenced by __construct().

◆ BACKGROUND_IMAGE_NAME

const ilCertificateBackgroundImageUpload::BACKGROUND_IMAGE_NAME = 'background.jpg'
private

Definition at line 34 of file class.ilCertificateBackgroundImageUpload.php.

Referenced by uploadBackgroundImage().

◆ BACKGROUND_TEMPORARY_FILENAME

const ilCertificateBackgroundImageUpload::BACKGROUND_TEMPORARY_FILENAME = 'background_upload_tmp'
private

Definition at line 36 of file class.ilCertificateBackgroundImageUpload.php.

◆ BACKGROUND_THUMBNAIL_IMAGE_NAME

const ilCertificateBackgroundImageUpload::BACKGROUND_THUMBNAIL_IMAGE_NAME = 'background.jpg.thumb.jpg'
private

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