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

Public Member Functions

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

Data Fields

const BACKGROUND_IMAGE_NAME = 'background.jpg'
 
const BACKGROUND_THUMBNAIL_IMAGE_NAME = 'background.jpg.thumb.jpg'
 
const BACKGROUND_TEMPORARY_FILENAME = 'background_upload.tmp'
 

Private Member Functions

 getTargetFilesystem (string $target)
 
 getTargetDir (string $target)
 
 createBackgroundImageTempfilePath ()
 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

 $fileUpload
 
 $certificatePath
 
 $language
 
 $rootDirectory
 
 $fileSystem
 
 $utilHelper
 
 $fileUtilsHelper
 
 $clientId
 
 $legacyPathHelper
 
 $logger
 
 $tmp_file_system
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

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

81 {
82 $this->fileUpload = $fileUpload;
83 $this->certificatePath = $certificatePath;
84 $this->language = $language;
85 $this->logger = $logger;
86 $this->rootDirectory = $rootDirectory;
87
88 if (null === $fileSystem) {
89 global $DIC;
90 $fileSystem = $DIC->filesystem()->web();
91 }
92 $this->fileSystem = $fileSystem;
93
94 if (null === $utilHelper) {
96 }
97 $this->utilHelper = $utilHelper;
98
99 if (null === $certificateFileUtilsHelper) {
100 $certificateFileUtilsHelper = new ilCertificateFileUtilsHelper();
101 }
102 $this->fileUtilsHelper = $certificateFileUtilsHelper;
103
104 if (null === $legacyPathHelper) {
106 }
107 $this->legacyPathHelper = $legacyPathHelper;
108
109 $this->clientId = $clientID;
110
111 if (null === $tmp_file_system) {
112 global $DIC;
113 $tmp_file_system = $DIC->filesystem()->temp();
114 }
115 $this->tmp_file_system = $tmp_file_system;
116 }
Just a wrapper class to create Unit Test for other classes.
global $DIC
Definition: goto.php:24
language()
Definition: language.php:2

References $certificatePath, $DIC, $fileSystem, $fileUpload, $language, $legacyPathHelper, $logger, $rootDirectory, $tmp_file_system, $utilHelper, and language().

+ Here is the call graph for this function:

Member Function Documentation

◆ createBackgroundImageTempfilePath()

ilCertificateBackgroundImageUpload::createBackgroundImageTempfilePath ( )
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 274 of file class.ilCertificateBackgroundImageUpload.php.

275 {
276 return $this->rootDirectory . $this->certificatePath . self::BACKGROUND_TEMPORARY_FILENAME;
277 }

References BACKGROUND_TEMPORARY_FILENAME.

Referenced by uploadBackgroundImage().

+ Here is the caller graph for this function:

◆ 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 284 of file class.ilCertificateBackgroundImageUpload.php.

285 {
286 return $this->rootDirectory . $this->certificatePath . self::BACKGROUND_THUMBNAIL_IMAGE_NAME;
287 }

References BACKGROUND_THUMBNAIL_IMAGE_NAME.

Referenced by uploadBackgroundImage().

+ Here is the caller graph for this function:

◆ getTargetDir()

ilCertificateBackgroundImageUpload::getTargetDir ( string  $target)
private
Parameters
$target
Returns
array

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

262 {
263 $absTargetDir = dirname($target);
264 $targetDir = $this->legacyPathHelper->createRelativePath($absTargetDir);
265
266 return $targetDir;
267 }

◆ getTargetFilesystem()

ilCertificateBackgroundImageUpload::getTargetFilesystem ( string  $target)
private
Parameters
string$target
Returns
int

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

234 {
235 switch (true) {
236 case strpos($target, $this->rootDirectory . '/' . $this->clientId) === 0:
237 case strpos($target, './' . $this->rootDirectory . '/' . $this->clientId) === 0:
238 case strpos($target, $this->rootDirectory) === 0:
239 $targetFilesystem = \ILIAS\FileUpload\Location::WEB;
240 break;
241 case strpos($target, CLIENT_DATA_DIR . "/temp") === 0:
242 $targetFilesystem = \ILIAS\FileUpload\Location::TEMPORARY;
243 break;
244 case strpos($target, CLIENT_DATA_DIR) === 0:
245 $targetFilesystem = \ILIAS\FileUpload\Location::STORAGE;
246 break;
247 case strpos($target, ILIAS_ABSOLUTE_PATH . '/Customizing') === 0:
248 $targetFilesystem = \ILIAS\FileUpload\Location::CUSTOMIZING;
249 break;
250 default:
251 throw new InvalidArgumentException("Can not move files to \"$target\" because path can not be mapped to web, storage or customizing location.");
252 }
253
254 return $targetFilesystem;
255 }
const CLIENT_DATA_DIR
Definition: constants.php:44
const TEMPORARY
The ILIAS temporary directory.
Definition: Location.php:38
const CUSTOMIZING
The filesystem within the web root where all the skins and plugins are saved.
Definition: Location.php:33
const WEB
The filesystem within the ilias web root.
Definition: Location.php:23
const STORAGE
The filesystem outside of the ilias web root.
Definition: Location.php:28

References CLIENT_DATA_DIR, ILIAS\FileUpload\Location\CUSTOMIZING, ILIAS\FileUpload\Location\STORAGE, ILIAS\FileUpload\Location\TEMPORARY, and ILIAS\FileUpload\Location\WEB.

◆ 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
integer An errorcode if the image upload fails, 0 otherwise
Exceptions

ILIAS\FileUpload\Exception\IllegalStateException

Exceptions

ILIAS\Filesystem\Exception\FileNotFoundException

Exceptions

ILIAS\Filesystem\Exception\IOException

Exceptions
ilException
ilFileUtilsException

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

133 {
134 $imagepath = $this->rootDirectory . $this->certificatePath;
135
136 if (!$this->fileSystem->hasDir($imagepath)) {
137 ilUtil::makeDirParents($imagepath);
138 }
139
140 $backgroundImageTempFilePath = $this->createBackgroundImageTempfilePath();
141
142 $this->uploadFile($imageTempFilename, $backgroundImageTempFilePath, $pending_file);
143
144 $backgroundImagePath = $this->certificatePath . 'background_' . $version . '.jpg';
145
146 $this->utilHelper->convertImage(
147 $backgroundImageTempFilePath,
148 $this->rootDirectory . $backgroundImagePath,
149 'JPEG'
150 );
151
152 $backgroundImageThumbnailPath = $this->createBackgroundImageThumbPath();
153
154 $this->utilHelper->convertImage(
155 $backgroundImageTempFilePath,
156 $backgroundImageThumbnailPath,
157 'JPEG',
158 100
159 );
160
161 $convert_filename = self::BACKGROUND_IMAGE_NAME;
162
163 if (!$this->fileSystem->has($backgroundImagePath)) {
164 // something went wrong converting the file. use the original file and hope, that PDF can work with it
165 if (!ilUtil::moveUploadedFile($backgroundImageTempFilePath, $convert_filename, $this->rootDirectory . $backgroundImagePath)) {
166 throw new ilException('Unable to convert the file and the original file');
167 }
168 }
169
170 $this->fileSystem->delete($this->certificatePath . self::BACKGROUND_TEMPORARY_FILENAME);
171
172 if ($this->fileSystem->has($backgroundImagePath)) {
173 return $this->certificatePath . 'background_' . $version . '.jpg';
174 }
175
176 throw new ilException('The given temporary filename is empty');
177 }
createBackgroundImageThumbPath()
Returns the filesystem path of the background image thumbnail.
createBackgroundImageTempfilePath()
Returns the filesystem path of the background image temp file during upload.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static makeDirParents($a_dir)
Create a new directory and all parent directories.

References $certificatePath, BACKGROUND_IMAGE_NAME, createBackgroundImageTempfilePath(), createBackgroundImageThumbPath(), ilUtil\makeDirParents(), and ilUtil\moveUploadedFile().

+ Here is the call graph for this function:

Field Documentation

◆ $certificatePath

ilCertificateBackgroundImageUpload::$certificatePath
private

◆ $clientId

ilCertificateBackgroundImageUpload::$clientId
private

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

◆ $fileSystem

ilCertificateBackgroundImageUpload::$fileSystem
private

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

Referenced by __construct().

◆ $fileUpload

ilCertificateBackgroundImageUpload::$fileUpload
private

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

Referenced by __construct().

◆ $fileUtilsHelper

ilCertificateBackgroundImageUpload::$fileUtilsHelper
private

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

◆ $language

ilCertificateBackgroundImageUpload::$language
private

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

Referenced by __construct().

◆ $legacyPathHelper

ilCertificateBackgroundImageUpload::$legacyPathHelper
private

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

Referenced by __construct().

◆ $logger

ilCertificateBackgroundImageUpload::$logger
private

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

Referenced by __construct().

◆ $rootDirectory

ilCertificateBackgroundImageUpload::$rootDirectory
private

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

Referenced by __construct().

◆ $tmp_file_system

ilCertificateBackgroundImageUpload::$tmp_file_system
private

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

Referenced by __construct().

◆ $utilHelper

ilCertificateBackgroundImageUpload::$utilHelper
private

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

Referenced by __construct().

◆ BACKGROUND_IMAGE_NAME

const ilCertificateBackgroundImageUpload::BACKGROUND_IMAGE_NAME = 'background.jpg'

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

Referenced by uploadBackgroundImage().

◆ BACKGROUND_TEMPORARY_FILENAME

const ilCertificateBackgroundImageUpload::BACKGROUND_TEMPORARY_FILENAME = 'background_upload.tmp'

◆ BACKGROUND_THUMBNAIL_IMAGE_NAME

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

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