ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilWebDAVMountInstructionsUploadGUI.php
Go to the documentation of this file.
1<?php
2
8
14{
15 const ACTION_SAVE_ADD_DOCUMENT_FORM = 'saveAddDocumentForm';
16 const ACTION_SAVE_EDIT_DOCUMENT_FORM = 'saveEditDocumentForm';
17
18 public function __construct(
19 ilObjFileAccessSettings $file_access_settings,
21 ilObjUser $user,
22 ilCtrl $ctrl,
24 ilRbacSystem $rbacsystem,
25 ilErrorHandling $error,
27 ilToolbarGUI $toolbar,
28 GlobalHttpState $http_state,
29 Factory $ui_factory,
30 Renderer $ui_renderer,
31 Filesystems $file_systems,
32 FileUpload $file_upload,
33 ilWebDAVMountInstructionsRepository $mount_instructions_repository
34 ) {
35 $this->file_access_settings = $file_access_settings;
36 $this->tpl = $tpl;
37 $this->ctrl = $ctrl;
38 $this->lng = $lng;
39 $this->rbacsystem = $rbacsystem;
40 $this->error = $error;
41 $this->user = $user;
42 $this->log = $log;
43 $this->toolbar = $toolbar;
44 $this->http_state = $http_state;
45 $this->ui_factory = $ui_factory;
46 $this->ui_renderer = $ui_renderer;
47 $this->file_systems = $file_systems;
48 $this->file_upload = $file_upload;
49 $this->mount_instructions_repository = $mount_instructions_repository;
50 }
51
55 public function executeCommand() : void
56 {
57 $cmd = $this->ctrl->getCmd();
58
59 if (!$this->rbacsystem->checkAccess('read', $this->file_access_settings->getRefId())) {
60 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
61 }
62
63 if ($cmd == '' || !method_exists($this, $cmd)) {
64 $cmd = 'showDocuments';
65 }
66 $this->$cmd();
67 }
68
72 protected function showDocuments() : void
73 {
74 if ($this->rbacsystem->checkAccess('write', $this->file_access_settings->getRefId())) {
75 $addDocumentBtn = ilLinkButton::getInstance();
76 $addDocumentBtn->setPrimary(true);
77 $addDocumentBtn->setUrl($this->ctrl->getLinkTarget($this, 'showAddDocumentForm'));
78 $addDocumentBtn->setCaption('webdav_add_instructions_btn_label');
79 $this->toolbar->addStickyItem($addDocumentBtn);
80 }
81
82 $uri_builder = new ilWebDAVUriBuilder($this->http_state->request());
83
84 $document_tbl_gui = new ilWebDAVMountInstructionsDocumentTableGUI(
85 $this,
86 $uri_builder,
87 'showDocuments',
88 $this->ui_factory,
89 $this->ui_renderer,
90 $this->rbacsystem->checkAccess('write', $this->file_access_settings->getRefId())
91 );
92 $document_tbl_gui->setProvider(new ilWebDAVMountInstructionsTableDataProvider($this->mount_instructions_repository));
93 $document_tbl_gui->populate();
94
95 $this->tpl->setContent($document_tbl_gui->getHTML());
96 }
97
103 {
104 if ($a_document->getId() > 0) {
105 $this->ctrl->setParameter($this, 'doc_id', $a_document->getId());
106
107 $form_action = $this->ctrl->getFormAction($this, self::ACTION_SAVE_EDIT_DOCUMENT_FORM);
109 } else {
110 $form_action = $this->ctrl->getFormAction($this, self::ACTION_SAVE_ADD_DOCUMENT_FORM);
112 }
113
115 $a_document,
116 $this->mount_instructions_repository,
118 $this->user,
119 $this->file_systems->temp(),
120 $this->file_upload,
121 $form_action,
122 $save_command,
123 'showDocuments',
124 $this->rbacsystem->checkAccess('write', $this->file_access_settings->getRefId())
125 );
126
127 return $form;
128 }
129
130 protected function showAddDocumentForm()
131 {
132 if (!$this->rbacsystem->checkAccess('write', $this->file_access_settings->getRefId())) {
133 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
134 }
135
137 $this->tpl->setContent($form->getHTML());
138 }
139
140 protected function showEditDocumentForm()
141 {
142 if (!$this->rbacsystem->checkAccess('write', $this->file_access_settings->getRefId())) {
143 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
144 }
145
146 $document_id = $_REQUEST['webdav_id'];
147 $document = $this->mount_instructions_repository->getMountInstructionsDocumentById($document_id);
148 $form = $this->getDocumentForm($document);
149 $this->tpl->setContent($form->getHTML());
150 }
151
155 protected function saveAddDocumentForm()
156 {
157 if (!$this->rbacsystem->checkAccess('write', $this->file_access_settings->getRefId())) {
158 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
159 }
160
162 if ($form->saveObject()) {
163 ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
164 if ($form->hasTranslatedInfo()) {
165 ilUtil::sendInfo($form->getTranslatedInfo(), true);
166 }
167 $this->ctrl->redirect($this, 'showDocuments');
168 } elseif ($form->hasTranslatedError()) {
169 ilUtil::sendFailure($form->getTranslatedError(), true);
170 }
171
172 $html = $form->getHTML();
173 $this->tpl->setContent($html);
174 }
175
179 protected function saveEditDocumentForm()
180 {
181 if (!$this->rbacsystem->checkAccess('write', $this->file_access_settings->getRefId())) {
182 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
183 }
184
185 $form = $this->getDocumentForm(new ilWebDAVMountInstructionsDocument((int) $_REQUEST['webdav_id']));
186 if ($form->updateObject()) {
187 ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
188 if ($form->hasTranslatedInfo()) {
189 ilUtil::sendInfo($form->getTranslatedInfo(), true);
190 }
191 $this->ctrl->redirect($this, 'showDocuments');
192 } elseif ($form->hasTranslatedError()) {
193 ilUtil::sendFailure($form->getTranslatedError(), true);
194 }
195
196 $html = $form->getHTML();
197 $this->tpl->setContent($html);
198 }
199
200 protected function getDocumentByServerRequest()
201 {
202 return $this->httpState->request() - getParsedBody()['instructions_id'] ?? [];
203 }
204
205 protected function deleteDocument()
206 {
207 if (!$this->rbacsystem->checkAccess('delete', $this->file_access_settings->getRefId())) {
208 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
209 } else {
210 $webdav_id = $_REQUEST['webdav_id'];
211 $this->mount_instructions_repository->deleteMountInstructionsById($webdav_id);
212 ilUtil::sendSuccess($this->lng->txt('deleted_successfully'), true);
213 $this->ctrl->redirect($this, 'showDocuments');
214 }
215 }
216
217 public function saveDocumentSorting()
218 {
219 if (!$this->rbacsystem->checkAccess('write', $this->file_access_settings->getRefId())) {
220 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
221 }
222
223 $sorting = $this->http_state->request()->getParsedBody()['sorting'] ?? [];
224 if (!is_array($sorting) || 0 === count($sorting)) {
225 $this->showDocuments();
226 return;
227 }
228
229 // Sort array by give sort value
230 asort($sorting, SORT_NUMERIC);
231
232 $position = 0;
233 foreach ($sorting as $document_id => $ignored_sort_value) {
234
235 // Only accept numbers
236 if (!is_numeric($document_id)) {
237 continue;
238 }
239
240 $this->mount_instructions_repository->updateSortingValueById((int) $document_id, ++$position);
241 }
242
243 ilUtil::sendSuccess($this->lng->txt('webdav_saved_sorting'), true);
244 $this->ctrl->redirect($this);
245 }
246}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
This class provides processing control methods.
Class ilGlobalPageTemplate.
language handling
static getInstance()
Factory.
Component logger with individual log levels by component id.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
getDocumentForm(ilWebDAVMountInstructionsDocument $a_document)
__construct(ilObjFileAccessSettings $file_access_settings, ilGlobalPageTemplate $tpl, ilObjUser $user, ilCtrl $ctrl, ilLanguage $lng, ilRbacSystem $rbacsystem, ilErrorHandling $error, ilLogger $log, ilToolbarGUI $toolbar, GlobalHttpState $http_state, Factory $ui_factory, Renderer $ui_renderer, Filesystems $file_systems, FileUpload $file_upload, ilWebDAVMountInstructionsRepository $mount_instructions_repository)
Interface GlobalHttpState.
This is how the factory for UI elements looks.
Definition: Factory.php:18
An entity that renders components to a string output.
Definition: Renderer.php:15
Interface ilWebDAVMountInstructionsRepository.
$log
Definition: result.php:15
$lng
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl