ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
UploadGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\WebDAV\Mount;
22
26use ILIAS\Refinery\Factory as RefineryFactory;
27use ILIAS\UI\Factory as UIFactory;
32use ilObjUser;
34use ilLanguage;
35use ilRbacSystem;
37use ilToolbarGUI;
38
43{
44 public const string ACTION_SAVE_ADD_DOCUMENT_FORM = 'saveAddDocumentForm';
45 public const string ACTION_SAVE_EDIT_DOCUMENT_FORM = 'saveEditDocumentForm';
46 private const string P_DOCUMENT_ID = 'document_id';
47
48 private UIFactory $ui_factory;
51
52 public function __construct(
53 private ilGlobalTemplateInterface $tpl,
54 private ilObjUser $user,
55 private ilCtrlInterface $ctrl,
56 private ilLanguage $lng,
57 private ilRbacSystem $rbacsystem,
58 private ilErrorHandling $error,
59 private ilToolbarGUI $toolbar,
60 private Services $http,
61 private RefineryFactory $refinery,
62 UIServices $ui,
63 private Filesystems $file_systems,
64 private FileUpload $file_upload,
65 private Repository $mount_instructions_repository
66 ) {
67 $this->ui_factory = $ui->factory();
68 $this->ui_renderer = $ui->renderer();
69
70 $this->lng->loadLanguageModule('meta');
71 }
72
73 public function executeCommand(): void
74 {
75 $cmd = $this->ctrl->getCmd();
76
77 if (!$this->rbacsystem->checkAccess('read', $this->webdav_object_ref_id)) {
78 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
79 }
80
81 if ($cmd === 'delete') {
82 $cmd .= 'Document';
83 }
84 if ($cmd === '' || !method_exists($this, $cmd)) {
85 $cmd = 'showDocuments';
86 }
87 $this->$cmd();
88 }
89
90 public function setRefId(int $ref_id): void
91 {
92 $this->webdav_object_ref_id = $ref_id;
93 }
94
95 protected function showDocuments(): void
96 {
97 if ($this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
98 $document_button = $this->ui_factory->link()->standard(
99 $this->lng->txt('webdav_add_instructions_btn_label'),
100 $this->ctrl->getLinkTarget($this, 'showAddDocumentForm')
101 );
102 $this->toolbar->addStickyItem($document_button);
103 }
104
105 $uri_builder = new UriBuilder($this->http->request(), new Config());
106
107 $document_tbl_gui = new DocumentTableGUI(
108 $this,
109 $uri_builder,
110 'showDocuments',
111 $this->ui_factory,
112 $this->ui_renderer,
113 $this->http->request(),
114 $this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)
115 );
116 $document_tbl_gui->setProvider(
117 new TableDataProvider($this->mount_instructions_repository)
118 );
119 $document_tbl_gui->populate();
120
121 $this->tpl->setContent($document_tbl_gui->getHTML());
122 }
123
124 protected function getDocumentForm(Document $a_document): DocumentFormGUI
125 {
126 if ($a_document->getId() > 0) {
127 $this->ctrl->setParameter($this, self::P_DOCUMENT_ID, $a_document->getId());
128
129 $form_action = $this->ctrl->getFormAction($this, self::ACTION_SAVE_EDIT_DOCUMENT_FORM);
131 } else {
132 $form_action = $this->ctrl->getFormAction($this, self::ACTION_SAVE_ADD_DOCUMENT_FORM);
134 }
135
136 return new DocumentFormGUI(
137 $a_document,
138 $this->mount_instructions_repository,
139 new DocumentPurifier(),
140 $this->user,
141 $this->file_systems->temp(),
142 $this->file_upload,
143 $form_action,
144 $save_command,
145 'showDocuments',
146 $this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)
147 );
148 }
149
150 protected function showAddDocumentForm(): void
151 {
152 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
153 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
154 }
155
156 $form = $this->getDocumentForm(new Document());
157 $this->tpl->setContent($form->getHTML());
158 }
159
160 protected function showEditDocumentForm(): void
161 {
162 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
163 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
164 }
165
166 $document_id = $this->http->wrapper()->query()->retrieve(self::P_DOCUMENT_ID, $this->refinery->kindlyTo()->int());
167 $document = $this->mount_instructions_repository->getMountInstructionsDocumentById($document_id);
168 $form = $this->getDocumentForm($document);
169 $this->tpl->setContent($form->getHTML());
170 }
171
172 protected function saveAddDocumentForm(): void
173 {
174 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
175 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
176 }
177
178 $form = $this->getDocumentForm(new Document());
179 if ($form->saveObject()) {
180 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
181 if ($form->hasTranslatedInfo()) {
182 $this->tpl->setOnScreenMessage('info', $form->getTranslatedInfo(), true);
183 }
184 $this->ctrl->redirect($this, 'showDocuments');
185 } elseif ($form->hasTranslatedError()) {
186 $this->tpl->setOnScreenMessage('failure', $form->getTranslatedError(), true);
187 }
188
189 $html = $form->getHTML();
190 $this->tpl->setContent($html);
191 }
192
193 protected function saveEditDocumentForm(): void
194 {
195 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
196 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
197 }
198
199 $document_id = $this->http->wrapper()->query()->retrieve(self::P_DOCUMENT_ID, $this->refinery->kindlyTo()->int());
200 $form = $this->getDocumentForm(
201 $this->mount_instructions_repository->getMountInstructionsDocumentById($document_id)
202 );
203 if ($form->updateObject()) {
204 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
205 if ($form->hasTranslatedInfo()) {
206 $this->tpl->setOnScreenMessage('info', $form->getTranslatedInfo(), true);
207 }
208 $this->ctrl->redirect($this, 'showDocuments');
209 } elseif ($form->hasTranslatedError()) {
210 $this->tpl->setOnScreenMessage('failure', $form->getTranslatedError(), true);
211 }
212
213 $html = $form->getHTML();
214 $this->tpl->setContent($html);
215 }
216
217 protected function deleteDocument(): void
218 {
219 if (!$this->rbacsystem->checkAccess('delete', $this->webdav_object_ref_id)) {
220 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
221 }
222
223 $document_id = $this->http->wrapper()->query()->retrieve(self::P_DOCUMENT_ID, $this->refinery->kindlyTo()->int());
224
225 $this->mount_instructions_repository->deleteMountInstructionsById($document_id);
226 $this->tpl->setOnScreenMessage('success', $this->lng->txt('deleted_successfully'), true);
227 $this->ctrl->redirect($this, 'showDocuments');
228 }
229
230 public function saveDocumentSorting(): void
231 {
232 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
233 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
234 }
235
236 $sorting = $this->http->request()->getParsedBody()['sorting'] ?? [];
237 if (!is_array($sorting) || $sorting === []) {
238 $this->showDocuments();
239 return;
240 }
241
242 asort($sorting, SORT_NUMERIC);
243
244 $position = 0;
245 foreach (array_keys($sorting) as $document_id) {
246 if (!is_numeric($document_id)) {
247 continue;
248 }
249
250 $this->mount_instructions_repository->updateSortingValueById((int) $document_id, ++$position);
251 }
252
253 $this->tpl->setOnScreenMessage('success', $this->lng->txt('webdav_saved_sorting'), true);
254 $this->ctrl->redirect($this);
255 }
256}
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
renderer()
Get a renderer for UI components.
Definition: UIServices.php:44
factory()
Get the factory that crafts UI components.
Definition: UIServices.php:36
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
@ilCtrl_isCalledBy ILIAS\WebDAV\Mount\UploadGUI: ilObjWebDAVGUI
Definition: UploadGUI.php:43
getDocumentForm(Document $a_document)
Definition: UploadGUI.php:124
const string ACTION_SAVE_ADD_DOCUMENT_FORM
Definition: UploadGUI.php:44
__construct(private ilGlobalTemplateInterface $tpl, private ilObjUser $user, private ilCtrlInterface $ctrl, private ilLanguage $lng, private ilRbacSystem $rbacsystem, private ilErrorHandling $error, private ilToolbarGUI $toolbar, private Services $http, private RefineryFactory $refinery, UIServices $ui, private Filesystems $file_systems, private FileUpload $file_upload, private Repository $mount_instructions_repository)
Definition: UploadGUI.php:52
const string ACTION_SAVE_EDIT_DOCUMENT_FORM
Definition: UploadGUI.php:45
ilErrorHandling $error
Definition: class.ilias.php:69
error(string $a_errmsg)
Error Handling & global info handling.
language handling
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...
$http
Definition: deliver.php:30
The Filesystems interface defines the access methods which can be used to fetch the different filesys...
Definition: Filesystems.php:30
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...
$ref_id
Definition: ltiauth.php:66
static http()
Fetches the global http state from ILIAS.
global $lng
Definition: privfeed.php:26