ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMMSubItemGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
32{
33 public const CMD_CONFIRM_MOVE = 'confirmMove';
34 public const CMD_MOVE = 'MOVE';
35
39
40 public function __construct(Pons $pons)
41 {
43 $this->sub_token = $this->pons->in()->buildToken('sub', 'id');
44 $this->top_token = $this->pons->in()->buildToken('top', 'id');
45 $this->parent_item = $this->repository->getItemFacadeForIdentificationString(
46 $this->pons->in()->getFirstFromRequest($this->top_token->token())
47 );
48 }
49
50 #[\Override]
51 public function executeCommand(): bool
52 {
53 $this->pons->in()->keep($this->top_token->token());
54 if ($this->pons->handle('sub_items')) {
55 return true;
56 }
57
58 match ($this->pons->flow()->getCommand(self::CMD_DEFAULT)) {
59 self::CMD_CONFIRM_MOVE => $this->confirmMove(),
60 self::CMD_MOVE => $this->move(),
61 default => parent::executeCommand()
62 };
63 return true;
64 }
65
67 {
68 return $this->repository->getItemFacadeForIdentificationString(
69 $this->pons->in()->getFirstFromRequest($this->sub_token->token())
70 );
71 }
72
73 public function getMutlipleItems(): array
74 {
75 $ids = $this->pons->in()->getAllFromRequest($this->sub_token->token());
76 if (($ids[0] ?? null) === Input::ALL_OBJECTS) {
77 return array_map(
78 fn(array $data): \ilMMItemFacadeInterface => $this->repository->getItemFacadeForIdentificationString(
79 $data['identification']
80 ),
81 $this->repository->getSubItemsForTable($this->parent_item)
82 );
83 }
84 return $this->repository->getItemFacadesForIdentificationStrings($ids);
85 }
86
87 public function getTokensToKeep(): array
88 {
89 return [
90 $this->top_token->token(),
91 $this->sub_token->token(),
92 ];
93 }
94
95 protected function buildForm(): ilMMSubitemFormGUI
96 {
97 $item = $this->repository->getItemFacadeForIdentificationString(
98 $this->pons->in()->getFirstFromRequest($this->sub_token->token())
99 );
100 return new ilMMSubitemFormGUI(
101 $this->flow->ctrl(),
102 $this->ui->factory(),
103 $this->ui->renderer(),
104 $this->lng,
105 $this->pons->in()->request(),
106 $item,
107 $this->repository,
108 $this->parent_item
109 );
110 }
111
112 protected function form(bool $save = false): void
113 {
114 if (!$save) {
115 $this->pons->in()->keep($this->sub_token->token());
116 }
117
118 $form = $this->buildForm();
119
120 if ($save && $form->save()) {
121 $this->pons->out()->success($this->lng->t('item_updated'), true);
122 $this->pons->flow()->redirect(self::CMD_DEFAULT);
123 }
124
125 $this->pons->out()->outAsyncAsModal(
126 $this->lng->txt('subitem'),
127 $this->flow->getLinkTarget($this, self::CMD_UPDATE),
128 $form->get()
129 );
130 }
131
132 protected function index(): void
133 {
134 $write_access = $this->access->hasUserPermissionTo('write');
135 if ($write_access) {
136 // ADD NEW
137 $form = $this->buildForm();
138 $add_modal = $this->ui->factory()->modal()->roundtrip(
139 $this->lng->t('subitem_add'),
140 null,
141 $form->get()->getInputs(),
142 $this->flow->getLinkTarget($this, self::CMD_CREATE)
143 );
144
145 $btn_add = $this->ui->factory()->button()->primary(
146 $this->lng->t('subitem_add'),
147 $add_modal->getShowSignal()
148 );
149 $this->toolbar->addComponent($add_modal);
150 $this->toolbar->addComponent($btn_add);
151 }
152
153 $table = new ilMMSubItemTableComponent(
154 $this->pons,
155 $this->sub_token,
156 $this->repository,
157 $this->parent_item,
158 $write_access
159 );
160
161 $this->pons->out()->out(...$table->get());
162 }
163
164 private function confirmMove(): void
165 {
166 $this->keepTokens();
167
168 $items = [];
169 foreach ($this->getMutlipleItems() as $item) {
170 $items[] = $this->ui->factory()->modal()->interruptiveItem()->standard(
171 $this->hash($item->getId()),
172 $item->getDefaultTitle(),
173 );
174 }
175
176 $this->pons->out()->outAsyncAsConfirmation(
177 $this->lng->t('move'),
178 $this->lng->t('confirm_move'),
179 $this->lng->t('move'),
180 $this->flow->getLinkTarget($this, self::CMD_MOVE),
181 ...$items
182 );
183 }
184
185 private function move(): void
186 {
187 $mutliple_items = $this->getMutlipleItems();
188 if (empty($mutliple_items)) {
189 $this->pons->out()->error($this->lng->t('msg_not_moved'), true);
190 $this->pons->flow()->redirect(self::CMD_DEFAULT);
191 return;
192 }
193 foreach ($mutliple_items as $item) {
194 $item->setParent('');
195 $this->repository->updateItem($item);
196 }
197
198 $this->pons->out()->success($this->lng->t('msg_moved'), true);
199 $this->pons->flow()->redirect(self::CMD_DEFAULT);
200 }
201}
@ilCtrl_IsCalledBy ilMMSubItemGUI: ilMMTopItemGUI @ilCtrl_Calls ilMMSubItemGUI: ILIAS\GlobalScreen\GU...
TokenContainer $sub_token
TokenContainer $top_token
form(bool $save=false)
ilMMItemFacadeInterface $parent_item
Class ilMMSubitemFormGUI.
Interface ilMMItemFacadeInterface.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc