ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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)
 
 uploadBackgroundImage (string $imageTempFilename, int $version)
 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
 

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 
)
Parameters
\ILIAS\FileUpload\FileUpload$fileUpload
string$certificatePath
ilLanguage$language
ilLogger$logger
\ILIAS\Filesystem\Filesystem | null$fileSystem
ilCertificateUtilHelper | null$utilHelper
ilCertificateFileUtilsHelper | null$certificateFileUtilsHelper
LegacyPathHelperHelper | null$legacyPathHelper
string$rootDirectory
string$clientID

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

References $certificatePath, $DIC, $fileSystem, $fileUpload, $language, $legacyPathHelper, $rootDirectory, and $utilHelper.

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  }
global $DIC
Definition: saml.php:7
Just a wrapper class to create Unit Test for other classes.

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

Referenced by uploadBackgroundImage().

261  {
262  return $this->rootDirectory . $this->certificatePath . self::BACKGROUND_TEMPORARY_FILENAME;
263  }
+ 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 270 of file class.ilCertificateBackgroundImageUpload.php.

Referenced by uploadBackgroundImage().

271  {
272  return $this->rootDirectory . $this->certificatePath . self::BACKGROUND_THUMBNAIL_IMAGE_NAME;
273  }
+ Here is the caller graph for this function:

◆ getTargetDir()

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

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

Referenced by uploadBackgroundImage().

248  {
249  $absTargetDir = dirname($target);
250  $targetDir = $this->legacyPathHelper->createRelativePath($absTargetDir);
251 
252  return $targetDir;
253  }
$target
Definition: test.php:19
+ Here is the caller graph for this function:

◆ getTargetFilesystem()

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

Definition at line 219 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().

220  {
221  switch (true) {
222  case strpos($target, $this->rootDirectory . '/' . $this->clientId) === 0:
223  case strpos($target, './' . $this->rootDirectory . '/' . $this->clientId) === 0:
224  case strpos($target, $this->rootDirectory) === 0:
225  $targetFilesystem = \ILIAS\FileUpload\Location::WEB;
226  break;
227  case strpos($target, CLIENT_DATA_DIR . "/temp") === 0:
228  $targetFilesystem = \ILIAS\FileUpload\Location::TEMPORARY;
229  break;
230  case strpos($target, CLIENT_DATA_DIR) === 0:
231  $targetFilesystem = \ILIAS\FileUpload\Location::STORAGE;
232  break;
233  case strpos($target, ILIAS_ABSOLUTE_PATH . '/Customizing') === 0:
234  $targetFilesystem = \ILIAS\FileUpload\Location::CUSTOMIZING;
235  break;
236  default:
237  throw new InvalidArgumentException("Can not move files to \"$target\" because path can not be mapped to web, storage or customizing location.");
238  }
239 
240  return $targetFilesystem;
241  }
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
$target
Definition: test.php:19
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 
)

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

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

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

126  {
127  $imagepath = $this->rootDirectory . $this->certificatePath;
128 
129  if (!$this->fileSystem->hasDir($imagepath)) {
130  ilUtil::makeDirParents($imagepath);
131  }
132 
133  $backgroundImageTempFilePath = $this->createBackgroundImageTempfilePath();
134 
135  $this->uploadFile($imageTempFilename, $backgroundImageTempFilePath);
136 
137  $backgroundImagePath = $this->certificatePath . 'background_' . $version . '.jpg';
138 
139  $this->utilHelper->convertImage(
140  $backgroundImageTempFilePath,
141  $this->rootDirectory . $backgroundImagePath,
142  'JPEG'
143  );
144 
145  $backgroundImageThumbnailPath = $this->createBackgroundImageThumbPath();
146 
147  $this->utilHelper->convertImage(
148  $backgroundImageTempFilePath,
149  $backgroundImageThumbnailPath,
150  'JPEG',
151  100
152  );
153 
154  $convert_filename = self::BACKGROUND_IMAGE_NAME;
155 
156  if (!$this->fileSystem->has($backgroundImagePath)) {
157  // something went wrong converting the file. use the original file and hope, that PDF can work with it
158  if (!ilUtil::moveUploadedFile($backgroundImageTempFilePath, $convert_filename, $this->rootDirectory . $backgroundImagePath)) {
159  throw new ilException('Unable to convert the file and the original file');
160  }
161  }
162 
163  $this->fileSystem->delete($this->certificatePath . self::BACKGROUND_TEMPORARY_FILENAME);
164 
165  if ($this->fileSystem->has($backgroundImagePath)) {
166  return $this->certificatePath . 'background_' . $version . '.jpg';
167  }
168 
169  throw new ilException('The given temporary filename is empty');
170  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$version
Definition: build.php:27
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 51 of file class.ilCertificateBackgroundImageUpload.php.

◆ $fileSystem

ilCertificateBackgroundImageUpload::$fileSystem
private

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

Referenced by __construct().

◆ $fileUpload

ilCertificateBackgroundImageUpload::$fileUpload
private

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

Referenced by __construct().

◆ $fileUtilsHelper

ilCertificateBackgroundImageUpload::$fileUtilsHelper
private

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

◆ $language

ilCertificateBackgroundImageUpload::$language
private

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

Referenced by __construct().

◆ $legacyPathHelper

ilCertificateBackgroundImageUpload::$legacyPathHelper
private

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

Referenced by __construct().

◆ $rootDirectory

ilCertificateBackgroundImageUpload::$rootDirectory
private

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

Referenced by __construct().

◆ $utilHelper

ilCertificateBackgroundImageUpload::$utilHelper
private

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

Referenced by __construct().

◆ BACKGROUND_IMAGE_NAME

const ilCertificateBackgroundImageUpload::BACKGROUND_IMAGE_NAME = 'background.jpg'

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

◆ BACKGROUND_TEMPORARY_FILENAME

const ilCertificateBackgroundImageUpload::BACKGROUND_TEMPORARY_FILENAME = 'background_upload.tmp'

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

◆ BACKGROUND_THUMBNAIL_IMAGE_NAME

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

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


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