ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMMSubItemGUI.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_SUB_ITEMS = 'subtab_subitems';
16 const CMD_ADD = 'subitem_add';
17 const CMD_CREATE = 'subitem_create';
18 const CMD_CONFIRM_MOVE = 'confirm_move';
19 const CMD_MOVE = 'move';
20 const CMD_DELETE = 'delete';
21 const CMD_CONFIRM_DELETE = 'subitem_confirm_delete';
22 const CMD_EDIT = 'subitem_edit';
23 const CMD_TRANSLATE = 'subitem_translate';
24 const CMD_UPDATE = 'subitem_update';
25 const CMD_SAVE_TABLE = 'save_table';
26 const CMD_APPLY_FILTER = 'applyFilter';
27 const CMD_RESET_FILTER = 'resetFilter';
28 const CMD_RENDER_INTERRUPTIVE = 'render_interruptive_modal';
29 const CMD_CANCEL = 'cancel';
30
31 private function dispatchCommand($cmd)
32 {
33 global $DIC;
34 switch ($cmd) {
35 case self::CMD_ADD:
36 $this->access->checkAccessAndThrowException('write');
37 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, ilMMSubItemGUI::CMD_VIEW_SUB_ITEMS, true, self::class);
38
39 return $this->add($DIC);
41 $this->access->checkAccessAndThrowException('write');
42 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, ilMMSubItemGUI::CMD_VIEW_SUB_ITEMS, true, self::class);
43
44 return $this->create($DIC);
45 case self::CMD_EDIT:
46 $this->access->checkAccessAndThrowException('write');
47 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, ilMMSubItemGUI::CMD_VIEW_SUB_ITEMS, true, self::class);
48
49 return $this->edit($DIC);
51 $this->access->checkAccessAndThrowException('write');
52 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, ilMMSubItemGUI::CMD_VIEW_SUB_ITEMS, true, self::class);
53
54 return $this->update($DIC);
56 $this->access->checkAccessAndThrowException('visible,read');
57 $this->applyFilter();
58 break;
60 $this->access->checkAccessAndThrowException('visible,read');
61 $this->resetFilter();
62 break;
64 $this->access->checkAccessAndThrowException('visible,read');
65 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, $cmd);
66
67 return $this->index();
69 $this->access->checkAccessAndThrowException('write');
70 $this->saveTable();
71 break;
73 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, ilMMSubItemGUI::CMD_VIEW_SUB_ITEMS, true, self::class);
74 $this->access->checkAccessAndThrowException('write');
75
76 return $this->confirmDelete();
78 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, ilMMSubItemGUI::CMD_VIEW_SUB_ITEMS, true, self::class);
79 $this->access->checkAccessAndThrowException('write');
80
81 return $this->confirmMove();
82 case self::CMD_MOVE:
83 $this->access->checkAccessAndThrowException('write');
84 $this->move();
85 break;
87 $this->access->checkAccessAndThrowException('write');
88 $this->delete();
89 break;
91 $this->cancel();
92 break;
93 }
94
95 return "";
96 }
97
98 private function saveTable() : void
99 {
100 global $DIC;
101 $r = $DIC->http()->request()->getParsedBody();
102 foreach ($r[self::IDENTIFIER] as $identification_string => $data) {
103 $item = $this->repository->getItemFacadeForIdentificationString($this->unhash($identification_string));
104 $position = (int) $data['position'];
105 $item->setPosition($position);
106 $item->setActiveStatus(isset($data['active']) && (bool) $data['active']);
107 $item->setParent($this->unhash((string) $data['parent']));
108 $this->repository->updateItem($item);
109 }
110 $this->cancel();
111 }
112
113 public function executeCommand() : void
114 {
115 $next_class = $this->ctrl->getNextClass();
116
117 if ('' === $next_class) {
118 $cmd = $this->determineCommand(self::CMD_VIEW_SUB_ITEMS, self::CMD_DELETE);
119 $this->tpl->setContent($this->dispatchCommand($cmd));
120
121 return;
122 }
123
124 switch ($next_class) {
125 case strtolower(ilMMItemTranslationGUI::class):
126 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_SUB_ITEMS, true, $this->ctrl->getCallHistory()[2]['class'] ? $this->ctrl->getCallHistory()[2]['class'] : "");
127 $g = new ilMMItemTranslationGUI($this->getMMItemFromRequest(), $this->repository);
128 $this->ctrl->forwardCommand($g);
129 break;
130 default:
131 break;
132 }
133 }
134
140 private function add($DIC) : string
141 {
142 $f = new ilMMSubitemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $this->repository->getItemFacade(), $this->repository);
143
144 return $f->getHTML();
145 }
146
152 private function create($DIC) : string
153 {
154 $f = new ilMMSubitemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $this->repository->getItemFacade(), $this->repository);
155 if ($f->save()) {
156 $this->cancel();
157 }
158
159 return $f->getHTML();
160 }
161
167 private function edit($DIC) : string
168 {
169 $f = new ilMMSubitemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $this->getMMItemFromRequest(), $this->repository);
170
171 return $f->getHTML();
172 }
173
179 private function update($DIC) : string
180 {
181 $f = new ilMMSubitemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $this->getMMItemFromRequest(), $this->repository);
182 if ($f->save()) {
183 $this->cancel();
184 }
185
186 return $f->getHTML();
187 }
188
189 private function applyFilter() : void
190 {
191 $table = new ilMMSubItemTableGUI($this, $this->repository, $this->access);
192 $table->writeFilterToSession();
193
194 $this->cancel();
195 }
196
197 private function resetFilter() : void
198 {
199 $table = new ilMMSubItemTableGUI($this, $this->repository, $this->access);
200 $table->resetFilter();
201 $table->resetOffset();
202
203 $this->cancel();
204 }
205
209 private function index() : string
210 {
211 // ADD NEW
212 if ($this->access->hasUserPermissionTo('write')) {
214 $b->setUrl($this->ctrl->getLinkTarget($this, ilMMSubItemGUI::CMD_ADD));
215 $b->setCaption($this->lng->txt(ilMMSubItemGUI::CMD_ADD), false);
216
217 $this->toolbar->addButtonInstance($b);
218 }
219
220 // TABLE
221 $table = new ilMMSubItemTableGUI($this, $this->repository, $this->access);
222 $table->setShowRowsSelector(false);
223
224 return $table->getHTML();
225 }
226
227 private function delete() : void
228 {
229 $item = $this->getMMItemFromRequest();
230 if ($item->isCustom()) {
231 $this->repository->deleteItem($item);
232 }
233
234 ilUtil::sendSuccess($this->lng->txt("msg_subitem_deleted"), true);
235 $this->cancel();
236 }
237
238 private function cancel() : void
239 {
240 $this->ctrl->redirectByClass(self::class, self::CMD_VIEW_SUB_ITEMS);
241 }
242
247 private function confirmDelete() : string
248 {
249 $this->ctrl->saveParameterByClass(self::class, self::IDENTIFIER);
250 $i = $this->getMMItemFromRequest();
251 $c = new ilConfirmationGUI();
252 $c->addItem(self::IDENTIFIER, $this->hash($i->getId()), $i->getDefaultTitle());
253 $c->setFormAction($this->ctrl->getFormActionByClass(self::class));
254 $c->setConfirm($this->lng->txt(self::CMD_DELETE), self::CMD_DELETE);
255 $c->setCancel($this->lng->txt(self::CMD_CANCEL), self::CMD_CANCEL);
256 $c->setHeaderText($this->lng->txt(self::CMD_CONFIRM_DELETE));
257
258 return $c->getHTML();
259 }
260
265 private function confirmMove() : string
266 {
267 $this->ctrl->saveParameterByClass(self::class, self::IDENTIFIER);
268 $i = $this->getMMItemFromRequest();
269 $c = new ilConfirmationGUI();
270 $c->addItem(self::IDENTIFIER, $this->hash($i->getId()), $i->getDefaultTitle());
271 $c->setFormAction($this->ctrl->getFormActionByClass(self::class));
272 $c->setConfirm($this->lng->txt(self::CMD_MOVE), self::CMD_MOVE);
273 $c->setCancel($this->lng->txt(self::CMD_CANCEL), self::CMD_CANCEL);
274 $c->setHeaderText($this->lng->txt(self::CMD_CONFIRM_MOVE));
275
276 return $c->getHTML();
277 }
278
279 private function move() : void
280 {
281 $item = $this->getMMItemFromRequest();
282 if ($item->isInterchangeable()) {
283 $item->setParent('');
284 $this->repository->updateItem($item);
285 }
286
287 ilUtil::sendSuccess($this->lng->txt("msg_moved"), true);
288 $this->cancel();
289 }
290}
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 ilMMItemTranslationGUI.
Class ilMMTopItemGUI @ilCtrl_IsCalledBy ilMMSubItemGUI: ilObjMainMenuGUI @ilCtrl_Calls ilMMSubItemGUI...
Class ilMMSubItemTableGUI.
Class ilMMSubitemFormGUI.
$c
Definition: cli.php:37
global $DIC
Definition: goto.php:24
$i
Definition: metadata.php:24
repository()
Definition: repository.php:5
$data
Definition: storeScorm.php:23