ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMMTopItemGUI.php
Go to the documentation of this file.
1<?php
2
3use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Renderer\Hasher;
4
12{
13 use Hasher;
14
15 const CMD_VIEW_TOP_ITEMS = 'subtab_topitems';
16 const CMD_ADD = 'topitem_add';
17 const CMD_RESTORE = 'restore';
18 const CMD_CREATE = 'topitem_create';
19 const CMD_EDIT = 'topitem_edit';
20 const CMD_DELETE = 'delete';
21 const CMD_CONFIRM_DELETE = 'topitem_confirm_delete';
22 const CMD_TRANSLATE = 'topitem_translate';
23 const CMD_UPDATE = 'topitem_update';
24 const CMD_SAVE_TABLE = 'save_table';
25 const CMD_CANCEL = 'cancel';
26 const CMD_RENDER_INTERRUPTIVE = 'render_interruptive_modal';
27 const CMD_CONFIRM_RESTORE = 'confirmRestore';
28 const CMD_UPLOAD = 'upload';
29 const CMD_SELECT_PARENT = 'selectParent';
30 const CMD_MOVE = 'move';
31 const CMD_FLUSH = 'flush';
32
33 private function dispatchCommand($cmd)
34 {
35 global $DIC;
36 switch ($cmd) {
38 $this->access->checkAccessAndThrowException("visible,read");
39 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, $cmd);
40
41 return $this->index($DIC);
42 case self::CMD_ADD:
43 $this->access->checkAccessAndThrowException('write');
44 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
45
46 return $this->add($DIC);
48 $this->access->checkAccessAndThrowException('write');
49 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
50
51 return $this->create($DIC);
52 case self::CMD_EDIT:
53 $this->access->checkAccessAndThrowException('write');
54 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
55
56 return $this->edit($DIC);
58 $this->access->checkAccessAndThrowException('write');
59 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
60
61 return $this->update($DIC);
63 $this->access->checkAccessAndThrowException('write');
64 $this->saveTable();
65
66 break;
68 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
69 $this->access->checkAccessAndThrowException('write');
70
71 return $this->confirmDelete();
73 $this->access->checkAccessAndThrowException('write');
74 $this->delete();
75 break;
77 $this->cancel();
78 break;
80 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
81 $this->access->checkAccessAndThrowException('write');
82 return $this->confirmRestore();
84 $this->access->checkAccessAndThrowException('write');
85
86 $this->restore();
87 break;
89 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
90 $this->access->checkAccessAndThrowException('write');
91 return $this->selectParent();
92 case self::CMD_FLUSH:
93 $this->access->checkAccessAndThrowException('write');
94 $this->flush();
95 break;
97 $this->access->checkAccessAndThrowException('write');
98 return $this->selectParent();
99 case self::CMD_MOVE:
100 $this->access->checkAccessAndThrowException('write');
101 $this->move();
102 break;
103 }
104
105 return "";
106 }
107
108 private function saveTable() : void
109 {
110 global $DIC;
111 $r = $DIC->http()->request()->getParsedBody();
112 foreach ($r[self::IDENTIFIER] as $identification_string => $data) {
113 $item = $this->repository->getItemFacadeForIdentificationString($this->unhash($identification_string));
114 $item->setPosition((int) $data['position']);
115 $item->setActiveStatus((bool) $data['active']);
116 $this->repository->updateItem($item);
117 }
118 $this->cancel();
119 }
120
121 public function executeCommand() : void
122 {
123 $next_class = $this->ctrl->getNextClass();
124
125 if ($next_class === '') {
126 $cmd = $this->determineCommand(self::CMD_VIEW_TOP_ITEMS, self::CMD_DELETE);
127 $this->tpl->setContent($this->dispatchCommand($cmd));
128
129 return;
130 }
131
132 switch ($next_class) {
133 case strtolower(ilMMItemTranslationGUI::class):
134 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true);
135 $g = new ilMMItemTranslationGUI($this->getMMItemFromRequest(), $this->repository);
136 $this->ctrl->forwardCommand($g);
137 break;
138 default:
139 break;
140 }
141 }
142
146 private function index() : string
147 {
148
149 if ($this->access->hasUserPermissionTo('write')) {
150 // ADD NEW
152 $b->setCaption($this->lng->txt(self::CMD_ADD), false);
153 $b->setUrl($this->ctrl->getLinkTarget($this, self::CMD_ADD));
154 $this->toolbar->addButtonInstance($b);
155
156 // RESTORE
158 $b->setCaption($this->lng->txt(self::CMD_RESTORE), false);
159 $b->setUrl($this->ctrl->getLinkTarget($this, self::CMD_CONFIRM_RESTORE));
160 $this->toolbar->addButtonInstance($b);
161
162 // REMOVE LOST ITEMS
163 if ($this->repository->hasLostItems()) {
165 $b->setUrl($this->ctrl->getLinkTarget($this, self::CMD_FLUSH));
166 $b->setCaption($this->lng->txt(self::CMD_FLUSH), false);
167 $this->toolbar->addButtonInstance($b);
168 }
169 }
170
171 // TABLE
172 $table = new ilMMTopItemTableGUI($this, new ilMMItemRepository(), $this->access);
173 $table->setShowRowsSelector(false);
174
175 return $table->getHTML();
176 }
177
178 private function cancel()
179 {
180 $this->ctrl->redirectByClass(self::class, self::CMD_VIEW_TOP_ITEMS);
181 }
182
183 private function doubleCancel()
184 {
185 $this->ctrl->redirectByClass(self::class, self::CMD_CANCEL);
186 }
187
193 private function add(\ILIAS\DI\Container $DIC) : string
194 {
195 $f = new ilMMTopItemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $DIC->http(), $this->repository->getItemFacade(), $this->repository);
196
197 return $f->getHTML();
198 }
199
205 private function create(\ILIAS\DI\Container $DIC) : string
206 {
207 $f = new ilMMTopItemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $DIC->http(), $this->repository->getItemFacade(), $this->repository);
208 if ($f->save()) {
209 $this->cancel();
210 }
211
212 return $f->getHTML();
213 }
214
220 private function edit(\ILIAS\DI\Container $DIC) : string
221 {
222 $f = new ilMMTopItemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $DIC->http(), $this->getMMItemFromRequest(), $this->repository);
223
224 return $f->getHTML();
225 }
226
232 private function update(\ILIAS\DI\Container $DIC) : string
233 {
234 $item = $this->getMMItemFromRequest();
235 if ($item->isEditable()) {
236 $f = new ilMMTopItemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $DIC->http(), $item, $this->repository);
237 if ($f->save()) {
238 $this->cancel();
239 }
240
241 return $f->getHTML();
242 }
243
244 return "";
245 }
246
247 private function delete() : void
248 {
249 $item = $this->getMMItemFromRequest();
250 if ($item->isDeletable()) {
251 $this->repository->deleteItem($item);
252 }
253 ilUtil::sendSuccess($this->lng->txt("msg_topitem_deleted"), true);
254 $this->cancel();
255 }
256
261 private function confirmDelete() : string
262 {
263 $this->ctrl->saveParameterByClass(self::class, self::IDENTIFIER);
264 $i = $this->getMMItemFromRequest();
265 $c = new ilConfirmationGUI();
266 $c->addItem(self::IDENTIFIER, $this->hash($i->getId()), $i->getDefaultTitle());
267 $c->setFormAction($this->ctrl->getFormActionByClass(self::class));
268 $c->setConfirm($this->lng->txt(self::CMD_DELETE), self::CMD_DELETE);
269 $c->setCancel($this->lng->txt(self::CMD_CANCEL), self::CMD_CANCEL);
270 $c->setHeaderText($this->lng->txt(self::CMD_CONFIRM_DELETE));
271
272 return $c->getHTML();
273 }
274
275 private function confirmRestore() : string
276 {
277 $c = new ilConfirmationGUI();
278 $c->setFormAction($this->ctrl->getFormActionByClass(self::class));
279 $c->setConfirm($this->lng->txt(self::CMD_DELETE), self::CMD_RESTORE);
280 $c->setCancel($this->lng->txt(self::CMD_CANCEL), self::CMD_CANCEL);
281 $c->setHeaderText($this->lng->txt('msg_restore_confirm'));
282
283 return $c->getHTML();
284 }
285
286 private function flush() : void
287 {
288 $this->repository->flushLostItems();
289 ilUtil::sendSuccess($this->lng->txt("msg_subitem_flushed"), true);
290 $this->cancel();
291 }
292
293 private function restore() : void
294 {
299
300 ilUtil::sendSuccess($this->lng->txt('msg_restored'), true);
301
302 $this->cancel();
303 }
304
305 private function selectParent() : string
306 {
307 $form = $this->getMoveForm();
308
309 return $this->ui->renderer()->render($form);
310 }
311
312 private function move() : void
313 {
314 $form = $this->getMoveForm();
315 $form = $form->withRequest($this->http->request());
316
317 $item = $this->getMMItemFromRequest();
318
319 $data = $form->getData();
320 if ($item->isInterchangeable() && isset($data[0])) {
321 $f = $this->repository->getItemFacadeForIdentificationString($data[0]);
322 $item->setParent($data[0]);
323 $this->repository->updateItem($item);
324 ilUtil::sendSuccess($this->lng->txt('msg_moved'), true);
325 } else {
326 ilUtil::sendFailure($this->lng->txt('msg_not_moved'), true);
327 }
328
329 $this->cancel();
330 }
331
335 private function getMoveForm() : \ILIAS\UI\Component\Input\Container\Form\Standard
336 {
337 $this->ctrl->saveParameter($this, self::IDENTIFIER);
338 $f = $this->ui->factory();
339
340 $parent = $f->input()->field()->select($this->lng->txt('select_parent'), $this->repository->getPossibleParentsForFormAndTable())->withRequired(true);
341
342 return $f->input()->container()->form()->standard($this->ctrl->getFormAction($this, self::CMD_MOVE), [$parent]);
343 }
344}
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
static getInstance()
Factory.
Class ilMMAbstractItemGUI.
determineCommand(string $standard, string $delete)
Class ilMMItemRepository.
Class ilMMItemTranslationGUI.
Class ilMMTopItemFormGUI.
Class ilMMTopItemGUI @ilCtrl_IsCalledBy ilMMTopItemGUI: ilObjMainMenuGUI @ilCtrl_Calls ilMMTopItemGUI...
update(\ILIAS\DI\Container $DIC)
create(\ILIAS\DI\Container $DIC)
add(\ILIAS\DI\Container $DIC)
edit(\ILIAS\DI\Container $DIC)
Class ilMMTopItemTableGUI.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$c
Definition: cli.php:37
global $DIC
Definition: goto.php:24
$i
Definition: metadata.php:24
Class HTTPServicesTest.
static http()
Fetches the global http state from ILIAS.
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
repository()
Definition: repository.php:5
$data
Definition: storeScorm.php:23
ui()
Definition: ui.php:5