ILIAS  release_8 Revision v8.24
class.ilMMTopItemGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Renderer\Hasher;
24
32{
33 use Hasher;
34
35 public const CMD_VIEW_TOP_ITEMS = 'subtab_topitems';
36 public const CMD_ADD = 'topitem_add';
37 public const CMD_RESTORE = 'restore';
38 public const CMD_CREATE = 'topitem_create';
39 public const CMD_EDIT = 'topitem_edit';
40 public const CMD_DELETE = 'delete';
41 public const CMD_CONFIRM_DELETE = 'topitem_confirm_delete';
42 public const CMD_TRANSLATE = 'topitem_translate';
43 public const CMD_UPDATE = 'topitem_update';
44 public const CMD_SAVE_TABLE = 'save_table';
45 public const CMD_CANCEL = 'cancel';
46 public const CMD_RENDER_INTERRUPTIVE = 'render_interruptive_modal';
47 public const CMD_CONFIRM_RESTORE = 'confirmRestore';
48 public const CMD_UPLOAD = 'upload';
49 public const CMD_SELECT_PARENT = 'selectParent';
50 public const CMD_MOVE = 'move';
51
52 private function dispatchCommand(string $cmd): string
53 {
54 global $DIC;
55 switch ($cmd) {
57 $this->access->checkAccessAndThrowException("visible,read");
58 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, $cmd);
59
60 return $this->index();
61 case self::CMD_ADD:
62 $this->access->checkAccessAndThrowException('write');
63 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
64
65 return $this->add($DIC);
67 $this->access->checkAccessAndThrowException('write');
68 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
69
70 return $this->create($DIC);
71 case self::CMD_EDIT:
72 $this->access->checkAccessAndThrowException('write');
73 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
74
75 return $this->edit($DIC);
77 $this->access->checkAccessAndThrowException('write');
78 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
79
80 return $this->update($DIC);
82 $this->access->checkAccessAndThrowException('write');
83 $this->saveTable();
84
85 break;
87 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
88 $this->access->checkAccessAndThrowException('write');
89
90 return $this->confirmDelete();
92 $this->access->checkAccessAndThrowException('write');
93 $this->delete();
94 break;
96 $this->cancel();
97 break;
99 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
100 $this->access->checkAccessAndThrowException('write');
101 return $this->confirmRestore();
103 $this->access->checkAccessAndThrowException('write');
104
105 $this->restore();
106 break;
108 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
109 $this->access->checkAccessAndThrowException('write');
110 return $this->selectParent();
111 case self::CMD_FLUSH:
112 $this->access->checkAccessAndThrowException('write');
113 $this->flush();
114 break;
115 case self::CMD_UPLOAD:
116 $this->access->checkAccessAndThrowException('write');
117 return $this->selectParent();
118 case self::CMD_MOVE:
119 $this->access->checkAccessAndThrowException('write');
120 $this->move();
121 break;
122 }
123
124 return "";
125 }
126
127 private function saveTable(): void
128 {
129 global $DIC;
130 $r = $DIC->http()->request()->getParsedBody();
131 foreach ($r[self::IDENTIFIER] as $identification_string => $data) {
132 $item = $this->repository->getItemFacadeForIdentificationString($this->unhash($identification_string));
133 $item->setPosition((int) ($data['position'] ?? 999));
134 $item->setActiveStatus((bool) ($data['active'] ?? false));
135 $this->repository->updateItem($item);
136 }
137 $this->cancel();
138 }
139
140 public function executeCommand(): void
141 {
142 $next_class = $this->ctrl->getNextClass();
143
144 if ($next_class === '') {
145 $cmd = $this->determineCommand(self::CMD_VIEW_TOP_ITEMS, self::CMD_DELETE);
146 $this->tpl->setContent($this->dispatchCommand($cmd));
147
148 return;
149 }
150
151 switch ($next_class) {
152 case strtolower(ilMMItemTranslationGUI::class):
153 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true);
154 $g = new ilMMItemTranslationGUI($this->getMMItemFromRequest(), $this->repository);
155 $this->ctrl->forwardCommand($g);
156 break;
157 default:
158 break;
159 }
160 }
161
165 private function index(): string
166 {
167 if ($this->access->hasUserPermissionTo('write')) {
168 // ADD NEW
170 $b->setCaption($this->lng->txt(self::CMD_ADD), false);
171 $b->setUrl($this->ctrl->getLinkTarget($this, self::CMD_ADD));
172 $this->toolbar->addButtonInstance($b);
173
174 // RESTORE
176 $b->setCaption($this->lng->txt(self::CMD_RESTORE), false);
177 $b->setUrl($this->ctrl->getLinkTarget($this, self::CMD_CONFIRM_RESTORE));
178 $this->toolbar->addButtonInstance($b);
179
180 // REMOVE LOST ITEMS
181 if ($this->repository->hasLostItems()) {
183 $b->setUrl($this->ctrl->getLinkTarget($this, self::CMD_FLUSH));
184 $b->setCaption($this->lng->txt(self::CMD_FLUSH), false);
185 $this->toolbar->addButtonInstance($b);
186 }
187 }
188
189 // TABLE
190 $table = new ilMMTopItemTableGUI($this, new ilMMItemRepository(), $this->access);
191 $table->setShowRowsSelector(false);
192
193 return $table->getHTML();
194 }
195
196 protected function cancel(): void
197 {
198 $this->ctrl->redirectByClass(self::class, self::CMD_VIEW_TOP_ITEMS);
199 }
200
201 private function doubleCancel(): void
202 {
203 $this->ctrl->redirectByClass(self::class, self::CMD_CANCEL);
204 }
205
211 private function add(Container $DIC): string
212 {
213 $f = new ilMMTopItemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $DIC->http(), $this->repository->getItemFacade(), $this->repository);
214
215 return $f->getHTML();
216 }
217
223 private function create(Container $DIC): string
224 {
225 $f = new ilMMTopItemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $DIC->http(), $this->repository->getItemFacade(), $this->repository);
226 if ($f->save()) {
227 $this->cancel();
228 }
229
230 return $f->getHTML();
231 }
232
238 private function edit(Container $DIC): string
239 {
240 $f = new ilMMTopItemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $DIC->http(), $this->getMMItemFromRequest(), $this->repository);
241
242 return $f->getHTML();
243 }
244
250 private function update(Container $DIC): string
251 {
252 $item = $this->getMMItemFromRequest();
253 if ($item->isEditable()) {
254 $f = new ilMMTopItemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $DIC->http(), $item, $this->repository);
255 if ($f->save()) {
256 $this->cancel();
257 }
258
259 return $f->getHTML();
260 }
261
262 return "";
263 }
264
265 private function delete(): void
266 {
267 $item = $this->getMMItemFromRequest();
268 if ($item->isDeletable()) {
269 $this->repository->deleteItem($item);
270 }
271 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_topitem_deleted"), true);
272 $this->cancel();
273 }
274
279 private function confirmDelete(): string
280 {
281 $this->ctrl->saveParameterByClass(self::class, self::IDENTIFIER);
282 $i = $this->getMMItemFromRequest();
283 $c = new ilConfirmationGUI();
284 $c->addItem(self::IDENTIFIER, $this->hash($i->getId()), $i->getDefaultTitle());
285 $c->setFormAction($this->ctrl->getFormActionByClass(self::class));
286 $c->setConfirm($this->lng->txt(self::CMD_DELETE), self::CMD_DELETE);
287 $c->setCancel($this->lng->txt(self::CMD_CANCEL), self::CMD_CANCEL);
288 $c->setHeaderText($this->lng->txt(self::CMD_CONFIRM_DELETE));
289
290 return $c->getHTML();
291 }
292
293 private function confirmRestore(): string
294 {
295 $c = new ilConfirmationGUI();
296 $c->setFormAction($this->ctrl->getFormActionByClass(self::class));
297 $c->setConfirm($this->lng->txt(self::CMD_DELETE), self::CMD_RESTORE);
298 $c->setCancel($this->lng->txt(self::CMD_CANCEL), self::CMD_CANCEL);
299 $c->setHeaderText($this->lng->txt('msg_restore_confirm'));
300
301 return $c->getHTML();
302 }
303
304
305 private function restore(): void
306 {
311
312 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_restored'), true);
313
314 $this->cancel();
315 }
316
317 private function selectParent(): string
318 {
319 $form = $this->getMoveForm();
320
321 return $this->ui->renderer()->render($form);
322 }
323
324 private function move(): void
325 {
326 $form = $this->getMoveForm();
327 $form = $form->withRequest($this->http->request());
328
329 $item = $this->getMMItemFromRequest();
330
331 $data = $form->getData();
332 if ($item->isInterchangeable() && isset($data[0])) {
333 $f = $this->repository->getItemFacadeForIdentificationString($data[0]);
334 $item->setParent($data[0]);
335 $this->repository->updateItem($item);
336 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_moved'), true);
337 } else {
338 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_not_moved'), true);
339 }
340
341 $this->cancel();
342 }
343
347 private function getMoveForm(): Standard
348 {
349 $this->ctrl->saveParameter($this, self::IDENTIFIER);
350 $f = $this->ui->factory();
351
352 $parent = $f->input()->field()->select($this->lng->txt('select_parent'), $this->repository->getPossibleParentsForFormAndTable())->withRequired(true);
353
354 return $f->input()->container()->form()->standard($this->ctrl->getFormAction($this, self::CMD_MOVE), [$parent]);
355 }
356}
static flushDB()
@depracated never use in ILIAS Core, Plugins only
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilMMAbstractItemGUI.
determineCommand(string $standard, string $delete)
Class ilMMItemRepository.
Class ilMMItemTranslationGUI.
Class ilMMTopItemFormGUI.
Class ilMMTopItemGUI @ilCtrl_IsCalledBy ilMMTopItemGUI: ilObjMainMenuGUI @ilCtrl_Calls ilMMTopItemGUI...
update(Container $DIC)
dispatchCommand(string $cmd)
create(Container $DIC)
edit(Container $DIC)
add(Container $DIC)
Class ilMMTopItemTableGUI.
$c
Definition: cli.php:38
global $DIC
Definition: feed.php:28
This describes a standard form.
Definition: Standard.php:27
$i
Definition: metadata.php:41
static http()
Fetches the global http state from ILIAS.