ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilWebDAVMountInstructionsUploadGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 
34 {
35  public const ACTION_SAVE_ADD_DOCUMENT_FORM = 'saveAddDocumentForm';
36  public const ACTION_SAVE_EDIT_DOCUMENT_FORM = 'saveEditDocumentForm';
39  private int $webdav_object_ref_id;
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);
127  $save_command = self::ACTION_SAVE_EDIT_DOCUMENT_FORM;
128  } else {
129  $form_action = $this->ctrl->getFormAction($this, self::ACTION_SAVE_ADD_DOCUMENT_FORM);
130  $save_command = 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 
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 
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 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$http
Definition: deliver.php:30
Provides fluid interface to RBAC services.
Definition: UIServices.php:24
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)
static http()
Fetches the global http state from ILIAS.
$ref_id
Definition: ltiauth.php:65
$log
Definition: result.php:32
renderer()
Get a renderer for UI components.
Definition: UIServices.php:44
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class FileUpload.
Definition: FileUpload.php:37
global $lng
Definition: privfeed.php:31
factory()
Get the factory that crafts UI components.
Definition: UIServices.php:36
The Filesystems interface defines the access methods which can be used to fetch the different filesys...
Definition: Filesystems.php:29