ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
ResultPresenterImpl.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use DateTimeImmutable;
32use Generator;
40
42{
43 protected const int MAX_SUBITEMS = 49;
44 protected const int MAX_SUBITEMS_PER_PAGE = 5;
45
46 public function __construct(
47 protected ComponentFactory $component_factory,
48 protected ObjectPropertiesAggregator $obj_properties,
49 protected SubitemPropertiesAggregator $subitem_properties,
50 protected SubitemPropertiesFactory $subitem_properties_factory,
51 protected CopyrightHelper $copyright_helper,
52 protected AccessChecker $access,
53 protected Sanitizer $sanitizer
54 ) {
55 }
56
61 ilSearchResult $result,
62 ViewControlInfos $view_control_infos
63 ): array {
64 $items = [];
65 $subitem_modals = [];
66
67 $items_with_sort_data = [];
68 $subitem_ids_by_obj_id = $result->getSubitemIds();
69 foreach ($result->getResultsForPresentation() as $ref_id => $obj_id) {
70 $title = $this->obj_properties->lookupTitle($obj_id);
71 $creation_date = $this->obj_properties->lookupCreationDate($obj_id);
72 $type = $this->obj_properties->lookupType($obj_id);
73
74 $subitem_ids = [];
75 $too_many_subitems = false;
76 if ($this->access->canSeeSubitemsOfObject($ref_id)) {
77 $subitem_ids = $subitem_ids_by_obj_id[$obj_id] ?? [];
78 $too_many_subitems = count($subitem_ids) > self::MAX_SUBITEMS;
79 $subitem_ids = array_slice($subitem_ids, 0, self::MAX_SUBITEMS);
80 }
81 $subitem_modal = $this->component_factory->getModalForSubitems(
82 $title,
83 self::MAX_SUBITEMS_PER_PAGE,
84 $too_many_subitems,
85 ...$this->getItemsForSubitemsFromDirectSearch($ref_id, $obj_id, $type, ...$subitem_ids),
86 );
87 if ($subitem_modal !== null) {
88 $subitem_modals[] = $subitem_modal;
89 }
90
91 $item = $this->component_factory->getItemForObject(
92 $this->obj_properties->buildIconPath($obj_id, $type),
93 $this->obj_properties->makeTypePresentable($type),
94 $title,
95 $this->obj_properties->buildLink($ref_id, $type),
96 $this->obj_properties->lookupDescription($obj_id),
97 '',
98 $this->obj_properties->buildRepositoryPath($ref_id),
99 $creation_date,
100 $this->copyright_helper->readPresentableCopyright($obj_id, 0, $type),
101 $subitem_modal?->getShowSignal()
102 );
103 $items_with_sort_data[] = [
104 'relevance' => 0,
105 'title' => $title,
106 'creation_date' => $creation_date,
107 'item' => $item
108 ];
109 }
110
111 $items = $this->sortObjectItems($view_control_infos->sortation(), ...$items_with_sort_data);
112
113 return [
114 $this->component_factory->getPanel(
115 $view_control_infos,
116 ...$items
117 ),
118 $subitem_modals
119 ];
120 }
121
127 int $ref_id,
128 int $obj_id,
129 string $type,
130 array ...$raw_sub_ids
131 ): Generator {
132 $sub_ids = [];
133 foreach ($raw_sub_ids as $raw_sub_id) {
134 $sub_ids[] = $this->subitem_properties_factory->getID(
135 (string) $raw_sub_id['id'],
136 (string) $raw_sub_id['type']
137 );
138 }
139 $subitem_properties = $this->subitem_properties->getSubitemProperties($ref_id, $type, ...$sub_ids);
140 foreach ($subitem_properties as $properties) {
141 yield $this->component_factory->getItemForSubitem(
142 $properties->title(),
143 $properties->link(),
144 $properties->openLinkInNewViewport(),
145 '',
146 $properties->presentableSubitemType(),
147 $this->copyright_helper->readPresentableCopyright($obj_id, (int) $properties->id()->id(), $properties->id()->type())
148 );
149 }
150 }
151
158 ViewControlInfos $view_control_infos
159 ): array {
160 $items = [];
161 $subitem_modals = [];
162
163 $items_with_sort_data = [];
164 foreach ($result->getResults() as $ref_id => $obj_id) {
165 $creation_date = $this->obj_properties->lookupCreationDate($obj_id);
166 $type = $this->obj_properties->lookupType($obj_id);
167 $title_no_highlights = $this->obj_properties->lookupTitle($obj_id);
168
169 $subitem_ids = [];
170 $too_many_subitems = false;
171 if ($this->access->canSeeSubitemsOfObject($ref_id)) {
172 $subitem_ids = $highlighter->getSubItemIds($obj_id);
173 $too_many_subitems = count($subitem_ids) > self::MAX_SUBITEMS;
174 $subitem_ids = array_slice($subitem_ids, 0, self::MAX_SUBITEMS);
175 }
176 $subitem_modal = $this->component_factory->getModalForSubitems(
177 $title_no_highlights,
178 self::MAX_SUBITEMS_PER_PAGE,
179 $too_many_subitems,
180 ...$this->getItemsForSubitemsFromLuceneSearch($highlighter, $obj_id, $ref_id, $type, ...$subitem_ids),
181 );
182 if ($subitem_modal !== null) {
183 $subitem_modals[] = $subitem_modal;
184 }
185
186 $item = $this->component_factory->getItemForObject(
187 $this->obj_properties->buildIconPath($obj_id, $type),
188 $this->obj_properties->makeTypePresentable($type),
189 $highlighter->getTitle($obj_id, 0, '') ?: $title_no_highlights,
190 $this->obj_properties->buildLink($ref_id, $type),
191 $highlighter->getDescription($obj_id, 0, '') ?: $this->obj_properties->lookupDescription($obj_id),
192 $highlighter->getContent($obj_id, 0, ''),
193 $this->obj_properties->buildRepositoryPath($ref_id),
194 $creation_date,
195 $this->copyright_helper->readPresentableCopyright($obj_id, 0, $type),
196 $subitem_modal?->getShowSignal()
197 );
198 $items_with_sort_data[] = [
199 'relevance' => $highlighter->getRelevance($obj_id, 0, ''),
200 'title' => $title_no_highlights,
201 'creation_date' => $creation_date,
202 'item' => $item
203 ];
204 }
205
206 $items = $this->sortObjectItems($view_control_infos->sortation(), ...$items_with_sort_data);
207
208 return [
209 $this->component_factory->getPanel(
210 $view_control_infos,
211 ...$items
212 ),
213 $subitem_modals
214 ];
215 }
216
223 int $obj_id,
224 int $ref_id,
225 string $type,
226 array ...$raw_sub_ids
227 ): Generator {
228 $sub_ids = [];
229 foreach ($raw_sub_ids as $raw_sub_id) {
230 $sub_ids[] = $this->subitem_properties_factory->getID(
231 (string) $raw_sub_id['id'],
232 (string) $raw_sub_id['type']
233 );
234 }
235 $subitem_properties = $this->subitem_properties->getSubitemProperties($ref_id, $type, ...$sub_ids);
236 foreach ($subitem_properties as $properties) {
237 $subitem_id = (int) $properties->id()->id();
238 $subitem_type = $properties->id()->type();
239 yield $this->component_factory->getItemForSubitem(
240 $highlighter->getTitle($obj_id, $subitem_id, $subitem_type) ?: $properties->title(),
241 $properties->link(),
242 $properties->openLinkInNewViewport(),
243 $highlighter->getContent($obj_id, $subitem_id, $subitem_type),
244 $properties->presentableSubitemType(),
245 $this->copyright_helper->readPresentableCopyright($obj_id, (int) $properties->id()->id(), $properties->id()->type())
246 );
247 }
248 }
249
254 protected function sortObjectItems(Sortation $sortation, array ...$items_with_sort_data): \Generator
255 {
256 $sort_callable = match ($sortation) {
257 Sortation::RELEVANCE_DESC => fn($a, $b) => $b['relevance'] <=> $a['relevance'],
258 Sortation::TITLE_ASC => fn($a, $b) => [$a['title'], $a['relevance']] <=> [$b['title'], $b['relevance']],
259 Sortation::TITLE_DESC => fn($a, $b) => [$b['title'], $b['relevance']] <=> [$a['title'], $a['relevance']],
260 Sortation::CREATION_DATE_ASC => fn($a, $b) => [$a['creation_date'], $a['relevance']] <=> [$b['creation_date'], $b['relevance']],
261 Sortation::CREATION_DATE_DESC => fn($a, $b) => [$b['creation_date'], $b['relevance']] <=> [$a['creation_date'], $a['relevance']]
262 };
263
264 usort($items_with_sort_data, $sort_callable);
265
266 foreach ($items_with_sort_data as $item) {
267 yield $item['item'];
268 }
269 }
270
271 public function getViewControlInfos(
272 Sortation $sortation,
273 int $current_page,
274 int $max_pages,
275 int $page_size,
276 URI $pagination_action,
277 Param $page_param_name,
278 URI $sortation_action,
279 Param $sortation_param_name
282 $sortation,
283 $current_page,
284 $max_pages,
285 $page_size,
286 $pagination_action,
287 $page_param_name,
288 $sortation_action,
289 $sortation_param_name
290 );
291 }
292
293 public function replacePlaceholders(string $html): string
294 {
295 return $this->sanitizer->replacePlaceholders($html);
296 }
297}
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
getItemsForSubitemsFromDirectSearch(int $ref_id, int $obj_id, string $type, array ... $raw_sub_ids)
getLuceneSearchResultAsPanel(ilLuceneSearchResultFilter $result, ilLuceneHighlighterResultParser $highlighter, ViewControlInfos $view_control_infos)
sortObjectItems(Sortation $sortation, array ... $items_with_sort_data)
getItemsForSubitemsFromLuceneSearch(ilLuceneHighlighterResultParser $highlighter, int $obj_id, int $ref_id, string $type, array ... $raw_sub_ids)
__construct(protected ComponentFactory $component_factory, protected ObjectPropertiesAggregator $obj_properties, protected SubitemPropertiesAggregator $subitem_properties, protected SubitemPropertiesFactory $subitem_properties_factory, protected CopyrightHelper $copyright_helper, protected AccessChecker $access, protected Sanitizer $sanitizer)
getDirectSearchResultAsPanel(ilSearchResult $result, ViewControlInfos $view_control_infos)
getViewControlInfos(Sortation $sortation, int $current_page, int $max_pages, int $page_size, URI $pagination_action, Param $page_param_name, URI $sortation_action, Param $sortation_param_name)
Parses result XML from lucene search highlight.
getTitle(int $obj_id, int $sub_id, string $sub_type)
getDescription(int $obj_id, int $sub_id, string $sub_type)
getContent(int $obj_id, int $sub_id, string $sub_type)
getRelevance(int $obj_id, int $sub_id, string $sub_type)
Validate Lucene search results Do access checks, create ref_ids from obj_ids...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Common interface to all items.
Definition: Item.php:32
This describes commonalities between the different modals.
Definition: Modal.php:35
$ref_id
Definition: ltiauth.php:66
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples