ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
Data.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use Psr\Http\Message\ServerRequestInterface;
31use ILIAS\Data\Factory as DataFactory;
33use ILIAS\UI\Component\Input\Container\ViewControl as ViewControlContainer;
36
37class Data extends AbstractTable implements T\Data
38{
43
44 public const STORAGE_ID_PREFIX = self::class . '_';
45 public const VIEWCONTROL_KEY_PAGINATION = 'range';
46 public const VIEWCONTROL_KEY_ORDERING = 'order';
47 public const VIEWCONTROL_KEY_FIELDSELECTION = 'selection';
48 public const VIEWCONTROL_KEY_ADDITIONAL = 'additional';
49
50 protected mixed $filter = null;
51 protected mixed $additional_parameters = null;
52 protected mixed $additional_viewcontrol_data = null;
53 protected ?ViewControlContainer\ViewControlInput $additional_view_control = null;
54
58 public function __construct(
59 SignalGeneratorInterface $signal_generator,
60 ViewControl\Factory $view_control_factory,
61 ViewControlContainer\Factory $view_control_container_factory,
62 protected DataFactory $data_factory,
63 protected DataRowBuilder $data_row_builder,
64 string $title,
65 array $columns,
66 protected T\DataRetrieval $data_retrieval,
67 \ArrayAccess $storage
68 ) {
70 $signal_generator,
71 $view_control_factory,
72 $view_control_container_factory,
73 $storage,
74 $title,
75 $columns
76 );
77 $this->initViewControlFieldSelection($columns);
80 }
81
82 public function getDataRetrieval(): T\DataRetrieval
83 {
84 return $this->data_retrieval;
85 }
86
87 public function withFilter(mixed $filter): self
88 {
89 $clone = clone $this;
90 $clone->filter = $filter;
91 return $clone;
92 }
93
94 public function getFilter(): mixed
95 {
96 return $this->filter;
97 }
98
99 public function withAdditionalParameters(mixed $additional_parameters): self
100 {
101 $clone = clone $this;
102 $clone->additional_parameters = $additional_parameters;
103 return $clone;
104 }
105
106 public function getAdditionalParameters(): mixed
107 {
108 return $this->additional_parameters;
109 }
110
111
112 protected function withAdditionalViewControlData(mixed $additional_viewcontrol_data): self
113 {
114 $clone = clone $this;
115 $clone->additional_viewcontrol_data = $additional_viewcontrol_data;
116 return $clone;
117 }
118
119 public function getAdditionalViewControlData(): mixed
120 {
121 return $this->additional_viewcontrol_data;
122 }
123
124 public function getRowBuilder(): DataRowBuilder
125 {
126 return $this->data_row_builder
127 ->withMultiActionsPresent($this->hasMultiActions())
128 ->withSingleActions($this->getSingleActions())
129 ->withVisibleColumns($this->getVisibleColumns());
130 }
131
135 public function applyViewControls(
136 mixed $filter_data,
137 mixed $additional_parameters = []
138 ): array {
139 $request = $this->getRequest();
140 if ($request === null) {
141 return [
142 $this,
143 $this->getViewControls()
144 ];
145 }
146
147 $additional_viewcontrol_data = array_filter(
148 $this->applyValuesToViewcontrols($this->getViewControls(null), $request)->getData(),
149 fn($key) => !in_array($key, [self::VIEWCONTROL_KEY_PAGINATION, self::VIEWCONTROL_KEY_ORDERING, self::VIEWCONTROL_KEY_FIELDSELECTION]),
150 ARRAY_FILTER_USE_KEY
151 );
152
153 $total_count = $this->getDataRetrieval()->getTotalRowCount($additional_viewcontrol_data, $filter_data, $additional_parameters);
154 $view_controls = $this->getViewControls($total_count);
155
156 $data = $this->applyValuesToViewcontrols($view_controls, $request)->getData();
157 $range = $data[self::VIEWCONTROL_KEY_PAGINATION];
158 $range = ($range instanceof Range) ? $range : null;
159 $order = $data[self::VIEWCONTROL_KEY_ORDERING];
160 $order = ($order instanceof Order) ? $order : null;
161
162 if ($range instanceof Range) {
163 $range = $range->withStart($range->getStart() < $total_count ? $range->getStart() : 0);
164 $range = $range->croppedTo($total_count ?? PHP_INT_MAX);
165 }
166
167 $table = $this
168 ->withRange($range)
169 ->withOrder($order)
170 ->withSelectedOptionalColumns($data[self::VIEWCONTROL_KEY_FIELDSELECTION] ?? null)
171 ->withAdditionalViewControlData($additional_viewcontrol_data);
172
173 # This retrieves the view controls that should be displayed
174 $view_controls = $table->applyValuesToViewcontrols($table->getViewControls($total_count), $request);
175
176 return [
177 $table,
178 $view_controls
179 ];
180 }
181
182 protected function getViewControls(?int $total_count = null): ViewControlContainer\ViewControl
183 {
184 $view_controls = [
185 self::VIEWCONTROL_KEY_PAGINATION => $this->getViewControlPagination($total_count),
186 self::VIEWCONTROL_KEY_ORDERING => $this->getViewControlOrdering($total_count),
187 self::VIEWCONTROL_KEY_FIELDSELECTION => $this->getViewControlFieldSelection(),
188 $this->additional_view_control
189 ];
190 $view_controls = array_filter($view_controls);
191 $vc = $this->view_control_container_factory->standard($view_controls);
192 if ($this->getId() !== null) {
193 $vc = $vc->withDedicatedName('vc' . $this->getId());
194 }
195 return $vc;
196 }
197
199 ViewControlContainer\ViewControlInput $view_control
200 ): self {
201 $clone = clone $this;
202 $clone->additional_view_control = $view_control
203 ->withDedicatedName(self::VIEWCONTROL_KEY_ADDITIONAL);
204 return $clone;
205 }
206
207}
Builds data types.
Definition: Factory.php:36
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
withStart(int $start)
Definition: Range.php:79
croppedTo(int $max)
This will create a range that is guaranteed to not exceed $max.
Definition: Range.php:98
applyViewControls(mixed $filter_data, mixed $additional_parameters=[])
Definition: Data.php:135
withAdditionalParameters(mixed $additional_parameters)
Definition: Data.php:99
ViewControlContainer ViewControlInput $additional_view_control
Definition: Data.php:53
getViewControls(?int $total_count=null)
Definition: Data.php:182
withAdditionalViewControlData(mixed $additional_viewcontrol_data)
Definition: Data.php:112
withAdditionalViewControl(ViewControlContainer\ViewControlInput $view_control)
Definition: Data.php:198
__construct(SignalGeneratorInterface $signal_generator, ViewControl\Factory $view_control_factory, ViewControlContainer\Factory $view_control_container_factory, protected DataFactory $data_factory, protected DataRowBuilder $data_row_builder, string $title, array $columns, protected T\DataRetrieval $data_retrieval, \ArrayAccess $storage)
Definition: Data.php:58
This describes the basis of all View Control Inputs.
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.