ILIAS  release_8 Revision v8.24
class.ilObjFileServicesGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
23
31{
32 public const CMD_EDIT_SETTINGS = 'editSettings';
33 protected ilTabsGUI $tabs;
36 protected ilCtrl $ctrl;
39 protected Factory $refinery;
42
47 public function __construct(int $id = 0, int $id_type = self::REPOSITORY_NODE_ID, int $parent_node_id = 0)
48 {
49 global $DIC;
50
52 parent::__construct($id, $id_type, $parent_node_id);
53
54 $this->tabs = $DIC['ilTabs'];
55 $this->lng = $DIC->language();
56 $this->lng->loadLanguageModule('adn');
57 $this->ctrl = $DIC['ilCtrl'];
58 $this->tpl = $DIC['tpl'];
59 $this->tree = $DIC['tree'];
60 $this->settings = $DIC['ilSetting'];
61 $this->error_handling = $DIC["ilErr"];
62 $this->http = $DIC->http()->wrapper();
63 $this->ref_id = $this->http->query()->retrieve('ref_id', $DIC->refinery()->kindlyTo()->int());
64 $this->refinery = $DIC->refinery();
65 $this->file_service_settings = $DIC->fileServiceSettings();
66 }
67
68 public function getType(): string
69 {
71 }
72
73 protected function checkPermissionOrFail(string $str): void
74 {
75 if (!$this->hasUserPermissionTo($str)) {
76 $this->error_handling->raiseError(
77 $this->lng->txt('no_permission'),
78 $this->error->MESSAGE
79 );
80 }
81 }
82
83 protected function hasUserPermissionTo(string $str): bool
84 {
85 return $this->access->checkAccess($str, '', $this->ref_id);
86 }
87
92 public function executeCommand(): void
93 {
94 $this->lng->loadLanguageModule("fils");
95
96 $next_class = $this->ctrl->getNextClass($this);
97 $cmd = $this->ctrl->getCmd();
98
99 $this->prepareOutput();
100 $this->checkPermissionOrFail('read');
101
102 switch ($next_class) {
103 case 'ilpermissiongui':
104 $this->tabs_gui->setTabActive('perm_settings');
105 $perm_gui = new ilPermissionGUI($this);
106 $this->ctrl->forwardCommand($perm_gui);
107 break;
108 default:
109 if (!$cmd || $cmd === 'view') {
111 }
112 $this->$cmd();
113 break;
114 }
115 }
116
120 public function getAdminTabs(): void
121 {
122 if ($this->rbac_system->checkAccess(
123 "visible,read",
124 $this->object->getRefId()
125 )
126 ) {
127 $this->tabs_gui->addTarget(
128 'settings',
129 $this->ctrl->getLinkTarget($this, self::CMD_EDIT_SETTINGS),
130 [self::CMD_EDIT_SETTINGS, "view"]
131 );
132 }
133 if ($this->rbac_system->checkAccess(
134 'edit_permission',
135 $this->object->getRefId()
136 )
137 ) {
138 $this->tabs_gui->addTarget(
139 "perm_settings",
140 $this->ctrl->getLinkTargetByClass(ilPermissionGUI::class, "perm"),
141 [],
142 ilPermissionGUI::class
143 );
144 }
145 }
146
147 public function setTitleAndDescription(): void
148 {
149 parent::setTitleAndDescription();
150 $this->tpl->setDescription($this->object->getDescription());
151 }
152
154 {
155 $permission_to_write = $this->hasUserPermissionTo('write');
156
157 $form = new ilPropertyFormGUI();
158 $form->setFormAction($this->ctrl->getFormAction($this));
159 $form->setTitle($this->lng->txt("settings"));
160
161 // default positive list
162 $ne = new ilNonEditableValueGUI($this->lng->txt("file_suffix_default_positive"), "");
163 $ne->setValue(implode(", ", $this->file_service_settings->getDefaultWhitelist()));
164 $ne->setInfo($this->lng->txt("file_suffix_default_positive_info"));
165 $form->addItem($ne);
166
167 // file suffix custom negative list
168 $ta = new ilTextAreaInputGUI(
169 $this->lng->txt(
170 "file_suffix_custom_negative"
171 ),
172 "suffix_repl_additional"
173 );
174 $ta->setInfo($this->lng->txt("file_suffix_custom_negative_info"));
175 $ta->setRows(5);
176 $ta->setDisabled(!$permission_to_write);
177 $form->addItem($ta);
178
179 // file suffix custom positive list
180 $ta = new ilTextAreaInputGUI(
181 $this->lng->txt(
182 "file_suffix_custom_positive"
183 ),
184 "suffix_custom_white_list"
185 );
186 $ta->setInfo($this->lng->txt("file_suffix_custom_positive_info"));
187 $ta->setRows(5);
188 $ta->setDisabled(!$permission_to_write);
189 $form->addItem($ta);
190
191 // resulting overall positive list
192 $ne = new ilNonEditableValueGUI($this->lng->txt("file_suffix_overall_positive"), "");
193 $ne->setValue(implode(", ", $this->file_service_settings->getWhiteListedSuffixes()));
194 $ne->setInfo($this->lng->txt("file_suffix_overall_positive_info"));
195 $form->addItem($ne);
196
197 // explicit negative list
198 $ta = new ilTextAreaInputGUI(
199 $this->lng->txt("file_suffix_custom_expl_negative"),
200 "suffix_custom_expl_black"
201 );
202 $ta->setInfo($this->lng->txt("file_suffix_custom_expl_negative_info"));
203 $ta->setRows(5);
204 $ta->setDisabled(!$permission_to_write);
205 $form->addItem($ta);
206
207 // command buttons
208 if ($permission_to_write) {
209 $form->addCommandButton('saveSettings', $this->lng->txt('save'));
210 $form->addCommandButton('view', $this->lng->txt('cancel'));
211 }
212
213 return $form;
214 }
215
216 protected function editSettings(): void
217 {
218 $this->tabs_gui->setTabActive('settings');
219
220 $this->checkPermissionOrFail("visible,read");
221
222 // get form
223 $form = $this->initSettingsForm();
224
225 // set current values
226 $val = [];
227 $val["suffix_repl_additional"] = implode(", ", $this->file_service_settings->getWhiteListNegative());
228 $val["suffix_custom_white_list"] = implode(", ", $this->file_service_settings->getWhiteListPositive());
229 $val["suffix_custom_expl_black"] = implode(", ", $this->file_service_settings->getProhibited());
230 $form->setValuesByArray($val);
231
232 // set content
233 $this->tpl->setContent($form->getHTML());
234 }
235
236 protected function saveSettings(): void
237 {
238 $this->checkPermissionOrFail("write");
239
240 // get form
241 $form = $this->initSettingsForm();
242 if ($form->checkInput()) {
243 $trafo = function (string $id): ?string {
244 return $this->http->post()->has($id)
245 ? $this->http->post()->retrieve($id, $this->refinery->to()->string())
246 : null;
247 };
248
249
250 $this->settings->set("suffix_repl_additional", $trafo("suffix_repl_additional"));
251 $this->settings->set("suffix_custom_white_list", $trafo("suffix_custom_white_list"));
252 $this->settings->set("suffix_custom_expl_black", $trafo("suffix_custom_expl_black"));
253
254 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
255 $this->ctrl->redirect($this, self::CMD_EDIT_SETTINGS);
256 } else {
257 $form->setValuesByPost();
258 $this->tpl->setContent($form->getHTML());
259 }
260 }
261}
Builds data types.
Definition: Factory.php:21
Class ilCtrl provides processing control methods.
Error Handling & global info handling uses PEAR error class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjFileServicesGUI.
executeCommand()
Execute command @access public.
ilGlobalTemplateInterface $tpl
ilFileServicesSettings $file_service_settings
__construct(int $id=0, int $id_type=self::REPOSITORY_NODE_ID, int $parent_node_id=0)
Constructor @access public.
getType()
Functions that must be overwritten.
New implementation of ilObjectGUI.
prepareOutput(bool $show_sub_objects=true)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a text area property in a property form.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc