ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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.

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

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) {
95  $utilHelper = new ilCertificateUtilHelper();
96  }
97  $this->utilHelper = $utilHelper;
98 
99  if (null === $certificateFileUtilsHelper) {
100  $certificateFileUtilsHelper = new ilCertificateFileUtilsHelper();
101  }
102  $this->fileUtilsHelper = $certificateFileUtilsHelper;
103 
104  if (null === $legacyPathHelper) {
105  $legacyPathHelper = new LegacyPathHelperHelper();
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.
$DIC
Definition: xapitoken.php:46
language()
Definition: language.php:2
+ 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.

Referenced by uploadBackgroundImage().

275  {
276  return $this->rootDirectory . $this->certificatePath . self::BACKGROUND_TEMPORARY_FILENAME;
277  }
+ 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.

Referenced by uploadBackgroundImage().

285  {
286  return $this->rootDirectory . $this->certificatePath . self::BACKGROUND_THUMBNAIL_IMAGE_NAME;
287  }
+ 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.

Referenced by uploadBackgroundImage().

262  {
263  $absTargetDir = dirname($target);
264  $targetDir = $this->legacyPathHelper->createRelativePath($absTargetDir);
265 
266  return $targetDir;
267  }
+ Here is the caller graph for this function:

◆ getTargetFilesystem()

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

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

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

Referenced by uploadBackgroundImage().

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 STORAGE
The filesystem outside of the ilias web root.
Definition: Location.php:28
const CUSTOMIZING
The filesystem within the web root where all the skins and plugins are saved.
Definition: Location.php:33
const TEMPORARY
The ILIAS temporary directory.
Definition: Location.php:38
const WEB
The filesystem within the ilias web root.
Definition: Location.php:23
+ Here is the caller graph for this function:

◆ 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

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

References $certificatePath, createBackgroundImageTempfilePath(), createBackgroundImageThumbPath(), getTargetDir(), getTargetFilesystem(), language(), ilUtil\makeDirParents(), ilUtil\moveUploadedFile(), and ILIAS\FileUpload\DTO\ProcessingStatus\REJECTED.

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  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
createBackgroundImageTempfilePath()
Returns the filesystem path of the background image temp file during upload.
createBackgroundImageThumbPath()
Returns the filesystem path of the background image thumbnail.
+ 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.

◆ BACKGROUND_TEMPORARY_FILENAME

const ilCertificateBackgroundImageUpload::BACKGROUND_TEMPORARY_FILENAME = 'background_upload.tmp'

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

◆ BACKGROUND_THUMBNAIL_IMAGE_NAME

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

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


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