ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilObjectPropertyIcon.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 
34 {
35  public const SUPPORTED_MIME_TYPES = [MimeType::IMAGE__SVG_XML];
36  private const INPUT_LABEL = 'custom_icon';
37 
38  private bool $deleted_flag = false;
39  private ?string $temp_file_name = null;
40 
41  public function __construct(
42  private bool $custom_icons_enabled,
43  private ?ilObjectCustomIcon $custom_icon = null,
44  private ?ilObjectTypeSpecificPropertyProviders $object_type_specific_property_providers = null
45  ) {
46  }
47 
48  public function getObjectTypeSpecificIcon(
49  int $object_id,
50  IconFactory $factory,
51  StorageService $irss
52  ): ?CustomIcon {
53  if ($this->object_type_specific_property_providers === null) {
54  return null;
55  }
56  return $this->object_type_specific_property_providers->getObjectTypeSpecificIcon($object_id, $factory, $irss);
57  }
58 
59  public function getCustomIcon(): ?ilObjectCustomIcon
60  {
61  return $this->custom_icons_enabled ? $this->custom_icon : null;
62  }
63 
64  public function getDeletedFlag(): bool
65  {
66  return $this->deleted_flag;
67  }
68 
69  public function withDeletedFlag(): self
70  {
71  $clone = clone $this;
72  $clone->deleted_flag = true;
73  return $clone;
74  }
75 
76  public function getTempFileName(): ?string
77  {
78  return $this->temp_file_name;
79  }
80 
81  public function withTempFileName(string $name): self
82  {
83  $clone = $this;
84  $clone->temp_file_name = $name;
85  return $clone;
86  }
87 
88  public function toForm(
89  \ilLanguage $language,
90  FieldFactory $field_factory,
92  ): ?File {
93  if (!$this->custom_icons_enabled) {
94  return null;
95  }
96  $trafo = $refinery->custom()->transformation(
97  function ($v): ?ilObjectProperty {
98  $property_icon = new ilObjectPropertyIcon(
99  $this->custom_icons_enabled,
100  $this->custom_icon
101  );
102 
103  if (count($v) > 0 && $v[0] !== 'custom_icon') {
104  return $property_icon
105  ->withTempFileName($v[0]);
106  }
107 
108  if (count($v) === 0 && $this->custom_icon->exists()) {
109  return $property_icon
110  ->withDeletedFlag();
111  }
112 
113  return $property_icon;
114  }
115  );
116  $custom_icon = $field_factory
117  ->file(new ilObjectCustomIconUploadHandlerGUI($this->custom_icon), $language->txt(self::INPUT_LABEL))
118  ->withAcceptedMimeTypes(self::SUPPORTED_MIME_TYPES)
119  ->withAdditionalTransformation($trafo);
120 
121  if (!$this->custom_icon->exists()) {
122  return $custom_icon;
123  }
124 
125  return $custom_icon->withValue(['custom_icon']);
126  }
127 
128  public function toLegacyForm(
129  \ilLanguage $language
130  ): ?ilImageFileInputGUI {
131  if (!$this->custom_icons_enabled) {
132  return null;
133  }
134  $custom_icon_input = new ilImageFileInputGUI($language->txt(self::INPUT_LABEL), 'icon');
135  $custom_icon_input->setSuffixes($this->custom_icon->getSupportedFileExtensions());
136  $custom_icon_input->setUseCache(false);
137  if ($this->custom_icon->exists()) {
138  $custom_icon_input->setImage($this->custom_icon->getFullPath());
139  } else {
140  $custom_icon_input->setImage('');
141  }
142 
143  return $custom_icon_input;
144  }
145 }
Class ilObjectCustomIconImpl TODO: Inject database persistence in future instead of using ...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setSuffixes(array $a_suffixes)
custom_icon()
description: > Example for rendering custom icons.
Definition: custom_icon.php:33
toForm(\ilLanguage $language, FieldFactory $field_factory, Refinery $refinery)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This is how a factory for icons looks like.
Definition: Factory.php:26
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents an image file property in a property form.
getObjectTypeSpecificIcon(int $object_id, IconFactory $factory, StorageService $irss)
This describes file field.
Definition: File.php:26
__construct(private bool $custom_icons_enabled, private ?ilObjectCustomIcon $custom_icon=null, private ?ilObjectTypeSpecificPropertyProviders $object_type_specific_property_providers=null)
toLegacyForm(\ilLanguage $language)