ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilCertificateBackgroundImageFileService.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 {
28  final public const BACKGROUND_IMAGE_NAME = 'background.jpg';
29  final public const BACKGROUND_TEMPORARY_UPLOAD_FILE_NAME = 'background_upload_tmp';
30  final public const BACKGROUND_THUMBNAIL_FILE_ENDING = '.thumb.jpg';
31  final public const PLACEHOLDER_CLIENT_WEB_DIRECTORY = '[CLIENT_WEB_DIR]';
32  final public const VALID_BACKGROUND_IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'gif', 'png'];
33 
34  public function __construct(
35  private readonly string $certificatePath,
36  private readonly Filesystem $fileSystem,
37  private readonly string $webDirectory = CLIENT_WEB_DIR
38  ) {
39  }
40 
41  public function hasBackgroundImage(ilCertificateTemplate $template): bool
42  {
43  $backgroundImagePath = $template->getBackgroundImagePath();
44  if ($backgroundImagePath === '') {
45  return false;
46  }
47 
48  return $this->fileSystem->has($backgroundImagePath);
49  }
50 
51  public function getBackgroundImageThumbPath(): string
52  {
53  return $this->webDirectory . $this->certificatePath . self::BACKGROUND_IMAGE_NAME . self::BACKGROUND_THUMBNAIL_FILE_ENDING;
54  }
55 
56  public function getBackgroundImageDirectory(string $backgroundImagePath = ''): string
57  {
58  return str_replace(
59  [$this->webDirectory, '//'],
60  [self::PLACEHOLDER_CLIENT_WEB_DIRECTORY, '/'],
61  $backgroundImagePath
62  );
63  }
64 
65  public function getBackgroundImageTempfilePath(string $extension): string
66  {
67  return implode('', [
68  $this->webDirectory,
69  $this->certificatePath,
70  self::BACKGROUND_TEMPORARY_UPLOAD_FILE_NAME,
71  '.' . $extension
72  ]);
73  }
74 
78  public function getValidBackgroundImageFileExtensions(): array
79  {
80  return self::VALID_BACKGROUND_IMAGE_EXTENSIONS;
81  }
82 }
__construct(private readonly string $certificatePath, private readonly Filesystem $fileSystem, private readonly string $webDirectory=CLIENT_WEB_DIR)
const CLIENT_WEB_DIR
Definition: constants.php:47