ILIAS  release_8 Revision v8.23
ilCertificateBackgroundImageFileService.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 {
28  public const BACKGROUND_IMAGE_NAME = 'background.jpg';
29  public const BACKGROUND_TEMPORARY_UPLOAD_FILE_NAME = 'background_upload_tmp';
30  public const BACKGROUND_THUMBNAIL_FILE_ENDING = '.thumb.jpg';
31  public const PLACEHOLDER_CLIENT_WEB_DIRECTORY = '[CLIENT_WEB_DIR]';
32  public const VALID_BACKGROUND_IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'gif', 'png'];
33 
35  private string $certificatePath;
36  private string $webDirectory;
37 
38  public function __construct(
39  string $certificatePath,
40  Filesystem $filesystem,
41  string $webDirectory = CLIENT_WEB_DIR
42  ) {
43  $this->certificatePath = $certificatePath;
44  $this->fileSystem = $filesystem;
45  $this->webDirectory = $webDirectory;
46  }
47 
48  public function hasBackgroundImage(ilCertificateTemplate $template): bool
49  {
50  $backgroundImagePath = $template->getBackgroundImagePath();
51  if ($backgroundImagePath === '') {
52  return false;
53  }
54 
55  if ($this->fileSystem->has($backgroundImagePath)) {
56  return true;
57  }
58 
59  return false;
60  }
61 
62  public function hasBackgroundImageThumbnail(ilCertificateTemplate $template): bool
63  {
64  $backgroundImagePath = $template->getThumbnailImagePath();
65  if ($backgroundImagePath === '') {
66  return false;
67  }
68 
69  if ($this->fileSystem->has($backgroundImagePath)) {
70  return true;
71  }
72 
73  return false;
74  }
75 
76  public function getBackgroundImageThumbPath(): string
77  {
78  return $this->webDirectory . $this->certificatePath . self::BACKGROUND_IMAGE_NAME . self::BACKGROUND_THUMBNAIL_FILE_ENDING;
79  }
80 
81  public function getBackgroundImageDirectory(string $backgroundImagePath = ''): string
82  {
83  return str_replace(
84  [$this->webDirectory, '//'],
85  [self::PLACEHOLDER_CLIENT_WEB_DIRECTORY, '/'],
86  $backgroundImagePath
87  );
88  }
89 
90  public function getBackgroundImageTempfilePath(string $extension): string
91  {
92  return implode('', [
93  $this->webDirectory,
94  $this->certificatePath,
95  self::BACKGROUND_TEMPORARY_UPLOAD_FILE_NAME,
96  '.' . $extension
97  ]);
98  }
99 
103  public function getValidBackgroundImageFileExtensions(): array
104  {
105  return self::VALID_BACKGROUND_IMAGE_EXTENSIONS;
106  }
107 }
__construct(string $certificatePath, Filesystem $filesystem, string $webDirectory=CLIENT_WEB_DIR)
const CLIENT_WEB_DIR
Definition: constants.php:47
Class FlySystemFileAccessTest disabled disabled disabled.