19 declare(strict_types=1);
38 public function __construct(
int $a_id = 0,
bool $a_reference =
true)
44 $this->cert_logger = $DIC->logger()->cert();
45 $this->uuid_factory =
new Factory();
46 $this->certificate_settings =
new ilSetting(
'certificate');
59 $image_temp_file_name = $upload_result->
getPath();
60 if ($image_temp_file_name !==
'') {
61 $extension = pathinfo($upload_result->
getName(), PATHINFO_EXTENSION);
63 $new_image_file_name =
"background_{$this->uuid_factory->uuid4AsString()}.jpg";
64 $new_image_path = $image_path . $new_image_file_name;
66 if (!is_dir($image_path)) {
71 $image_temp_file_name,
75 $this->cert_logger->error(sprintf(
76 "Could not upload certificate background image from '%s' to temporary file '%s' (name: '%s')",
77 $image_temp_file_name,
85 $this->cert_logger->error(sprintf(
86 "Uploaded certificate background image could not be moved to temporary file '%s'",
105 if (!is_file($new_image_path) || !file_exists($new_image_path)) {
107 $this->cert_logger->error(sprintf(
108 "Could not convert certificate background image from '%s' as JPEG to '%s', trying fallbacj ...",
114 $new_image_file_name,
117 $this->cert_logger->error(sprintf(
118 "Could not upload certificate background image from '%s' to final file '%s' (name: '%s')",
134 if (file_exists($new_image_path) && (filesize($new_image_path) > 0)) {
138 $this->certificate_settings->set(
'defaultImageFileName', $new_image_file_name);
141 $this->certificate_repo->updateDefaultBackgroundImagePaths($old_relative_path, $new_relative_path);
144 !$this->certificate_repo->isBackgroundImageUsed($old_relative_path)
145 && !$this->user_certificate_repo->isBackgroundImageUsed($old_relative_path)
147 if (is_file($old_path) && file_exists($old_path)) {
151 if (is_file($old_path_thumb) && file_exists($old_path_thumb)) {
152 unlink($old_path_thumb);
158 $this->cert_logger->error(sprintf(
159 "Final background image '%s' does not exist or is empty",
173 $this->certificate_settings->get(
'defaultImageFileName',
'')
193 $this->certificate_settings->set(
'defaultImageFileName',
'');
197 return (
bool) $result;
202 return ($relativePath ?
'' :
CLIENT_WEB_DIR) .
'/certificates/default/';
208 . $this->certificate_settings->get(
'defaultImageFileName',
'');
229 return is_file($filePath) && filesize($filePath) > 0;
uploadBackgroundImage(UploadResult $upload_result)
Uploads a background image for the certificate.
getDefaultBackgroundImageThumbPath(bool $relativePath=false)
const VALID_BACKGROUND_IMAGE_EXTENSIONS
ilSetting $certificate_settings
getBackgroundImageDefaultFolder(bool $relativePath=false)
getBackgroundImageThumbPathWeb()
const BACKGROUND_THUMBNAIL_FILE_ENDING
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
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
static convertImage(string $a_from, string $a_to, string $a_target_format="", string $a_geometry="", string $a_background_color="")
convert image
getDefaultBackgroundImagePathWeb()
getDefaultBackgroundImagePath(bool $relativePath=false)
const BACKGROUND_TEMPORARY_UPLOAD_FILE_NAME
__construct(Container $dic, ilPlugin $plugin)
__construct(int $a_id=0, bool $a_reference=true)