ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 mixed $additional_viewcontrol_data,
114 mixed $filter_data,
115 mixed $additional_parameters
116 ): \Generator {
117 $this->initSortingAndOrdering($range, $order);
118
119 foreach ($this->data_provider->getIdentifications() as $resource_identification) {
120 $information = $this->getResourceInfo($resource_identification);
121 $mime_type = $information->getMimeType();
122
123 $data_row = $row_builder->buildDataRow(
124 $this->hash($resource_identification->serialize()),
125 [
126 self::F_TITLE => $information->getTitle(),
127 self::F_SIZE => $this->formatSize($information->getSize()),
128 self::F_CREATION_DATE => $information->getCreationDate(),
129 self::F_TYPE => $information->getMimeType(),
130 ]
131 );
132
133 if (!in_array($mime_type, ['application/zip', 'application/x-zip-compressed'])) {
134 $data_row = $data_row->withDisabledAction(ActionBuilder::ACTION_UNZIP);
135 }
136
137 yield $data_row;
138 }
139 }
140
141 private function initSortingAndOrdering(Range $range, Order $order): void
142 {
143 $sort_field = array_keys($order->get())[0];
144 $sort_direction = $order->get()[$sort_field];
145
146 $start = $range->getStart();
147 $length = $range->getLength();
148 $this->data_provider->getViewRequest()->setPage((int) round($start / $length, 0, \RoundingMode::HalfTowardsZero));
149 $this->data_provider->getViewRequest()->setItemsPerPage($length);
150
151 switch ($sort_field . '_' . $sort_direction) {
152 case self::F_TITLE . '_' . Order::ASC:
153 $this->data_provider->getViewRequest()->setSortation(Request::BY_TITLE_ASC);
154 break;
155 case self::F_TITLE . '_' . Order::DESC:
156 $this->data_provider->getViewRequest()->setSortation(Request::BY_TITLE_DESC);
157 break;
158 case self::F_SIZE . '_' . Order::ASC:
159 $this->data_provider->getViewRequest()->setSortation(Request::BY_SIZE_ASC);
160 break;
161 case self::F_SIZE . '_' . Order::DESC:
162 $this->data_provider->getViewRequest()->setSortation(Request::BY_SIZE_DESC);
163 break;
164 case self::F_CREATION_DATE . '_' . Order::ASC:
165 $this->data_provider->getViewRequest()->setSortation(Request::BY_CREATION_DATE_ASC);
166 break;
167 case self::F_CREATION_DATE . '_' . Order::DESC:
168 $this->data_provider->getViewRequest()->setSortation(Request::BY_CREATION_DATE_DESC);
169 break;
170 }
171 }
172
173 public function getTotalRowCount(
174 mixed $additional_viewcontrol_data,
175 mixed $filter_data,
176 mixed $additional_parameters
177 ): ?int {
178 return $this->data_provider->getTotal();
179 }
180}
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
getTotalRowCount(mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
This is called by the table to retrieve rows; map data-records to rows using the $row_builder e....
__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
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildDataRow(string $id, array $record)
This describes a Data Table.
Definition: Data.php:33
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