19 declare(strict_types=1);
40 public function __construct(
int $a_id = 0,
bool $a_reference =
true)
46 $this->cert_logger = $DIC->logger()->cert();
47 $this->file_converter = $DIC->fileConverters()->legacyImages();
48 $this->uuid_factory =
new Factory();
49 $this->certificate_settings =
new ilSetting(
'certificate');
62 $image_temp_file_name = $upload_result->
getPath();
63 if ($image_temp_file_name !==
'') {
64 $extension = pathinfo($upload_result->
getName(), PATHINFO_EXTENSION);
66 $new_image_file_name =
"background_{$this->uuid_factory->uuid4AsString()}.jpg";
67 $new_image_path = $image_path . $new_image_file_name;
69 if (!is_dir($image_path)) {
74 $image_temp_file_name,
78 $this->cert_logger->error(sprintf(
79 "Could not upload certificate background image from '%s' to temporary file '%s' (name: '%s')",
80 $image_temp_file_name,
88 $this->cert_logger->error(sprintf(
89 "Uploaded certificate background image could not be moved to temporary file '%s'",
96 $this->file_converter->convertToFormat(
99 ImageOutputOptions::FORMAT_JPG
102 $this->file_converter->croppedSquare(
106 ImageOutputOptions::FORMAT_JPG
109 if (!is_file($new_image_path) || !file_exists($new_image_path)) {
111 $this->cert_logger->error(sprintf(
112 "Could not convert certificate background image from '%s' as JPEG to '%s', trying fallback ...",
118 $new_image_file_name,
121 $this->cert_logger->error(sprintf(
122 "Could not upload certificate background image from '%s' to final file '%s' (name: '%s')",
138 if (file_exists($new_image_path) && (filesize($new_image_path) > 0)) {
142 $this->certificate_settings->set(
'defaultImageFileName', $new_image_file_name);
145 $this->certificate_repo->updateDefaultBackgroundImagePaths($old_relative_path, $new_relative_path);
148 !$this->certificate_repo->isBackgroundImageUsed($old_relative_path)
149 && !$this->user_certificate_repo->isBackgroundImageUsed($old_relative_path)
151 if (is_file($old_path) && file_exists($old_path)) {
155 if (is_file($old_path_thumb) && file_exists($old_path_thumb)) {
156 unlink($old_path_thumb);
162 $this->cert_logger->error(sprintf(
163 "Final background image '%s' does not exist or is empty",
177 $this->certificate_settings->get(
'defaultImageFileName',
'')
197 $this->certificate_settings->set(
'defaultImageFileName',
'');
201 return (
bool) $result;
206 return ($relativePath ?
'' :
CLIENT_WEB_DIR) .
'/certificates/default/';
212 . $this->certificate_settings->get(
'defaultImageFileName',
'');
233 return is_file($filePath) && filesize($filePath) > 0;
uploadBackgroundImage(UploadResult $upload_result)
Uploads a background image for the certificate.
getDefaultBackgroundImageThumbPath(bool $relativePath=false)
ilSetting $certificate_settings
getBackgroundImageDefaultFolder(bool $relativePath=false)
getBackgroundImageThumbPathWeb()
ILIAS Filesystem Util Convert LegacyImages $file_converter
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
getDefaultBackgroundImageTempFilePath(string $extension)
static removeTrailingPathSeparators(string $path)
Class ilObjCertificateSettings.
ilUserCertificateRepository $user_certificate_repo
final const VALID_BACKGROUND_IMAGE_EXTENSIONS
ilCertificateTemplateDatabaseRepository $certificate_repo
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
getDefaultBackgroundImagePathWeb()
getDefaultBackgroundImagePath(bool $relativePath=false)
final const BACKGROUND_THUMBNAIL_FILE_ENDING
__construct(int $a_id=0, bool $a_reference=true)
final const BACKGROUND_TEMPORARY_UPLOAD_FILE_NAME