ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
RequestToDataTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28use ILIAS\components\ResourceStorage\BinToHexSerializer;
32
37{
38 use RIDHelper;
39 use Formatter;
40 use BinToHexSerializer;
41
42 public const F_TITLE = 'title';
43 public const F_SIZE = 'size';
44 public const F_TYPE = 'type';
45 public const F_CREATION_DATE = 'create_date';
46 public const FIELD_TITLE = 'title';
47 public const F_FILENAME = 'filename';
48 private \ILIAS\Data\Factory $data_factory;
49 private \ILIAS\ResourceStorage\Services $irss;
50
51 public function __construct(
52 private Request $request,
53 private Factory $ui_factory,
54 private \ilLanguage $language,
55 private Services $http,
56 private TableDataProvider $data_provider,
57 private ActionBuilder $action_builder,
58 private ViewControlBuilder $view_control_builder,
59 private UploadBuilder $upload_builder
60 ) {
61 global $DIC;
62 $this->irss = $DIC->resourceStorage();
63 $this->data_factory = new \ILIAS\Data\Factory();
64 }
65
66 public function getComponents(): \Generator
67 {
68 yield from $this->upload_builder->getDropZone();
69
70 yield $this->ui_factory->panel()->standard(
71 $this->request->getTitle(),
72 $this->buildTable()
73 );
74 }
75
79 protected function buildTable(): Data
80 {
81 return $this->ui_factory->table()->data(
82 $this,
83 '', // $this->request->getTitle() we already have the title in the panel
84 [
85 self::F_TITLE => $this->ui_factory->table()->column()->text(
86 $this->language->txt(self::F_TITLE)
87 )->withIsSortable(true),
88 self::F_SIZE => $this->ui_factory->table()->column()->text(
89 $this->language->txt(self::F_SIZE)
90 )->withIsSortable(true),
91 self::F_CREATION_DATE => $this->ui_factory->table()->column()->date(
92 $this->language->txt(self::F_CREATION_DATE),
93 $this->data_factory->dateFormat()->germanLong()
94 )->withIsSortable(true),
95 self::F_TYPE => $this->ui_factory->table()->column()->text(
96 $this->language->txt(self::F_TYPE)
97 )->withIsSortable(false),
98 ],
99 )->withRequest(
100 $this->http->request()
101 )->withActions(
102 $this->action_builder->getActions()
103 )->withRange(
104 new Range(0, $this->request->getItemsPerPage())
105 );
106 }
107
108 public function getRows(
109 DataRowBuilder $row_builder,
110 array $visible_column_ids,
112 Order $order,
113 ?array $filter_data,
114 ?array $additional_parameters
115 ): \Generator {
116 $this->initSortingAndOrdering($range, $order);
117
118 foreach ($this->data_provider->getIdentifications() as $resource_identification) {
119 $information = $this->getResourceInfo($resource_identification);
120 $mime_type = $information->getMimeType();
121
122 $data_row = $row_builder->buildDataRow(
123 $this->hash($resource_identification->serialize()),
124 [
125 self::F_TITLE => $information->getTitle(),
126 self::F_SIZE => $this->formatSize($information->getSize()),
127 self::F_CREATION_DATE => $information->getCreationDate(),
128 self::F_TYPE => $information->getMimeType(),
129 ]
130 );
131
132 if (!in_array($mime_type, ['application/zip', 'application/x-zip-compressed'])) {
133 $data_row = $data_row->withDisabledAction(ActionBuilder::ACTION_UNZIP);
134 }
135
136 yield $data_row;
137 }
138 }
139
140 private function initSortingAndOrdering(Range $range, Order $order): void
141 {
142 $sort_field = array_keys($order->get())[0];
143 $sort_direction = $order->get()[$sort_field];
144
145 $start = $range->getStart();
146 $length = $range->getLength();
147 $this->data_provider->getViewRequest()->setPage((int) round($start / $length, 0, \RoundingMode::HalfTowardsZero));
148 $this->data_provider->getViewRequest()->setItemsPerPage($length);
149
150 switch ($sort_field . '_' . $sort_direction) {
151 case self::F_TITLE . '_' . Order::ASC:
152 $this->data_provider->getViewRequest()->setSortation(Request::BY_TITLE_ASC);
153 break;
154 case self::F_TITLE . '_' . Order::DESC:
155 $this->data_provider->getViewRequest()->setSortation(Request::BY_TITLE_DESC);
156 break;
157 case self::F_SIZE . '_' . Order::ASC:
158 $this->data_provider->getViewRequest()->setSortation(Request::BY_SIZE_ASC);
159 break;
160 case self::F_SIZE . '_' . Order::DESC:
161 $this->data_provider->getViewRequest()->setSortation(Request::BY_SIZE_DESC);
162 break;
163 case self::F_CREATION_DATE . '_' . Order::ASC:
164 $this->data_provider->getViewRequest()->setSortation(Request::BY_CREATION_DATE_ASC);
165 break;
166 case self::F_CREATION_DATE . '_' . Order::DESC:
167 $this->data_provider->getViewRequest()->setSortation(Request::BY_CREATION_DATE_DESC);
168 break;
169 }
170 }
171
172 public function getTotalRowCount(?array $filter_data, ?array $additional_parameters): ?int
173 {
174 return $this->data_provider->getTotal();
175 }
176}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
const DESC
Definition: Order.php:31
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
Class Services.
Definition: Services.php:38
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
This is called by the table to retrieve rows; map data-records to rows using the $row_builder e....
getTotalRowCount(?array $filter_data, ?array $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
__construct(private Request $request, private Factory $ui_factory, private \ilLanguage $language, private Services $http, private TableDataProvider $data_provider, private ActionBuilder $action_builder, private ViewControlBuilder $view_control_builder, private UploadBuilder $upload_builder)
language handling
$http
Definition: deliver.php:30
buildDataRow(string $id, array $record)
This describes a Data Table.
Definition: Data.php:31
withRequest(ServerRequestInterface $request)
Rendering the Table must be done using the current Request: it (the request) will be forwarded to the...
This is how the factory for UI elements looks.
Definition: Factory.php:38
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26