ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjFileAccessSettingsGUI.php
Go to the documentation of this file.
1 <?php
19 
32 {
33  public const CMD_EDIT_SETTINGS = 'editSettings';
34  public const CMD_SHOW_PREVIEW_RENDERERS = 'showPreviewRenderers';
35 
37  protected Services $http;
38 
44  public function __construct($a_data, int $a_id, bool $a_call_by_reference)
45  {
46  global $DIC;
47  $this->type = "facs";
48  parent::__construct($a_data, $a_id, $a_call_by_reference, false);
49  $this->folderSettings = new ilSetting('fold');
50  $this->http = $DIC->http();
51  }
52 
53 
60  public function executeCommand(): void
61  {
62  $this->lng->loadLanguageModule("file");
63 
64  $next_class = $this->ctrl->getNextClass($this);
65  $cmd = $this->ctrl->getCmd();
66 
67  $this->prepareOutput();
68 
69  if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
70  $this->ilias->raiseError(
71  $this->lng->txt('no_permission'),
72  $this->ilias->error_obj->MESSAGE
73  );
74  }
75 
76  switch ($next_class) {
77  case 'ilpermissiongui':
78  $this->tabs_gui->setTabActive('perm_settings');
79  $perm_gui = new ilPermissionGUI($this);
80  $this->ctrl->forwardCommand($perm_gui);
81  break;
82  default:
83  if (!$cmd || $cmd == 'view') {
84  $cmd = self::CMD_EDIT_SETTINGS;
85  }
86 
87  $this->$cmd();
88  break;
89  }
90  }
91 
92 
99  public function getAdminTabs(): void
100  {
101  if ($this->rbac_system->checkAccess("visible,read", $this->object->getRefId())) {
102  $this->tabs_gui->addTarget(
103  'file_objects',
104  $this->ctrl->getLinkTarget($this, self::CMD_EDIT_SETTINGS),
105  array(self::CMD_EDIT_SETTINGS, "view")
106  );
107  }
108  if ($this->rbac_system->checkAccess('edit_permission', $this->object->getRefId())) {
109  $this->tabs_gui->addTarget("perm_settings", $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm"), array(), 'ilpermissiongui');
110  }
111  }
112 
113 
114  protected function addFileObjectsSubTabs(): void
115  {
116  $this->tabs_gui->addSubTabTarget(
117  "settings",
118  $this->ctrl->getLinkTarget($this, self::CMD_EDIT_SETTINGS),
119  array(self::CMD_EDIT_SETTINGS, "view")
120  );
121  $this->tabs_gui->addSubTabTarget(
122  "preview_renderers",
123  $this->ctrl->getLinkTarget($this, self::CMD_SHOW_PREVIEW_RENDERERS),
124  array(self::CMD_SHOW_PREVIEW_RENDERERS, "view")
125  );
126  }
127 
128 
132  protected function initSettingsForm(): \ilPropertyFormGUI
133  {
134  global $DIC;
135  $ilCtrl = $DIC['ilCtrl'];
136  $lng = $DIC['lng'];
137 
138  $form = new ilPropertyFormGUI();
139  $form->setFormAction($ilCtrl->getFormAction($this));
140  $form->setTitle($lng->txt("settings"));
141 
142  // Backwards compatibility with ILIAS 3.9: Use the name of the
143  // uploaded file as the filename for the downloaded file instead
144  // of the title of the file object.
145  $dl_prop = new ilCheckboxInputGUI($lng->txt("download_with_uploaded_filename"), "download_with_uploaded_filename");
146  $dl_prop->setValue('1');
147  // default value should reflect previous behaviour (-> 0)
148  $dl_prop->setChecked($this->object->isDownloadWithUploadedFilename() == 1);
149  $dl_prop->setInfo($lng->txt('download_with_uploaded_filename_info'));
150  $form->addItem($dl_prop);
151 
152  // download limit
153  $lng->loadLanguageModule("bgtask");
154  $dl_prop = new ilNumberInputGUI($lng->txt("bgtask_setting_limit"), "bg_limit");
155  $dl_prop->setInfo($lng->txt("bgtask_setting_limit_info"));
156  $dl_prop->setRequired(true);
157  $dl_prop->setSize(10);
158  $dl_prop->setMinValue(1);
159  $dl_prop->setSuffix($lng->txt("lang_size_mb"));
160  $dl_prop->setValue($this->folderSettings->get("bgtask_download_limit", null));
161  $form->addItem($dl_prop);
162 
163  // Inline file extensions
164  $tai_prop = new ilTextAreaInputGUI($lng->txt('inline_file_extensions'), 'inline_file_extensions');
165  $tai_prop->setValue($this->object->getInlineFileExtensions());
166  $tai_prop->setInfo($lng->txt('inline_file_extensions_info'));
167  $tai_prop->setCols(80);
168  $tai_prop->setRows(5);
169  $form->addItem($tai_prop);
170 
171  // enable preview
172  $chk_prop = new ilCheckboxInputGUI($lng->txt("enable_preview"), "enable_preview");
173  $chk_prop->setValue('1');
174  $chk_prop->setChecked(ilPreviewSettings::isPreviewEnabled());
175  $chk_prop->setInfo($lng->txt('enable_preview_info'));
176  $form->addItem($chk_prop);
177 
178  // max preview images
179  $num_prop = new ilNumberInputGUI($lng->txt("max_previews_per_object"), "max_previews_per_object");
180  $num_prop->setDecimals(0);
181  $num_prop->setMinValue(1);
182  $num_prop->setMinvalueShouldBeGreater(false);
183  $num_prop->setMaxValue(ilPreviewSettings::MAX_PREVIEWS_MAX);
184  $num_prop->setMaxvalueShouldBeLess(false);
185  $num_prop->setMaxLength(5);
186  $num_prop->setSize(10);
187  $num_prop->setValue(ilPreviewSettings::getMaximumPreviews());
188  $num_prop->setInfo($lng->txt('max_previews_per_object_info'));
189  $form->addItem($num_prop);
190 
191  // command buttons
192  $form->addCommandButton('saveSettings', $lng->txt('save'));
193  $form->addCommandButton('view', $lng->txt('cancel'));
194 
195  return $form;
196  }
197 
198 
202  public function editSettings(ilPropertyFormGUI $a_form = null): void
203  {
204  global $DIC, $ilErr;
205 
206  $this->tabs_gui->setTabActive('file_objects');
207  $this->addFileObjectsSubTabs();
208  $this->tabs_gui->setSubTabActive('settings');
209 
210  if (!$DIC->rbac()->system()->checkAccess("visible,read", $this->object->getRefId())) {
211  $ilErr->raiseError($DIC->language()->txt("no_permission"), $ilErr->WARNING);
212  }
213 
214  if ($a_form === null) {
215  $a_form = $this->initSettingsForm();
216  }
217 
218  $DIC->ui()->mainTemplate()->setContent($a_form->getHTML());
219  }
220 
221 
225  public function saveSettings(): void
226  {
227  global $DIC;
228  $rbacsystem = $DIC['rbacsystem'];
229 
230  if (!$rbacsystem->checkAccess("write", $this->object->getRefId())) {
231  $this->tpl->setOnScreenMessage('failure', $DIC->language()->txt("no_permission"), true);
232  $DIC->ctrl()->redirect($this, self::CMD_EDIT_SETTINGS);
233  }
234 
235  $form = $this->initSettingsForm();
236  if ($form->checkInput()) {
237  // TODO switch to new forms
238  $post = (array) $this->http->request()->getParsedBody();
239  $this->object->setDownloadWithUploadedFilename(
240  ilUtil::stripSlashes($post['download_with_uploaded_filename'] ?? '')
241  );
242  $this->object->setInlineFileExtensions(
243  ilUtil::stripSlashes($post['inline_file_extensions'] ?? '')
244  );
245  $this->object->update();
246  $this->folderSettings->set("bgtask_download_limit", (int) $post["bg_limit"]);
247  $enable_preview = (int) ($post["enable_preview"] ?? 0);
248  ilPreviewSettings::setPreviewEnabled($enable_preview === 1);
249  ilPreviewSettings::setMaximumPreviews($post["max_previews_per_object"]);
250 
251  $this->tpl->setOnScreenMessage('success', $DIC->language()->txt('settings_saved'), true);
252  $DIC->ctrl()->redirect($this, self::CMD_EDIT_SETTINGS);
253  }
254 
255  $form->setValuesByPost();
256  $this->editSettings($form);
257  }
258 
259 
260  protected function showPreviewRenderers(): void
261  {
262  global $DIC;
263  $rbacsystem = $DIC['rbacsystem'];
264  $ilErr = $DIC['ilErr'];
265  $tpl = $DIC['tpl'];
266  $lng = $DIC['lng'];
267 
268  $this->tabs_gui->setTabActive('file_objects');
269  $this->addFileObjectsSubTabs();
270  $this->tabs_gui->setSubTabActive('preview_renderers');
271 
272  if (!$rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
273  $ilErr->raiseError($lng->txt("no_permission"), $ilErr->WARNING);
274  }
275 
276  // set warning if ghostscript not installed
278  $this->tpl->setOnScreenMessage('info', $lng->txt("ghostscript_not_configured"));
279  }
280 
281  $factory = new ilRendererFactory();
282  $renderers = $factory->getRenderers();
283  $array_wrapper = array_map(function (ilFilePreviewRenderer $renderer): array {
284  return [
285  'name' => $renderer->getName(),
286  'is_plugin' => $renderer->isPlugin(),
287  'supported_repo_types' => $renderer->getSupportedRepositoryTypes(),
288  'supported_file_formats' => $renderer->getSupportedFileFormats(),
289  'object' => $renderer
290  ];
291  }, $renderers);
292 
293 
294  $table = new ilRendererTableGUI($this, self::CMD_SHOW_PREVIEW_RENDERERS);
295  $table->setMaxCount(count($renderers));
296  $table->setData($array_wrapper);
297 
298  // set content
299  $tpl->setContent($table->getHTML());
300  }
301 
302 
306  protected function setTitleAndDescription(): void
307  {
308  parent::setTitleAndDescription();
309  $this->tpl->setDescription($this->object->getDescription());
310  }
311 }
static setPreviewEnabled(bool $a_value)
Sets whether the preview functionality is enabled.
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...
getName()
Gets the name of the renderer.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setDecimals(int $a_decimals)
static isGhostscriptInstalled()
Determines whether Ghostscript is installed.
prepareOutput(bool $show_sub_objects=true)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
__construct($a_data, int $a_id, bool $a_call_by_reference)
Constructor.
isPlugin()
Determines whether the renderer is a plugin or a built in one.
This class represents a checkbox property in a property form.
loadLanguageModule(string $a_module)
Load language module.
static setMaximumPreviews(int $a_value)
Sets the maximum number of preview pictures per object.
getSupportedFileFormats()
Gets an array containing the file formats that are supported by the renderer.
$ilErr
Definition: raiseError.php:17
Class ilObjFileAccessSettingsGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
ilLanguage $lng
static http()
Fetches the global http state from ILIAS.
ilGlobalTemplateInterface $tpl
setContent(string $a_html)
Sets content for standard template.
This class represents a number property in a property form.
Class ilObjectGUI Basic methods of all Output classes.
header include for all ilias files.
getSupportedRepositoryTypes()
Gets an array containing the repository types (e.g.
static getMaximumPreviews()
Gets the maximum number of preview pictures per object.
static isPreviewEnabled()
Gets whether the preview functionality is enabled.
__construct(Container $dic, ilPlugin $plugin)
This class represents a text area property in a property form.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
editSettings(ilPropertyFormGUI $a_form=null)
Edit settings.
$post
Definition: ltitoken.php:49
setTitleAndDescription()
called by prepare output
$factory
Definition: metadata.php:75