ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilMMTopItemGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
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_UPLOAD = 'upload';
48  public const CMD_SELECT_PARENT = 'selectParent';
49  public const CMD_MOVE = 'move';
50 
51  private function dispatchCommand(string $cmd): string
52  {
53  global $DIC;
54  switch ($cmd) {
55  case self::CMD_VIEW_TOP_ITEMS:
56  $this->access->checkAccessAndThrowException("visible,read");
57  $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, $cmd);
58 
59  return $this->index();
60  case self::CMD_ADD:
61  $this->access->checkAccessAndThrowException('write');
62  $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
63 
64  return $this->add($DIC);
65  case self::CMD_CREATE:
66  $this->access->checkAccessAndThrowException('write');
67  $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
68 
69  return $this->create($DIC);
70  case self::CMD_EDIT:
71  $this->access->checkAccessAndThrowException('write');
72  $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
73 
74  return $this->edit($DIC);
75  case self::CMD_UPDATE:
76  $this->access->checkAccessAndThrowException('write');
77  $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
78 
79  return $this->update($DIC);
80  case self::CMD_SAVE_TABLE:
81  $this->access->checkAccessAndThrowException('write');
82  $this->saveTable();
83 
84  break;
85  case self::CMD_DELETE:
86  $this->access->checkAccessAndThrowException('write');
87  $this->delete();
88  break;
89  case self::CMD_CANCEL:
90  $this->cancel();
91  break;
92  case self::CMD_RESTORE:
93  $this->access->checkAccessAndThrowException('write');
94 
95  $this->restore();
96  break;
97  case self::CMD_SELECT_PARENT:
98  $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true, self::class);
99  $this->access->checkAccessAndThrowException('write');
100  return $this->selectParent();
101  case self::CMD_FLUSH:
102  $this->access->checkAccessAndThrowException('write');
103  $this->flush();
104  break;
105  case self::CMD_UPLOAD:
106  $this->access->checkAccessAndThrowException('write');
107  return $this->selectParent();
108  case self::CMD_MOVE:
109  $this->access->checkAccessAndThrowException('write');
110  $this->move();
111  break;
112  }
113 
114  return "";
115  }
116 
117  private function saveTable(): void
118  {
119  global $DIC;
120  $r = $DIC->http()->request()->getParsedBody();
121  foreach ($r[self::IDENTIFIER] as $identification_string => $data) {
122  $item = $this->repository->getItemFacadeForIdentificationString($this->unhash($identification_string));
123  $item->setPosition((int) ($data['position'] ?? 999));
124  $item->setActiveStatus((bool) ($data['active'] ?? false));
125  $this->repository->updateItem($item);
126  }
127  $this->cancel();
128  }
129 
130  public function executeCommand(): void
131  {
132  $next_class = $this->ctrl->getNextClass();
133 
134  if ($next_class === '') {
135  $cmd = $this->determineCommand(self::CMD_VIEW_TOP_ITEMS, self::CMD_DELETE);
136  $this->tpl->setContent($this->dispatchCommand($cmd));
137 
138  return;
139  }
140 
141  switch ($next_class) {
142  case strtolower(ilMMItemTranslationGUI::class):
143  $this->tab_handling->initTabs(ilObjMainMenuGUI::TAB_MAIN, self::CMD_VIEW_TOP_ITEMS, true);
144  $g = new ilMMItemTranslationGUI($this->getMMItemFromRequest(), $this->repository);
145  $this->ctrl->forwardCommand($g);
146  break;
147  default:
148  break;
149  }
150  }
151 
155  private function index(): string
156  {
157  if ($this->access->hasUserPermissionTo('write')) {
158  // ADD NEW
159  $btn_add = $this->ui->factory()->button()->standard(
160  $this->lng->txt(self::CMD_ADD),
161  $this->ctrl->getLinkTarget($this, self::CMD_ADD)
162  );
163  $this->toolbar->addComponent($btn_add);
164 
165  // RESTORE
166  $restoration_modal = $this->ui->factory()->modal()->interruptive(
167  $this->lng->txt(self::CMD_RESTORE),
168  $this->lng->txt('msg_restore_confirm'),
169  $this->ctrl->getLinkTarget($this, self::CMD_RESTORE)
170  )->withActionButtonLabel($this->lng->txt('restore'));
171  $btn_restore = $this->ui->factory()->button()->standard(
172  $this->lng->txt(self::CMD_RESTORE),
173  ''
174  )->withOnClick(
175  $restoration_modal->getShowSignal()
176  );
177  $this->toolbar->addComponent($btn_restore);
178  $this->toolbar->addComponent($restoration_modal);
179 
180  // REMOVE LOST ITEMS
181  if ($this->repository->hasLostItems()) {
182  $btn_flush = $this->ui->factory()->button()->standard(
183  $this->lng->txt(self::CMD_FLUSH),
184  $this->ctrl->getLinkTarget($this, self::CMD_FLUSH)
185  );
186  $this->toolbar->addComponent($btn_flush);
187  }
188  }
189 
190  // TABLE
191  $table = new ilMMTopItemTableGUI($this, new ilMMItemRepository(), $this->access);
192  $table->setShowRowsSelector(false);
193 
194  return $table->getHTML();
195  }
196 
197  protected function cancel(): void
198  {
199  $this->ctrl->redirectByClass(self::class, self::CMD_VIEW_TOP_ITEMS);
200  }
201 
202  private function doubleCancel(): void
203  {
204  $this->ctrl->redirectByClass(self::class, self::CMD_CANCEL);
205  }
206 
212  private function add(Container $DIC): string
213  {
214  $f = new ilMMTopItemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $DIC->http(), $this->repository->getItemFacade(), $this->repository);
215 
216  return $f->getHTML();
217  }
218 
224  private function create(Container $DIC): string
225  {
226  $f = new ilMMTopItemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $DIC->http(), $this->repository->getItemFacade(), $this->repository);
227  if ($f->save()) {
228  $this->cancel();
229  }
230 
231  return $f->getHTML();
232  }
233 
239  private function edit(Container $DIC): string
240  {
241  $f = new ilMMTopItemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $DIC->http(), $this->getMMItemFromRequest(), $this->repository);
242 
243  return $f->getHTML();
244  }
245 
251  private function update(Container $DIC): string
252  {
253  $item = $this->getMMItemFromRequest();
254  if ($item->isEditable()) {
255  $f = new ilMMTopItemFormGUI($DIC->ctrl(), $DIC->ui()->factory(), $DIC->ui()->renderer(), $this->lng, $DIC->http(), $item, $this->repository);
256  if ($f->save()) {
257  $this->cancel();
258  }
259 
260  return $f->getHTML();
261  }
262 
263  return "";
264  }
265 
266  private function delete(): void
267  {
268  $item = $this->getMMItemFromRequest();
269  if ($item->isDeletable()) {
270  $this->repository->deleteItem($item);
271  }
272  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_topitem_deleted"), true);
273  $this->cancel();
274  }
275 
276 
277  private function restore(): void
278  {
283 
284  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_restored'), true);
285 
286  $this->cancel();
287  }
288 
289  private function selectParent(): string
290  {
291  $form = $this->getMoveForm();
292 
293  return $this->ui->renderer()->render($form);
294  }
295 
296  private function move(): void
297  {
298  $form = $this->getMoveForm();
299  $form = $form->withRequest($this->http->request());
300 
301  $item = $this->getMMItemFromRequest();
302 
303  $data = $form->getData();
304  if ($item->isInterchangeable() && isset($data[0])) {
305  $f = $this->repository->getItemFacadeForIdentificationString($data[0]);
306  $item->setParent($data[0]);
307  $this->repository->updateItem($item);
308  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_moved'), true);
309  } else {
310  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_not_moved'), true);
311  }
312 
313  $this->cancel();
314  }
315 
319  private function getMoveForm(): Standard
320  {
321  $this->ctrl->saveParameter($this, self::IDENTIFIER);
322  $f = $this->ui->factory();
323 
324  $parent = $f->input()->field()->select($this->lng->txt('select_parent'), $this->repository->getPossibleParentsForFormAndTable())->withRequired(true);
325 
326  return $f->input()->container()->form()->standard($this->ctrl->getFormAction($this, self::CMD_MOVE), [$parent]);
327  }
328 }
Class ilMMAbstractItemGUI.
dispatchCommand(string $cmd)
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
Class ilMMItemRepository.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
edit(Container $DIC)
create(Container $DIC)
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:22
Class ilMMTopItemGUI ilMMTopItemGUI: ilObjMainMenuGUI ilMMTopItemGUI: ilMMItemTranslationGUI.
add(Container $DIC)
Class ilMMItemTranslationGUI.
ilMMItemRepository $repository
This describes a standard form.
Definition: Standard.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilMMTopItemFormGUI.
static flushDB()
never use in ILIAS Core, Plugins only
ctrl()
Get the interface to the control structure.
Definition: Container.php:63
ui()
Get the interface to get services from UI framework.
Definition: Container.php:127
Class ilMMTopItemTableGUI.
update(Container $DIC)
$r
determineCommand(string $standard, string $delete)