ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
LegacyRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 use ILIAS\ILIASObject\Properties\ObjectTypeSpecificProperties\Factory as ObjectTypeSpecificPropertiesFactory;
29 
34 class LegacyRepository implements Repository
35 {
36  public function __construct(
37  private CustomIconFactory $custom_icon_factory,
38  private ObjectTypeSpecificPropertiesFactory $object_type_specific_properties_factory
39  ) {
40  }
41 
42  public function getFor(int $object_id): AdditionalProperties
43  {
44  if ($object_id === 0) {
45  return $this->getDefaultAdditionalProperties();
46  }
47 
48  $type = \ilObject::_lookupType($object_id);
49  $object_type_specific_properties = $this->object_type_specific_properties_factory->getForObjectTypeString($type);
50  $providers = null;
51  if ($object_type_specific_properties !== null) {
52  $providers = $object_type_specific_properties->getProviders();
53  }
54 
55  return new AdditionalProperties(
56  new TitleAndIconVisibility($this->getTitleAndIconVisibility($object_id)),
57  new HeaderActionVisibility($this->getHeaderActionVisibility($object_id)),
58  new InfoTabVisibility($this->getInfoTabVisibility($object_id)),
59  new Icon(
60  $this->areCustomIconsEnabled(),
61  $this->custom_icon_factory->getByObjId($object_id),
62  $providers
63  ),
64  $object_id
65  );
66  }
67 
68  public function store(AdditionalProperties $properties): AdditionalProperties
69  {
70  if ($properties->getObjectId() === null) {
71  throw new \Exception('The current configuration cannot be saved.');
72  }
73 
74  $object_id = $properties->getObjectId();
75 
76  if ($properties->wasPropertyTitleAndIconVisibilityUpdated()) {
78  $object_id,
79  $properties->getPropertyTitleAndIconVisibility()->getVisibility()
80  );
81  }
82 
83  if ($properties->wasPropertyHeaderActionVisbilityUpdated()) {
85  $object_id,
86  $properties->getPropertyHeaderActionVisibility()->getVisibility()
87  );
88  }
89 
90  if ($properties->wasPropertyInfoTabVisbilityUpdated()) {
92  $object_id,
93  $properties->getPropertyInfoTabVisibility()->getVisibility()
94  );
95  }
96 
97  if ($properties->wasPropertyIconUpdated()) {
98  $this->storeIcon($properties->getPropertyIcon());
99  }
100 
101  return $properties->withResetUpdatedFlags();
102  }
103 
105  {
106  return new AdditionalProperties(
109  new InfoTabVisibility(),
110  new Icon(
111  $this->areCustomIconsEnabled()
112  )
113  );
114  }
115 
116  private function getTitleAndIconVisibility(int $object_id): bool
117  {
118  return !((bool) \ilContainer::_lookupContainerSetting($object_id, 'hide_header_icon_and_title'));
119  }
120 
121  private function storeTitleAndIconVisibility(int $object_id, bool $visibility): void
122  {
123  $hide_header_icon_and_title = $visibility ? '' : '1';
125  $object_id,
126  'hide_header_icon_and_title',
127  $hide_header_icon_and_title
128  );
129  }
130 
131  private function getHeaderActionVisibility(int $object_id): bool
132  {
133  return !((bool) \ilContainer::_lookupContainerSetting($object_id, 'hide_top_actions'));
134  }
135 
136  private function storeHeaderActionVisibility(int $object_id, bool $visibility): void
137  {
138  $hide_top_actions = $visibility ? '' : '1';
140  $object_id,
141  'hide_top_actions',
142  $hide_top_actions
143  );
144  }
145 
146  private function getInfoTabVisibility(int $object_id): bool
147  {
148  return ((bool) \ilContainer::_lookupContainerSetting($object_id, 'cont_show_info_tab'));
149  }
150 
151  private function storeInfoTabVisibility(int $object_id, bool $visibility): void
152  {
153  $show_info_tab = $visibility ? '1' : '';
155  $object_id,
156  'cont_show_info_tab',
157  $show_info_tab
158  );
159  }
160 
161  private function areCustomIconsEnabled(): bool
162  {
163  return (bool) \ilSetting::_lookupValue('common', 'custom_icons');
164  }
165 
166  private function storeIcon(Icon $property_icon): void
167  {
168  if ($property_icon->getDeletedFlag()) {
169  $property_icon->getCustomIcon()->remove();
170  }
171 
172  if ($property_icon->getTempFileName()) {
173  $property_icon->getCustomIcon()->saveFromTempFileName($property_icon->getTempFileName());
174  }
175  }
176 }
__construct(private CustomIconFactory $custom_icon_factory, private ObjectTypeSpecificPropertiesFactory $object_type_specific_properties_factory)
static _lookupValue(string $a_module, string $a_keyword)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Builds data types.
Definition: Factory.php:35
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
static _lookupType(int $id, bool $reference=false)