19 declare(strict_types=1);
44 private readonly
string $certificatePath,
54 if (null === $fileSystem) {
56 $fileSystem = $DIC->filesystem()->web();
60 if (null === $utilHelper) {
65 if (null === $certificateFileUtilsHelper) {
68 $this->fileUtilsHelper = $certificateFileUtilsHelper;
70 if (null === $legacyPathHelper) {
75 if (null === $tmp_file_system) {
77 $tmp_file_system = $DIC->filesystem()->temp();
96 $imagepath = $this->rootDirectory . $this->certificatePath;
98 if (!$this->fileSystem->hasDir($imagepath)) {
102 $backgroundImageTempFilePath = $this->
uploadFile($imageTempFilename, $pending_file);
104 $backgroundImagePath = $this->certificatePath .
'background_' . $version .
'.jpg';
106 $this->utilHelper->convertImage(
107 $backgroundImageTempFilePath,
108 $this->rootDirectory . $backgroundImagePath
113 $this->utilHelper->convertImage(
114 $backgroundImageTempFilePath,
115 $backgroundImageThumbnailPath,
119 $convert_filename = self::BACKGROUND_IMAGE_NAME;
123 $backgroundImageTempFilePath,
125 $this->rootDirectory . $backgroundImagePath
127 throw new ilException(
'Unable to convert the file and the original file');
130 if ($this->fileSystem->has($backgroundImageTempFilePath)) {
131 $this->fileSystem->delete($backgroundImageTempFilePath);
134 if ($this->fileSystem->has($backgroundImagePath)) {
135 return $this->certificatePath .
'background_' . $version .
'.jpg';
138 throw new ilException(
'The given temporary filename is empty');
148 private function uploadFile(
string $temporaryFilename, ?array $pending_file = null): string
150 if (!$this->fileUpload->hasBeenProcessed()) {
151 $this->fileUpload->process();
154 if (!$this->fileUpload->hasUploads()) {
158 $uploadResults = $this->fileUpload->getResults();
159 if (isset($uploadResults[$temporaryFilename])) {
160 $uploadResult = $uploadResults[$temporaryFilename];
161 $processingStatus = $uploadResult->getStatus();
163 throw new ilException($processingStatus->getMessage());
166 $extension = pathinfo($uploadResult->getName(), PATHINFO_EXTENSION);
168 $target_file_name = basename($temp_file_path);
169 $target_file_name = $this->fileUtilsHelper->getValidFilename($target_file_name);
172 $target_directory = $this->
getTargetDir($temp_file_path);
174 $this->fileUpload->moveOneFileTo(
182 return $temp_file_path;
183 } elseif (is_array($pending_file) && $pending_file !== []) {
184 $extension = pathinfo($pending_file[
'name'], PATHINFO_EXTENSION);
187 $target_file_name = basename($temp_file_path);
188 $target_file_name = $this->fileUtilsHelper->getValidFilename($target_file_name);
190 $target_directory = $this->
getTargetDir($temp_file_path);
192 $stream = $this->tmp_file_system->readStream(basename($pending_file[
'tmp_name']));
193 $this->fileSystem->writeStream($target_directory .
'/' . $target_file_name, $stream);
195 return $temp_file_path;
203 return match (
true) {
204 str_starts_with($target, $this->rootDirectory .
'/' . $this->clientId), str_starts_with(
206 './' . $this->rootDirectory .
'/' . $this->clientId
207 ), str_starts_with($target, $this->rootDirectory) => Location::WEB,
208 str_starts_with($target,
CLIENT_DATA_DIR .
"/temp") => Location::TEMPORARY,
210 str_starts_with($target, ILIAS_ABSOLUTE_PATH .
'/Customizing') => Location::CUSTOMIZING,
212 "Can not move files to \"$target\" because path can not be mapped to web, storage or customizing location." 219 $absTargetDir = dirname($target);
220 return $this->legacyPathHelper->createRelativePath($absTargetDir);
230 $this->rootDirectory,
231 $this->certificatePath,
232 self::BACKGROUND_TEMPORARY_FILENAME,
243 return $this->rootDirectory . $this->certificatePath . self::BACKGROUND_THUMBNAIL_IMAGE_NAME;
const REJECTED
Upload got rejected by a processor.
readonly LegacyPathHelperHelper $legacyPathHelper
createBackgroundImageTempfilePath(string $extension)
Returns the filesystem path of the background image temp file during upload.
readonly Filesystem $tmp_file_system
getTargetFilesystem(string $target)
const BACKGROUND_TEMPORARY_FILENAME
readonly ilCertificateFileUtilsHelper $fileUtilsHelper
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
readonly Filesystem $fileSystem
uploadFile(string $temporaryFilename, ?array $pending_file=null)
readonly ilCertificateUtilHelper $utilHelper
const BACKGROUND_IMAGE_NAME
getTargetDir(string $target)
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
uploadBackgroundImage(string $imageTempFilename, int $version, ?array $pending_file=null)
Uploads a background image for the certificate.
Just a wrapper class to create Unit Test for other classes.
const BACKGROUND_THUMBNAIL_IMAGE_NAME
createBackgroundImageThumbPath()
Returns the filesystem path of the background image thumbnail.
__construct(private readonly FileUpload $fileUpload, private readonly string $certificatePath, private readonly ilLanguage $language, private readonly string $rootDirectory=CLIENT_WEB_DIR, private readonly string $clientId=CLIENT_ID, ?Filesystem $fileSystem=null, ?ilCertificateUtilHelper $utilHelper=null, ?ilCertificateFileUtilsHelper $certificateFileUtilsHelper=null, ?LegacyPathHelperHelper $legacyPathHelper=null, ?Filesystem $tmp_file_system=null)