ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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_DELETE = 'subitem_delete';
19 const CMD_CONFIRM_DELETE = 'subitem_confirm_delete';
20 const CMD_EDIT = 'subitem_edit';
21 const CMD_TRANSLATE = 'subitem_translate';
22 const CMD_UPDATE = 'subitem_update';
23 const CMD_SAVE_TABLE = 'save_table';
24 const CMD_APPLY_FILTER = 'applyFilter';
25 const CMD_RESET_FILTER = 'resetFilter';
26 const CMD_RENDER_INTERRUPTIVE = 'render_interruptive_modal';
27 const CMD_CANCEL = 'cancel';
28
29 private function dispatchCommand($cmd)
30 {
31 global $DIC;
32 switch ($cmd) {
33 case self::CMD_ADD:
34 $this->access->checkAccessAndThrowException('write');
35 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, ilMMSubItemGUI::CMD_VIEW_SUB_ITEMS, true, self::class);
36
37 return $this->add($DIC);
39 $this->access->checkAccessAndThrowException('write');
40 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, ilMMSubItemGUI::CMD_VIEW_SUB_ITEMS, true, self::class);
41
42 return $this->create($DIC);
43 case self::CMD_EDIT:
44 $this->access->checkAccessAndThrowException('write');
45 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, ilMMSubItemGUI::CMD_VIEW_SUB_ITEMS, true, self::class);
46
47 return $this->edit($DIC);
49 $this->access->checkAccessAndThrowException('write');
50 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, ilMMSubItemGUI::CMD_VIEW_SUB_ITEMS, true, self::class);
51
52 return $this->update($DIC);
54 $this->access->checkAccessAndThrowException('visible,read');
55 $this->applyFilter();
56 break;
58 $this->access->checkAccessAndThrowException('visible,read');
59 $this->resetFilter();
60 break;
62 $this->access->checkAccessAndThrowException('visible,read');
63 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, $cmd);
64
65 return $this->index();
67 $this->access->checkAccessAndThrowException('write');
68 $this->saveTable();
69 break;
71 $this->access->checkAccessAndThrowException('write');
72
73 return $this->confirmDelete();
75 $this->access->checkAccessAndThrowException('write');
76 $this->delete();
77 break;
79 $this->cancel();
80 break;
82 $this->access->checkAccessAndThrowException('write');
84 break;
85 }
86
87 return "";
88 }
89
90 private function saveTable()
91 {
92 global $DIC;
93 $r = $DIC->http()->request()->getParsedBody();
94 foreach ($r[self::IDENTIFIER] as $identification_string => $data) {
95 $item = $this->repository->getItemFacadeForIdentificationString($this->unhash($identification_string));
96 $position = (int) $data['position'];
97 $item->setPosition($position);
98 $item->setActiveStatus((bool) $data['active']);
99 $item->setParent($this->unhash((string) $data['parent']));
100 $this->repository->updateItem($item);
101 }
102 $this->cancel();
103 }
104
105 public function executeCommand()
106 {
107 $next_class = $this->ctrl->getNextClass();
108
109 if ($next_class == '') {
110 $cmd = $this->determineCommand(self::CMD_VIEW_SUB_ITEMS, self::CMD_DELETE);
111 $this->tpl->setContent($this->dispatchCommand($cmd));
112
113 return;
114 }
115
116 switch ($next_class) {
117 case strtolower(ilMMItemTranslationGUI::class):
118 $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_SUB_ITEMS, true, $this->ctrl->getCallHistory()[2]['class'] ? $this->ctrl->getCallHistory()[2]['class'] : "");
119 $g = new ilMMItemTranslationGUI($this->getMMItemFromRequest(), $this->repository);
120 $this->ctrl->forwardCommand($g);
121 break;
122 default:
123 break;
124 }
125 }
126
132 private function add($DIC) : string
133 {
134 $f = new ilMMSubitemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $this->repository->getItemFacade(), $this->repository);
135
136 return $f->getHTML();
137 }
138
144 private function create($DIC)
145 {
146 $f = new ilMMSubitemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $this->repository->getItemFacade(), $this->repository);
147 if ($f->save()) {
148 $this->cancel();
149 }
150
151 return $f->getHTML();
152 }
153
159 private function edit($DIC) : string
160 {
161 $f = new ilMMSubitemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $this->getMMItemFromRequest(), $this->repository);
162
163 return $f->getHTML();
164 }
165
171 private function update($DIC)
172 {
173 $f = new ilMMSubitemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $this->getMMItemFromRequest(), $this->repository);
174 if ($f->save()) {
175 $this->cancel();
176 }
177
178 return $f->getHTML();
179 }
180
181 private function applyFilter()
182 {
183 $table = new ilMMSubItemTableGUI($this, $this->repository, $this->access);
184 $table->writeFilterToSession();
185
186 $this->cancel();
187 }
188
189 private function resetFilter()
190 {
191 $table = new ilMMSubItemTableGUI($this, $this->repository, $this->access);
192 $table->resetFilter();
193 $table->resetOffset();
194
195 $this->cancel();
196 }
197
201 private function index() : string
202 {
203 if ($this->access->hasUserPermissionTo('write')) {
204 // ADD NEW
206 $b->setUrl($this->ctrl->getLinkTarget($this, ilMMSubItemGUI::CMD_ADD));
207 $b->setCaption($this->lng->txt(ilMMSubItemGUI::CMD_ADD), false);
208 $this->toolbar->addButtonInstance($b);
209 }
210
211 // TABLE
212 $table = new ilMMSubItemTableGUI($this, $this->repository, $this->access);
213 $table->setShowRowsSelector(false);
214
215 return $table->getHTML();
216 }
217
218 private function delete()
219 {
220 $item = $this->getMMItemFromRequest();
221 if ($item->isDeletable()) {
222 $this->repository->deleteItem($item);
223 }
224
225 ilUtil::sendSuccess($this->lng->txt("msg_subitem_deleted"), true);
226 $this->cancel();
227 }
228
229 private function cancel()
230 {
231 $this->ctrl->redirectByClass(self::class, self::CMD_VIEW_SUB_ITEMS);
232 }
233
238 private function confirmDelete() : string
239 {
240 $this->ctrl->saveParameterByClass(self::class, self::IDENTIFIER);
241 $i = $this->getMMItemFromRequest();
242 $c = new ilConfirmationGUI();
243 $c->addItem(self::IDENTIFIER, $this->hash($i->getId()), $i->getDefaultTitle());
244 $c->setFormAction($this->ctrl->getFormActionByClass(self::class));
245 $c->setConfirm($this->lng->txt(self::CMD_DELETE), self::CMD_DELETE);
246 $c->setCancel($this->lng->txt(self::CMD_CANCEL), self::CMD_CANCEL);
247 $c->setHeaderText($this->lng->txt(self::CMD_CONFIRM_DELETE));
248
249 return $c->getHTML();
250 }
251}
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.
$i
Definition: disco.tpl.php:19
$r
Definition: example_031.php:79
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
Definition: functions.php:406
if(empty($password)) $table
Definition: pwgen.php:24
repository()
Definition: repository.php:5
global $DIC
Definition: saml.php:7
$data
Definition: bench.php:6