ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilObjectCommonSettingFormAdapter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
30 
37 {
38  public function __construct(
39  private ilLanguage $language,
40  private FileUpload $upload,
41  private ResourceStorageServices $storage,
42  private Stakeholder $stakeholder,
43  private FlavourDefinition $flavour,
44  private ilObjectCommonSettings $common_settings,
45  private Services $http,
46  private ?ilPropertyFormGUI $legacy_form = null
47  ) {
48  $this->language->loadLanguageModule('obj');
49  $this->language->loadLanguageModule('cntr');
50  }
51 
52  public function addIcon(): ?ilPropertyFormGUI
53  {
54  $icon = $this->common_settings->getPropertyIcon()->toLegacyForm($this->language);
55  if (!is_null($this->legacy_form) && $icon !== null) {
56  $this->legacy_form->addItem($icon);
57  }
58 
59  return $this->legacy_form;
60  }
61 
62  public function saveIcon(): void
63  {
64  if (is_null($this->legacy_form)) {
65  return;
66  }
67 
68  $item = $this->legacy_form->getItemByPostVar('icon');
69  if ($item && $item->getDeletionFlag()) {
70  $this->common_settings->storePropertyIcon(
71  $this->common_settings->getPropertyIcon()->withDeletedFlag()
72  );
73  return;
74  }
75 
76  $file_data = (array) $this->legacy_form->getInput('icon');
77  if (isset($file_data['tmp_name']) && $file_data['tmp_name']) {
78  $tempfile = ilFileUtils::ilTempnam();
79  if (!$this->upload->hasBeenProcessed()) {
80  $this->upload->process();
81  }
82 
83  rename($file_data['tmp_name'], $tempfile);
84 
85  $this->common_settings->storePropertyIcon(
86  $this->common_settings->getPropertyIcon()->withTempFileName(basename($tempfile))
87  );
88  }
89  }
90 
91  public function addTileImage(): ?ilPropertyFormGUI
92  {
93  if (!is_null($this->legacy_form)) {
94  $timg = $this->common_settings->getPropertyTileImage()->toLegacyForm($this->language);
95  $this->legacy_form->addItem($timg);
96  }
97 
98  return $this->legacy_form;
99  }
100 
101  public function saveTileImage(): void
102  {
103  if (is_null($this->legacy_form)) {
104  return;
105  }
106 
107  $item = $this->legacy_form->getItemByPostVar('tile_image');
108  if ($item && $item->getDeletionFlag()) {
109  $this->common_settings->storePropertyTileImage(
110  $this->common_settings->getPropertyTileImage()->withDeletedFlag()
111  );
112  return;
113  }
114 
115  // In case of a parallel oather upload, the uploads may already have been processed. otherwise we have to do it
116  if (!$this->upload->hasBeenProcessed()) {
117  $this->upload->process();
118  }
119  $result_array = $this->upload->getResults();
120 
121  // Determine Legacy Upload (since there can be more than one in this form). This is not best practice, because
122  // on the one hand we should actually use the wrapper, on the other hand with the conversion to the new forms
123  // this problem no longer have anyway. But at the moment we have to pick the right one out of all uploadResults,
124  // that's only possible with this way
125 
127  $file = $this->http->request()->getUploadedFiles()['tile_image']; // Direct Access to the Psr7/UploadedFile
128  if ($file->getClientFilename() === '') {
129  return;
130  }
131 
132  $temp_name = $file->getStream()->getMetadata('uri'); // Get the Path of the Temp. File
133  $result = $result_array[$temp_name] ?? null;
134 
135  if (!($result instanceof UploadResult) || !$result->isOK()) {
136  return;
137  }
138 
139  if ($item->getValue() === null || $item->getValue() === '') {
140  $i = $this->storage->manage()->upload($result, $this->stakeholder);
141  $this->storage->flavours()->ensure($i, $this->flavour);
142  $new_tile_image = $this->common_settings->getPropertyTileImage()
143  ->getTileImage()->withRid($i->serialize());
144  $this->common_settings->storePropertyTileImage(
145  $this->common_settings->getPropertyTileImage()->withTileImage($new_tile_image)
146  );
147  } else {
148  $i = $this->storage->manage()->find($item->getValue());
149  $this->storage->manage()->replaceWithUpload(
150  $i,
151  $result,
152  $this->stakeholder
153  );
154  }
155  }
156 
158  {
159  $title_and_icon_visibility_input = $this->common_settings->getPropertyTitleAndIconVisibility()
160  ->toLegacyForm($this->language);
161  $this->legacy_form->addItem($title_and_icon_visibility_input);
162 
163  return $this->legacy_form;
164  }
165 
166  public function saveTitleIconVisibility(): void
167  {
168  if (is_null($this->legacy_form)) {
169  return;
170  }
171 
172  $this->common_settings->storePropertyTitleAndIconVisibility(
173  new TitleAndIconVisibility((bool) $this->legacy_form->getInput('show_header_icon_and_title'))
174  );
175  }
176 
178  {
179  $top_actions_visibility_input = $this->common_settings->getPropertyHeaderActionVisibility()
180  ->toLegacyForm($this->language);
181  $this->legacy_form->addItem($top_actions_visibility_input);
182 
183  return $this->legacy_form;
184  }
185 
186  public function saveTopActionsVisibility(): void
187  {
188  if (is_null($this->legacy_form)) {
189  return;
190  }
191 
192  $this->common_settings->storePropertyHeaderActionVisibility(
193  new HeaderActionVisibility((bool) $this->legacy_form->getInput('show_top_actions'))
194  );
195  }
196 }
addTopActionsVisibility()
Add top actions visibility setting to form.
__construct(private ilLanguage $language, private FileUpload $upload, private ResourceStorageServices $storage, private Stakeholder $stakeholder, private FlavourDefinition $flavour, private ilObjectCommonSettings $common_settings, private Services $http, private ?ilPropertyFormGUI $legacy_form=null)
$http
Definition: deliver.php:30
saveTitleIconVisibility()
Save title icon visibility setting from form.
addTitleIconVisibility()
Add title icon visibility setting to form.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
11: This interface will be remove with ILIAS 11.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
saveTopActionsVisibility()
Save top actions visibility setting from form.
Class FileUpload.
Definition: FileUpload.php:37
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
saveTileImage()
Save tile image setting from form.