ILIAS  release_8 Revision v8.24
class.ilWebDAVMountInstructionsUploadGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
24use ILIAS\Refinery\Factory as RefineryFactory;
25use ILIAS\UI\Factory as UIFactory;
28
34{
35 public const ACTION_SAVE_ADD_DOCUMENT_FORM = 'saveAddDocumentForm';
36 public const ACTION_SAVE_EDIT_DOCUMENT_FORM = 'saveEditDocumentForm';
37
44 private ilLogger $log;
46 private Services $http;
47 private RefineryFactory $refinery;
48 private UIFactory $ui_factory;
54
55 public function __construct(
65 RefineryFactory $refinery,
66 UIServices $ui,
70 ) {
71 $this->tpl = $tpl;
72 $this->ctrl = $ctrl;
73 $this->lng = $lng;
74 $this->rbacsystem = $rbacsystem;
75 $this->error = $error;
76 $this->user = $user;
77 $this->log = $log;
78 $this->toolbar = $toolbar;
79 $this->http = $http;
80 $this->refinery = $refinery;
81 $this->ui_factory = $ui->factory();
82 $this->ui_renderer = $ui->renderer();
83 $this->file_systems = $file_systems;
84 $this->file_upload = $file_upload;
85 $this->mount_instructions_repository = $mount_instructions_repository;
86
87 $this->lng->loadLanguageModule('meta');
88 }
89
93 public function executeCommand(): void
94 {
95 $cmd = $this->ctrl->getCmd();
96
97 if (!$this->rbacsystem->checkAccess('read', $this->webdav_object_ref_id)) {
98 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
99 }
100
101 if ($cmd == 'delete') {
102 $cmd .= 'Document';
103 }
104 if ($cmd == '' || !method_exists($this, $cmd)) {
105 $cmd = 'showDocuments';
106 }
107 $this->$cmd();
108 }
109
110 public function setRefId(int $ref_id): void
111 {
112 $this->webdav_object_ref_id = $ref_id;
113 }
114
118 protected function showDocuments(): void
119 {
120 if ($this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
121 $addDocumentBtn = ilLinkButton::getInstance();
122 $addDocumentBtn->setPrimary(true);
123 $addDocumentBtn->setUrl($this->ctrl->getLinkTarget($this, 'showAddDocumentForm'));
124 $addDocumentBtn->setCaption('webdav_add_instructions_btn_label');
125 $this->toolbar->addStickyItem($addDocumentBtn);
126 }
127
128 $uri_builder = new ilWebDAVUriBuilder($this->http->request());
129
130 $document_tbl_gui = new ilWebDAVMountInstructionsDocumentTableGUI(
131 $this,
132 $uri_builder,
133 'showDocuments',
134 $this->ui_factory,
135 $this->ui_renderer,
136 $this->http->request(),
137 $this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)
138 );
139 $document_tbl_gui->setProvider(new ilWebDAVMountInstructionsTableDataProvider($this->mount_instructions_repository));
140 $document_tbl_gui->populate();
141
142 $this->tpl->setContent($document_tbl_gui->getHTML());
143 }
144
146 {
147 if ($a_document->getId() > 0) {
148 $this->ctrl->setParameter($this, 'doc_id', $a_document->getId());
149
150 $form_action = $this->ctrl->getFormAction($this, self::ACTION_SAVE_EDIT_DOCUMENT_FORM);
152 } else {
153 $form_action = $this->ctrl->getFormAction($this, self::ACTION_SAVE_ADD_DOCUMENT_FORM);
155 }
156
158 $a_document,
159 $this->mount_instructions_repository,
161 $this->user,
162 $this->file_systems->temp(),
163 $this->file_upload,
164 $form_action,
165 $save_command,
166 'showDocuments',
167 $this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)
168 );
169
170 return $form;
171 }
172
173 protected function showAddDocumentForm(): void
174 {
175 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
176 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
177 }
178
180 $this->tpl->setContent($form->getHTML());
181 }
182
183 protected function showEditDocumentForm(): void
184 {
185 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
186 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
187 }
188
189 $document_id = $this->http->wrapper()->query()->retrieve('document_id', $this->refinery->kindlyTo()->int());
190 $document = $this->mount_instructions_repository->getMountInstructionsDocumentById($document_id);
191 $form = $this->getDocumentForm($document);
192 $this->tpl->setContent($form->getHTML());
193 }
194
198 protected function saveAddDocumentForm(): void
199 {
200 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
201 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
202 }
203
205 if ($form->saveObject()) {
206 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
207 if ($form->hasTranslatedInfo()) {
208 $this->tpl->setOnScreenMessage('info', $form->getTranslatedInfo(), true);
209 }
210 $this->ctrl->redirect($this, 'showDocuments');
211 } elseif ($form->hasTranslatedError()) {
212 $this->tpl->setOnScreenMessage('failure', $form->getTranslatedError(), true);
213 }
214
215 $html = $form->getHTML();
216 $this->tpl->setContent($html);
217 }
218
222 protected function saveEditDocumentForm(): void
223 {
224 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
225 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
226 }
227
228 $document_id = $this->http->wrapper()->query()->retrieve('document_id', $this->refinery->kindlyTo()->int());
229 $form = $this->getDocumentForm($this->mount_instructions_repository->getMountInstructionsDocumentById($document_id));
230 if ($form->updateObject()) {
231 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
232 if ($form->hasTranslatedInfo()) {
233 $this->tpl->setOnScreenMessage('info', $form->getTranslatedInfo(), true);
234 }
235 $this->ctrl->redirect($this, 'showDocuments');
236 } elseif ($form->hasTranslatedError()) {
237 $this->tpl->setOnScreenMessage('failure', $form->getTranslatedError(), true);
238 }
239
240 $html = $form->getHTML();
241 $this->tpl->setContent($html);
242 }
243
244 protected function deleteDocument(): void
245 {
246 if (!$this->rbacsystem->checkAccess('delete', $this->webdav_object_ref_id)) {
247 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
248 }
249
250 $document_id = $this->http->wrapper()->query()->retrieve('document_id', $this->refinery->kindlyTo()->int());
251
252 $this->mount_instructions_repository->deleteMountInstructionsById($document_id);
253 $this->tpl->setOnScreenMessage('success', $this->lng->txt('deleted_successfully'), true);
254 $this->ctrl->redirect($this, 'showDocuments');
255 }
256
257 public function saveDocumentSorting(): void
258 {
259 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
260 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
261 }
262
263 $sorting = $this->http->request()->getParsedBody()['sorting'] ?? [];
264 if (!is_array($sorting) || 0 === count($sorting)) {
265 $this->showDocuments();
266 return;
267 }
268
269 // Sort array by give sort value
270 asort($sorting, SORT_NUMERIC);
271
272 $position = 0;
273 foreach ($sorting as $document_id => $ignored_sort_value) {
274
275 // Only accept numbers
276 if (!is_numeric($document_id)) {
277 continue;
278 }
279
280 $this->mount_instructions_repository->updateSortingValueById((int) $document_id, ++$position);
281 }
282
283 $this->tpl->setOnScreenMessage('success', $this->lng->txt('webdav_saved_sorting'), true);
284 $this->ctrl->redirect($this);
285 }
286}
Provides fluid interface to RBAC services.
Definition: UIServices.php:24
renderer()
Get a renderer for UI components.
Definition: UIServices.php:43
factory()
Get the factory that crafts UI components.
Definition: UIServices.php:35
Builds data types.
Definition: Factory.php:21
Class Services.
Definition: Services.php:38
error(string $a_errmsg)
Error Handling & global info handling uses PEAR error class.
language handling
Component logger with individual log levels by component id.
User class.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
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 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...
ilWebDAVMountInstructionsRepository $mount_instructions_repository
getDocumentForm(ilWebDAVMountInstructionsDocument $a_document)
__construct(ilGlobalTemplateInterface $tpl, ilObjUser $user, ilCtrlInterface $ctrl, ilLanguage $lng, ilRbacSystem $rbacsystem, ilErrorHandling $error, ilLogger $log, ilToolbarGUI $toolbar, Services $http, RefineryFactory $refinery, UIServices $ui, Filesystems $file_systems, FileUpload $file_upload, ilWebDAVMountInstructionsRepository $mount_instructions_repository)
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
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 file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67
static http()
Fetches the global http state from ILIAS.