ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ResourceListingUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\UI\Factory as UIFactory;
33use ILIAS\Refinery\Factory as Refinery;
34
39{
40 public const P_RESOURCE_ID = 'irss:resource_id';
41 public const P_PAGE = 'irss_page';
42 public const P_SORTATION = 'irss_sort';
43
44 private \ilUIFilterService $filter_service;
45 private \ilCtrlInterface $ctrl;
46 private UIFactory $ui_factory;
49 private \ilLanguage $language;
50 private array $components = [];
51 private Services $irss;
52
53 public function __construct(
54 private ViewDefinition $view_definition,
55 private TableDataSource $data_source,
56 private ActionGenerator $action_generator = new NullActionGenerator()
57 ) {
58 global $DIC;
59 $this->ctrl = $DIC->ctrl();
61 $this->language = $DIC->language();
62 $this->ui_factory = $DIC->ui()->factory();
63 $this->filter_service = $DIC->uiService()->filter();
64 $this->refinery = $DIC->refinery();
65 $this->irss = $DIC->resourceStorage();
66 $this->query = $DIC->http()->wrapper()->query();
67 // Setup DataSource
68 $this->data_source->setOffsetAndLimit(
69 $this->determinePage() * $this->view_definition->getItemsPerPage(),
70 $this->view_definition->getItemsPerPage()
71 );
72 $this->data_source->setSortDirection($this->determineSortation());
73 $this->initFilters();
74 $data_source->process();
75 $this->initUpload();
76 $this->initTable();
77 }
78
79 private function initFilters(): void
80 {
81 // Filters
82 $filters = $this->data_source->getFilterItems($this->ui_factory, $this->language);
83 if ($filters !== []) {
84 $embedding_gui = $this->view_definition->getEmbeddingGui();
85 $this->components[] = $filter = $this->filter_service->standard(
86 $embedding_gui,
87 $this->ctrl->getLinkTargetByClass($embedding_gui, $this->view_definition->getEmbeddingCmd()),
88 $filters,
89 array_map(
90 fn($filter): bool => true,
91 $filters
92 ),
93 true,
94 true
95 );
96 $this->data_source->applyFilterValues($this->filter_service->getData($filter));
97 }
98 }
99
100 private function initUpload(): void
101 {
102 // Currently no direct upload possible here
103 }
104
105 private function initTable(): void
106 {
107 // Table
108 $this->components[] = $this->ui_factory->table()->presentation(
109 '',
110 [],
111 $this->getRowMapping()
112 )->withData(
113 $this->data_source->getResourceIdentifications()
114 )->withViewControls($this->getViewControls());
115
116 $this->components = array_merge($this->components, $this->action_generator->getCollectedModals());
117 }
118
119 public function getRowMapping(): \Closure
120 {
121 return function (
122 PresentationRow $row,
123 ResourceIdentification $resource_identification
124 ): PresentationRow {
125 $resource = $this->irss->manage()->getResource($resource_identification);
126 $resource_to_component = new ResourceToComponent(
127 $resource,
128 $this->action_generator
129 );
130 return $resource_to_component->getAsRowMapping()($row, $resource_identification);
131 };
132 }
133
134 public function getComponents(): array
135 {
136 return $this->components;
137 }
138
139 protected function getViewControls(): array
140 {
141 $view_controls = [];
142 // Sortation
143 $sortations = [];
144 foreach (array_keys($this->data_source->getSortationsMapping()) as $sort_id) {
145 $sortations[$sort_id] = $this->language->txt('sorting_' . $sort_id);
146 }
147
148 $view_controls[] = $this->ui_factory->viewControl()->sortation($sortations, (string) $this->determineSortation())
149 ->withTargetURL(
150 $this->ctrl->getLinkTargetByClass(
151 $this->view_definition->getEmbeddingGui(),
152 $this->view_definition->getEmbeddingCmd()
153 ),
154 self::P_SORTATION
155 );
156
157 // Pagination
158 $count = $this->data_source->getFilteredAmountOfItems();
159 if ($count > $this->view_definition->getItemsPerPage()) {
160 $view_controls[] = $this->ui_factory->viewControl()->pagination()
161 ->withTargetURL(
162 $this->ctrl->getLinkTargetByClass(
163 $this->view_definition->getEmbeddingGui(),
164 $this->view_definition->getEmbeddingCmd()
165 ),
166 self::P_PAGE
167 )
168 ->withCurrentPage($this->determinePage())
169 ->withPageSize($this->view_definition->getItemsPerPage())
170 ->withTotalEntries($count)
171 ->withMaxPaginationButtons(5);
172 }
173
174 return $view_controls;
175 }
176
177 private function determinePage(): int
178 {
179 if ($this->query->has('cmdFilter')) { // Reset Page if Filter is applied, reset, ...
180 return 0;
181 }
182
183 return $this->query->has(self::P_PAGE)
184 ? $this->query->retrieve(self::P_PAGE, $this->refinery->kindlyTo()->int())
185 : 0;
186 }
187
188 private function determineSortation(): int
189 {
190 return $this->query->has(self::P_SORTATION)
191 ? $this->query->retrieve(self::P_SORTATION, $this->refinery->kindlyTo()->int())
192 : array_keys($this->data_source->getSortationsMapping())[0] ?? SortDirection::BY_SIZE_DESC;
193 }
194
195
196 protected function storeRequestParameters(): void
197 {
198 $this->ctrl->saveParameterByClass($this->view_definition->getEmbeddingGui(), self::P_SORTATION);
199 $this->ctrl->saveParameterByClass($this->view_definition->getEmbeddingGui(), self::P_PAGE);
200 }
201}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
__construct(private ViewDefinition $view_definition, private TableDataSource $data_source, private ActionGenerator $action_generator=new NullActionGenerator())
This describes a Row used in Presentation Table.
Class ilChatroomConfigFileHandler \ILIAS\Chatroom\classes.
global $DIC
Definition: shib_login.php:26