ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
AbstractTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use Psr\Http\Message\ServerRequestInterface;
32use ILIAS\UI\Component\Input\Container\ViewControl as ViewControlContainer;
34
35abstract class AbstractTable extends Table implements JSBindable
36{
38
42 protected $columns = [];
43
47 protected $actions_single = [];
48
52 protected $actions_multi = [];
53
57 protected $actions_std = [];
58
59 protected ?string $id = null;
63 protected ?ServerRequestInterface $request = null;
64
68 public function __construct(
70 protected ViewControl\Factory $view_control_factory,
71 protected ViewControlContainer\Factory $view_control_container_factory,
72 protected \ArrayAccess $storage,
73 string $title,
74 array $columns
75 ) {
76 $this->checkArgListElements('columns', $columns, [Column::class]);
77 if ($columns === []) {
78 throw new \InvalidArgumentException('cannot construct a table without columns.');
79 }
80
82 $this->multi_action_signal = $signal_generator->create();
83 $this->selection_signal = $signal_generator->create();
84 $this->async_action_signal = $signal_generator->create();
85 $this->columns = $this->enumerateColumns($columns);
86 }
87
92 private function enumerateColumns(array $columns): array
93 {
94 $ret = [];
95 $idx = 0;
96 foreach ($columns as $id => $col) {
97 $ret[$id] = $col->withIndex($idx++);
98 }
99 return $ret;
100 }
101
105 public function getColumns(): array
106 {
107 return $this->columns;
108 }
109
113 public function withActions(array $actions): static
114 {
115 $this->checkArgListElements('actions', $actions, [T\Action\Action::class]);
116 $clone = clone $this;
117
118 foreach ($actions as $id => $action) {
119 switch (true) {
120 case ($action instanceof T\Action\Single):
121 $clone->actions_single[$id] = $action;
122 break;
123 case ($action instanceof T\Action\Multi):
124 $clone->actions_multi[$id] = $action;
125 break;
126 case ($action instanceof T\Action\Standard):
127 $clone->actions_std[$id] = $action;
128 break;
129 }
130 }
131 return $clone;
132 }
133
134 public function withRequest(ServerRequestInterface $request): static
135 {
136 $clone = clone $this;
137 $clone->request = $request;
138 return $clone;
139 }
140 public function getRequest(): ?ServerRequestInterface
141 {
142 return $this->request;
143 }
144
145 public function getMultiActionSignal(): Signal
146 {
148 }
149
150 public function getSelectionSignal(): Signal
151 {
153 }
154
155 public function getAsyncActionSignal(): Signal
156 {
158 }
159
160 public function hasSingleActions(): bool
161 {
162 return $this->getSingleActions() !== [];
163 }
164
165 public function hasMultiActions(): bool
166 {
167 return $this->getMultiActions() !== [];
168 }
169
173 public function getMultiActions(): array
174 {
175 return array_merge($this->actions_multi, $this->actions_std);
176 }
177
181 public function getSingleActions(): array
182 {
183 return array_merge($this->actions_single, $this->actions_std);
184 }
185
189 public function getAllActions(): array
190 {
191 return array_merge($this->actions_single, $this->actions_multi, $this->actions_std);
192 }
193
194 public function getColumnCount(): int
195 {
196 return count($this->columns);
197 }
198
199 protected function getStorageData(): ?array
200 {
201 if (null !== ($storage_id = $this->getStorageId())) {
202 return $this->storage[$storage_id] ?? null;
203 }
204 return null;
205 }
206
207 protected function setStorageData(array $data): void
208 {
209 if (null !== ($storage_id = $this->getStorageId())) {
210 $this->storage[$storage_id] = $data;
211 }
212 }
213
214 public function withId(string $id): static
215 {
216 $clone = clone $this;
217 $clone->id = $id;
218 return $clone;
219 }
220
221 protected function getStorageId(): ?string
222 {
223 if (null !== ($id = $this->getId())) {
224 return static::STORAGE_ID_PREFIX . $id;
225 }
226 return null;
227 }
228
229 protected function getId(): ?string
230 {
231 return $this->id;
232 }
233
234 protected function applyValuesToViewcontrols(
235 ViewControlContainer\ViewControl $view_controls,
236 ServerRequestInterface $request
237 ): ViewControlContainer\ViewControl {
238 $stored_values = new ArrayInputData($this->getStorageData() ?? []);
239 $view_controls = $view_controls
240 ->withStoredInput($stored_values)
241 ->withRequest($request);
242 $this->setStorageData($view_controls->getComponentInternalValues());
243 return $view_controls;
244 }
245
246}
new(Request $for_container)
Definition: Services.php:64
Builds data types.
Definition: Factory.php:36
int()
Contains constraints and transformations on numbers.
Definition: Factory.php:74
bool()
Get a kind transformation to a bool.
Definition: Group.php:159
as(string $key, Closure $parse)
The value parsed by the given $parse parameter will be stored under the key $key.
Definition: Transform.php:61
__construct(SignalGeneratorInterface $signal_generator, protected ViewControl\Factory $view_control_factory, protected ViewControlContainer\Factory $view_control_container_factory, protected \ArrayAccess $storage, string $title, array $columns)
applyValuesToViewcontrols(ViewControlContainer\ViewControl $view_controls, ServerRequestInterface $request)
clone(int $target_parent_obj_id)
readonly SignalGenerator $signal_generator
storage()
Fetches the storage filesystem.
Interface to be extended by components that have the possibility to bind to Javascript.
A Column describes the form of presentation for a certain aspect of data, i.e.
Definition: Column.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.