ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Icon.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27use ILIAS\Refinery\Factory as Refinery;
30use ILIAS\ResourceStorage\Services as StorageService;
32
36class Icon implements Property
37{
39 private const INPUT_LABEL = 'custom_icon';
40
41 private bool $deleted_flag = false;
42 private ?string $temp_file_name = null;
43
44 public function __construct(
45 private bool $custom_icons_enabled,
46 private ?Custom $custom_icon = null,
47 private ?ObjectTypeSpecificPropertyProviders $object_type_specific_property_providers = null
48 ) {
49 }
50
52 int $object_id,
53 IconFactory $factory,
54 StorageService $irss
55 ): ?CustomIcon {
56 if ($this->object_type_specific_property_providers === null) {
57 return null;
58 }
59 return $this->object_type_specific_property_providers->getObjectTypeSpecificIcon($object_id, $factory, $irss);
60 }
61
62 public function getCustomIcon(): ?Custom
63 {
64 return $this->custom_icons_enabled ? $this->custom_icon : null;
65 }
66
67 public function getDeletedFlag(): bool
68 {
70 }
71
72 public function withDeletedFlag(): self
73 {
74 $clone = clone $this;
75 $clone->deleted_flag = true;
76 return $clone;
77 }
78
79 public function getTempFileName(): ?string
80 {
82 }
83
84 public function withTempFileName(string $name): self
85 {
86 $clone = $this;
87 $clone->temp_file_name = $name;
88 return $clone;
89 }
90
91 public function toForm(
92 \ilLanguage $language,
93 FieldFactory $field_factory,
95 ): ?File {
96 if (!$this->custom_icons_enabled) {
97 return null;
98 }
99 $trafo = $refinery->custom()->transformation(
100 function ($v): ?Property {
101 $property_icon = new self(
102 $this->custom_icons_enabled,
103 $this->custom_icon
104 );
105
106 if (count($v) > 0 && $v[0] !== 'custom_icon') {
107 return $property_icon
108 ->withTempFileName($v[0]);
109 }
110
111 if (count($v) === 0 && $this->custom_icon->exists()) {
112 return $property_icon
113 ->withDeletedFlag();
114 }
115
116 return $property_icon;
117 }
118 );
119 $custom_icon = $field_factory
120 ->file(new \CustomIconUploadHandlerGUI($this->custom_icon), $language->txt(self::INPUT_LABEL))
121 ->withAcceptedMimeTypes(self::SUPPORTED_MIME_TYPES)
122 ->withAdditionalTransformation($trafo);
123
124 if (!$this->custom_icon->exists()) {
125 return $custom_icon;
126 }
127
128 return $custom_icon->withValue(['custom_icon']);
129 }
130
131 public function toLegacyForm(
132 \ilLanguage $language
134 if (!$this->custom_icons_enabled) {
135 return null;
136 }
137 $custom_icon_input = new \ilImageFileInputGUI($language->txt(self::INPUT_LABEL), 'icon');
138 $custom_icon_input->setSuffixes($this->custom_icon->getSupportedFileExtensions());
139 $custom_icon_input->setUseCache(false);
140 if ($this->custom_icon->exists()) {
141 $custom_icon_input->setImage($this->custom_icon->getFullPath());
142 } else {
143 $custom_icon_input->setImage('');
144 }
145
146 return $custom_icon_input;
147 }
148}
Builds data types.
Definition: Factory.php:36
Mime type determination.
Definition: MimeType.php:30
getObjectTypeSpecificIcon(int $object_id, IconFactory $factory, StorageService $irss)
Definition: Icon.php:51
toForm(\ilLanguage $language, FieldFactory $field_factory, Refinery $refinery)
Definition: Icon.php:91
__construct(private bool $custom_icons_enabled, private ?Custom $custom_icon=null, private ?ObjectTypeSpecificPropertyProviders $object_type_specific_property_providers=null)
Definition: Icon.php:44
This class represents an image file property in a property form.
language handling
This is what a factory for input fields looks like.
Definition: Factory.php:31
This describes file field.
Definition: File.php:29
This describes the behavior of an custom icon.
Definition: Custom.php:27
This is how a factory for icons looks like.
Definition: Factory.php:27
if(!file_exists('../ilias.ini.php'))