ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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 const string P_DOCUMENT_ID = 'document_id';
38 private UIFactory $ui_factory;
41
42 public function __construct(
43 private ilGlobalTemplateInterface $tpl,
44 private ilObjUser $user,
45 private ilCtrlInterface $ctrl,
46 private ilLanguage $lng,
47 private ilRbacSystem $rbacsystem,
48 private ilErrorHandling $error,
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, self::P_DOCUMENT_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
147 protected function showAddDocumentForm(): void
148 {
149 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
150 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
151 }
152
153 $form = $this->getDocumentForm(new ilWebDAVMountInstructionsDocument());
154 $this->tpl->setContent($form->getHTML());
155 }
156
157 protected function showEditDocumentForm(): void
158 {
159 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
160 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
161 }
162
163 $document_id = $this->http->wrapper()->query()->retrieve(self::P_DOCUMENT_ID, $this->refinery->kindlyTo()->int());
164 $document = $this->mount_instructions_repository->getMountInstructionsDocumentById($document_id);
165 $form = $this->getDocumentForm($document);
166 $this->tpl->setContent($form->getHTML());
167 }
168
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 ilWebDAVMountInstructionsDocument());
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
196 protected function saveEditDocumentForm(): void
197 {
198 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
199 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
200 }
201
202 $document_id = $this->http->wrapper()->query()->retrieve(self::P_DOCUMENT_ID, $this->refinery->kindlyTo()->int());
203 $form = $this->getDocumentForm(
204 $this->mount_instructions_repository->getMountInstructionsDocumentById($document_id)
205 );
206 if ($form->updateObject()) {
207 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
208 if ($form->hasTranslatedInfo()) {
209 $this->tpl->setOnScreenMessage('info', $form->getTranslatedInfo(), true);
210 }
211 $this->ctrl->redirect($this, 'showDocuments');
212 } elseif ($form->hasTranslatedError()) {
213 $this->tpl->setOnScreenMessage('failure', $form->getTranslatedError(), true);
214 }
215
216 $html = $form->getHTML();
217 $this->tpl->setContent($html);
218 }
219
220 protected function deleteDocument(): void
221 {
222 if (!$this->rbacsystem->checkAccess('delete', $this->webdav_object_ref_id)) {
223 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
224 }
225
226 $document_id = $this->http->wrapper()->query()->retrieve(self::P_DOCUMENT_ID, $this->refinery->kindlyTo()->int());
227
228 $this->mount_instructions_repository->deleteMountInstructionsById($document_id);
229 $this->tpl->setOnScreenMessage('success', $this->lng->txt('deleted_successfully'), true);
230 $this->ctrl->redirect($this, 'showDocuments');
231 }
232
233 public function saveDocumentSorting(): void
234 {
235 if (!$this->rbacsystem->checkAccess('write', $this->webdav_object_ref_id)) {
236 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
237 }
238
239 $sorting = $this->http->request()->getParsedBody()['sorting'] ?? [];
240 if (!is_array($sorting) || [] === $sorting) {
241 $this->showDocuments();
242 return;
243 }
244
245 // Sort array by give sort value
246 asort($sorting, SORT_NUMERIC);
247
248 $position = 0;
249 foreach (array_keys($sorting) as $document_id) {
250 // Only accept numbers
251 if (!is_numeric($document_id)) {
252 continue;
253 }
254
255 $this->mount_instructions_repository->updateSortingValueById((int) $document_id, ++$position);
256 }
257
258 $this->tpl->setOnScreenMessage('success', $this->lng->txt('webdav_saved_sorting'), true);
259 $this->ctrl->redirect($this);
260 }
261}
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
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 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
static http()
Fetches the global http state from ILIAS.
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))