ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjFileServicesGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
31 {
32  public const CMD_EDIT_SETTINGS = 'editSettings';
33  protected const TAB_PERMISSIONS = 'perm_settings';
34  protected const TAB_SETTINGS = 'settings';
35  protected const TAB_OVERVIEW = 'resource_overview';
36  protected const TAB_UPLOAD_LIMITS = 'upload_limits';
37 
38  protected ilTabsGUI $tabs;
39  public ilLanguage $lng;
41  protected ilCtrl $ctrl;
42  protected ilSetting $settings;
44  protected Factory $refinery;
45  protected WrapperFactory $http;
47 
52  public function __construct(int $id = 0, int $id_type = self::REPOSITORY_NODE_ID, int $parent_node_id = 0)
53  {
54  global $DIC;
55 
57  parent::__construct($id, $id_type, $parent_node_id);
58 
59  $this->tabs = $DIC['ilTabs'];
60  $this->lng = $DIC->language();
61  $this->lng->loadLanguageModule('adn');
62  $this->lng->loadLanguageModule('irss');
63  $this->ctrl = $DIC['ilCtrl'];
64  $this->tpl = $DIC['tpl'];
65  $this->tree = $DIC['tree'];
66  $this->settings = $DIC['ilSetting'];
67  $this->error_handling = $DIC["ilErr"];
68  $this->http = $DIC->http()->wrapper();
69  $this->ref_id = $this->http->query()->retrieve('ref_id', $DIC->refinery()->kindlyTo()->int());
70  $this->refinery = $DIC->refinery();
71  $this->file_service_settings = $DIC->fileServiceSettings();
72  }
73 
74  public function getType(): string
75  {
77  }
78 
79  protected function checkPermissionOrFail(string $str): void
80  {
81  if (!$this->hasUserPermissionTo($str)) {
82  $this->error_handling->raiseError(
83  $this->lng->txt('no_permission'),
84  $this->error->MESSAGE
85  );
86  }
87  }
88 
89  protected function hasUserPermissionTo(string $str): bool
90  {
91  return $this->access->checkAccess($str, '', $this->ref_id);
92  }
93 
98  public function executeCommand(): void
99  {
100  $this->lng->loadLanguageModule("fils");
101 
102  $next_class = $this->ctrl->getNextClass($this);
103  $cmd = $this->ctrl->getCmd();
104 
105  $this->prepareOutput();
106  $this->checkPermissionOrFail('read');
107 
108  switch ($next_class) {
109  case strtolower(ilPermissionGUI::class):
110  $this->tabs_gui->activateTab(self::TAB_PERMISSIONS);
111  $perm_gui = new ilPermissionGUI($this);
112  $this->ctrl->forwardCommand($perm_gui);
113  break;
114  case strtolower(ilResourceOverviewGUI::class):
115  $this->tabs_gui->activateTab(self::TAB_OVERVIEW);
116  $overview = new ilResourceOverviewGUI();
117  $this->ctrl->forwardCommand($overview);
118  break;
119  case strtolower(ilUploadLimitsOverviewGUI::class):
120  $this->tabs_gui->activateTab(self::TAB_UPLOAD_LIMITS);
121  $limits_gui = new ilUploadLimitsOverviewGUI();
122  $this->ctrl->forwardCommand($limits_gui);
123  break;
124  default:
125  if (!$cmd || $cmd === 'view') {
126  $cmd = self::CMD_EDIT_SETTINGS;
127  }
128  $this->$cmd();
129  break;
130  }
131  }
132 
136  public function getAdminTabs(): void
137  {
138  // General Settings for File-Services
139  if ($this->rbac_system->checkAccess(
140  "visible,read",
141  $this->object->getRefId()
142  )
143  ) {
144  $this->tabs_gui->addTab(
145  self::TAB_SETTINGS,
146  $this->lng->txt(self::TAB_SETTINGS),
147  $this->ctrl->getLinkTarget($this, self::CMD_EDIT_SETTINGS)
148  );
149  }
150  // Resource-Overview
151  if ($this->rbac_system->checkAccess(
152  "visible,read",
153  $this->object->getRefId()
154  )
155  ) {
156  $this->tabs_gui->addTab(
157  self::TAB_OVERVIEW,
158  $this->lng->txt(self::TAB_OVERVIEW),
159  $this->ctrl->getLinkTargetByClass(ilResourceOverviewGUI::class),
160  );
161  }
162  // Upload-Limit
163  if ($this->rbac_system->checkAccess(
164  "visible,read",
165  $this->object->getRefId()
166  )
167  ) {
168  $this->tabs_gui->addTab(
169  self::TAB_UPLOAD_LIMITS,
170  $this->lng->txt(self::TAB_UPLOAD_LIMITS),
171  $this->ctrl->getLinkTargetByClass(ilUploadLimitsOverviewGUI::class),
172  );
173  }
174  // Permissions-tab
175  if ($this->rbac_system->checkAccess(
176  'edit_permission',
177  $this->object->getRefId()
178  )
179  ) {
180  $this->tabs_gui->addTab(
181  self::TAB_PERMISSIONS,
182  $this->lng->txt(self::TAB_PERMISSIONS),
183  $this->ctrl->getLinkTargetByClass(ilPermissionGUI::class, "perm")
184  );
185  }
186  }
187 
188  public function setTitleAndDescription(): void
189  {
190  parent::setTitleAndDescription();
191  $this->tpl->setDescription($this->object->getDescription());
192  }
193 
195  {
196  $permission_to_write = $this->hasUserPermissionTo('write');
197 
198  $form = new ilPropertyFormGUI();
199  $form->setFormAction($this->ctrl->getFormAction($this));
200  $form->setTitle($this->lng->txt(self::TAB_SETTINGS));
201 
202  // default positive list
203  $ne = new ilNonEditableValueGUI($this->lng->txt("file_suffix_default_positive"), "");
204  $ne->setValue(implode(", ", $this->file_service_settings->getDefaultWhitelist()));
205  $ne->setInfo($this->lng->txt("file_suffix_default_positive_info"));
206  $form->addItem($ne);
207 
208  // file suffix custom negative list
209  $ta = new ilTextAreaInputGUI(
210  $this->lng->txt(
211  "file_suffix_custom_negative"
212  ),
213  "suffix_repl_additional"
214  );
215  $ta->setInfo($this->lng->txt("file_suffix_custom_negative_info"));
216  $ta->setRows(5);
217  $ta->setDisabled(!$permission_to_write);
218  $form->addItem($ta);
219 
220  // file suffix custom positive list
221  $ta = new ilTextAreaInputGUI(
222  $this->lng->txt(
223  "file_suffix_custom_positive"
224  ),
225  "suffix_custom_white_list"
226  );
227  $ta->setInfo($this->lng->txt("file_suffix_custom_positive_info"));
228  $ta->setRows(5);
229  $ta->setDisabled(!$permission_to_write);
230  $form->addItem($ta);
231 
232  // resulting overall positive list
233  $ne = new ilNonEditableValueGUI($this->lng->txt("file_suffix_overall_positive"), "");
234  $ne->setValue(implode(", ", $this->file_service_settings->getWhiteListedSuffixes()));
235  $ne->setInfo($this->lng->txt("file_suffix_overall_positive_info"));
236  $form->addItem($ne);
237 
238  // explicit negative list
239  $ta = new ilTextAreaInputGUI(
240  $this->lng->txt("file_suffix_custom_expl_negative"),
241  "suffix_custom_expl_black"
242  );
243  $ta->setInfo($this->lng->txt("file_suffix_custom_expl_negative_info"));
244  $ta->setRows(5);
245  $ta->setDisabled(!$permission_to_write);
246  $form->addItem($ta);
247 
248  // command buttons
249  if ($permission_to_write) {
250  $form->addCommandButton('saveSettings', $this->lng->txt('save'));
251  $form->addCommandButton('view', $this->lng->txt('cancel'));
252  }
253 
254  return $form;
255  }
256 
257  protected function editSettings(): void
258  {
259  $this->tabs_gui->setTabActive(self::TAB_SETTINGS);
260 
261  $this->checkPermissionOrFail("visible,read");
262 
263  // get form
264  $form = $this->initSettingsForm();
265 
266  // set current values
267  $val = [];
268  $val["suffix_repl_additional"] = implode(", ", $this->file_service_settings->getWhiteListNegative());
269  $val["suffix_custom_white_list"] = implode(", ", $this->file_service_settings->getWhiteListPositive());
270  $val["suffix_custom_expl_black"] = implode(", ", $this->file_service_settings->getProhibited());
271  $form->setValuesByArray($val);
272 
273  // set content
274  $this->tpl->setContent($form->getHTML());
275  }
276 
277  protected function saveSettings(): void
278  {
279  $this->checkPermissionOrFail("write");
280 
281  // get form
282  $form = $this->initSettingsForm();
283  if ($form->checkInput()) {
284  $trafo = function (string $id): ?string {
285  return $this->http->post()->has($id)
286  ? $this->http->post()->retrieve($id, $this->refinery->to()->string())
287  : null;
288  };
289 
290 
291  $this->settings->set("suffix_repl_additional", $trafo("suffix_repl_additional"));
292  $this->settings->set("suffix_custom_white_list", $trafo("suffix_custom_white_list"));
293  $this->settings->set("suffix_custom_expl_black", $trafo("suffix_custom_expl_black"));
294 
295  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
296  $this->ctrl->redirect($this, self::CMD_EDIT_SETTINGS);
297  } else {
298  $form->setValuesByPost();
299  $this->tpl->setContent($form->getHTML());
300  }
301  }
302 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
New implementation of ilObjectGUI.
prepareOutput(bool $show_sub_objects=true)
ilGlobalTemplateInterface $tpl
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.
__construct(VocabulariesInterface $vocabularies)
Class ilObjFileServicesGUI.
executeCommand()
Execute command public.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Error Handling & global info handling.
This class represents a text area property in a property form.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
__construct(int $id=0, int $id_type=self::REPOSITORY_NODE_ID, int $parent_node_id=0)
Constructor public.
ilFileServicesSettings $file_service_settings