ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWebDAVMountInstructionsUploadGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
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 private UIFactory $ui_factory;
40
41 public function __construct(
42 private ilGlobalTemplateInterface $tpl,
43 private ilObjUser $user,
44 private ilCtrlInterface $ctrl,
45 private ilLanguage $lng,
46 private ilRbacSystem $rbacsystem,
47 private ilErrorHandling $error,
48 private ilLogger $log,
49 private ilToolbarGUI $toolbar,
50 private Services $http,
51 private RefineryFactory $refinery,
52 UIServices $ui,
53 private Filesystems $file_systems,
54 private FileUpload $file_upload,
55 private ilWebDAVMountInstructionsRepository $mount_instructions_repository
56 ) {
57 $this->ui_factory = $ui->factory();
58 $this->ui_renderer = $ui->renderer();
59
60 $this->lng->loadLanguageModule('meta');
61 }
62
66 public function executeCommand(): void
67 {
68 $cmd = $this->ctrl->getCmd();
69
70 if (!$this->rbacsystem->checkAccess('read', $this->webdav_object_ref_id)) {
71 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
72 }
73
74 if ($cmd == 'delete') {
75 $cmd .= 'Document';
76 }
77 if ($cmd == '' || !method_exists($this, $cmd)) {
78 $cmd = 'showDocuments';
79 }
80 $this->$cmd();
81 }
82
83 public function setRefId(int $ref_id): void
84 {
85 $this->webdav_object_ref_id = $ref_id;
86 }
87
91 protected function showDocuments(): void
92 {
93 if ($this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
94 $document_button = $this->ui_factory->link()->standard(
95 $this->lng->txt('webdav_add_instructions_btn_label'),
96 $this->ctrl->getLinkTarget($this, 'showAddDocumentForm')
97 );
98 $this->toolbar->addStickyItem($document_button);
99 }
100
101 $uri_builder = new ilWebDAVUriBuilder($this->http->request());
102
103 $document_tbl_gui = new ilWebDAVMountInstructionsDocumentTableGUI(
104 $this,
105 $uri_builder,
106 'showDocuments',
107 $this->ui_factory,
108 $this->ui_renderer,
109 $this->http->request(),
110 $this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)
111 );
112 $document_tbl_gui->setProvider(
113 new ilWebDAVMountInstructionsTableDataProvider($this->mount_instructions_repository)
114 );
115 $document_tbl_gui->populate();
116
117 $this->tpl->setContent($document_tbl_gui->getHTML());
118 }
119
120 protected function getDocumentForm(
123 if ($a_document->getId() > 0) {
124 $this->ctrl->setParameter($this, 'doc_id', $a_document->getId());
125
126 $form_action = $this->ctrl->getFormAction($this, self::ACTION_SAVE_EDIT_DOCUMENT_FORM);
128 } else {
129 $form_action = $this->ctrl->getFormAction($this, self::ACTION_SAVE_ADD_DOCUMENT_FORM);
131 }
132
134 $a_document,
135 $this->mount_instructions_repository,
137 $this->user,
138 $this->file_systems->temp(),
139 $this->file_upload,
140 $form_action,
141 $save_command,
142 'showDocuments',
143 $this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)
144 );
145
146 return $form;
147 }
148
149 protected function showAddDocumentForm(): void
150 {
151 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
152 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
153 }
154
155 $form = $this->getDocumentForm(new ilWebDAVMountInstructionsDocument());
156 $this->tpl->setContent($form->getHTML());
157 }
158
159 protected function showEditDocumentForm(): void
160 {
161 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
162 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
163 }
164
165 $document_id = $this->http->wrapper()->query()->retrieve('document_id', $this->refinery->kindlyTo()->int());
166 $document = $this->mount_instructions_repository->getMountInstructionsDocumentById($document_id);
167 $form = $this->getDocumentForm($document);
168 $this->tpl->setContent($form->getHTML());
169 }
170
174 protected function saveAddDocumentForm(): void
175 {
176 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
177 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
178 }
179
180 $form = $this->getDocumentForm(new ilWebDAVMountInstructionsDocument());
181 if ($form->saveObject()) {
182 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
183 if ($form->hasTranslatedInfo()) {
184 $this->tpl->setOnScreenMessage('info', $form->getTranslatedInfo(), true);
185 }
186 $this->ctrl->redirect($this, 'showDocuments');
187 } elseif ($form->hasTranslatedError()) {
188 $this->tpl->setOnScreenMessage('failure', $form->getTranslatedError(), true);
189 }
190
191 $html = $form->getHTML();
192 $this->tpl->setContent($html);
193 }
194
198 protected function saveEditDocumentForm(): 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
204 $document_id = $this->http->wrapper()->query()->retrieve('document_id', $this->refinery->kindlyTo()->int());
205 $form = $this->getDocumentForm(
206 $this->mount_instructions_repository->getMountInstructionsDocumentById($document_id)
207 );
208 if ($form->updateObject()) {
209 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
210 if ($form->hasTranslatedInfo()) {
211 $this->tpl->setOnScreenMessage('info', $form->getTranslatedInfo(), true);
212 }
213 $this->ctrl->redirect($this, 'showDocuments');
214 } elseif ($form->hasTranslatedError()) {
215 $this->tpl->setOnScreenMessage('failure', $form->getTranslatedError(), true);
216 }
217
218 $html = $form->getHTML();
219 $this->tpl->setContent($html);
220 }
221
222 protected function deleteDocument(): void
223 {
224 if (!$this->rbacsystem->checkAccess('delete', $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
230 $this->mount_instructions_repository->deleteMountInstructionsById($document_id);
231 $this->tpl->setOnScreenMessage('success', $this->lng->txt('deleted_successfully'), true);
232 $this->ctrl->redirect($this, 'showDocuments');
233 }
234
235 public function saveDocumentSorting(): void
236 {
237 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
238 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
239 }
240
241 $sorting = $this->http->request()->getParsedBody()['sorting'] ?? [];
242 if (!is_array($sorting) || [] === $sorting) {
243 $this->showDocuments();
244 return;
245 }
246
247 // Sort array by give sort value
248 asort($sorting, SORT_NUMERIC);
249
250 $position = 0;
251 foreach (array_keys($sorting) as $document_id) {
252 // Only accept numbers
253 if (!is_numeric($document_id)) {
254 continue;
255 }
256
257 $this->mount_instructions_repository->updateSortingValueById((int) $document_id, ++$position);
258 }
259
260 $this->tpl->setOnScreenMessage('success', $this->lng->txt('webdav_saved_sorting'), true);
261 $this->ctrl->redirect($this);
262 }
263}
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
error(string $a_errmsg)
Error Handling & global info handling.
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...
getDocumentForm(ilWebDAVMountInstructionsDocument $a_document)
__construct(private ilGlobalTemplateInterface $tpl, private ilObjUser $user, private ilCtrlInterface $ctrl, private ilLanguage $lng, private ilRbacSystem $rbacsystem, private ilErrorHandling $error, private ilLogger $log, private ilToolbarGUI $toolbar, private Services $http, private RefineryFactory $refinery, UIServices $ui, private Filesystems $file_systems, private FileUpload $file_upload, private ilWebDAVMountInstructionsRepository $mount_instructions_repository)
$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
$log
Definition: ltiresult.php:34
static http()
Fetches the global http state from ILIAS.
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))