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