ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
ILIAS\Search\Presentation\Result\ResultPresenterImpl Class Reference
+ Inheritance diagram for ILIAS\Search\Presentation\Result\ResultPresenterImpl:
+ Collaboration diagram for ILIAS\Search\Presentation\Result\ResultPresenterImpl:

Public Member Functions

 __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)
 
 getLuceneSearchResultAsPanel (ilLuceneSearchResultFilter $result, ilLuceneHighlighterResultParser $highlighter, 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)
 
 replacePlaceholders (string $html)
 
 getDirectSearchResultAsPanel (ilSearchResult $result, ViewControlInfos $view_control_infos)
 
 getLuceneSearchResultAsPanel (ilLuceneSearchResultFilter $result, ilLuceneHighlighterResultParser $highlighter, 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)
 
 replacePlaceholders (string $html)
 

Protected Member Functions

 getItemsForSubitemsFromDirectSearch (int $ref_id, int $obj_id, string $type, array ... $raw_sub_ids)
 
 getItemsForSubitemsFromLuceneSearch (ilLuceneHighlighterResultParser $highlighter, int $obj_id, int $ref_id, string $type, array ... $raw_sub_ids)
 
 sortObjectItems (Sortation $sortation, array ... $items_with_sort_data)
 

Protected Attributes

const int MAX_SUBITEMS = 49
 
const int MAX_SUBITEMS_PER_PAGE = 5
 

Detailed Description

Definition at line 41 of file ResultPresenterImpl.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Search\Presentation\Result\ResultPresenterImpl::__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 
)

Definition at line 46 of file ResultPresenterImpl.php.

54 {
55 }

Member Function Documentation

◆ getDirectSearchResultAsPanel()

ILIAS\Search\Presentation\Result\ResultPresenterImpl::getDirectSearchResultAsPanel ( ilSearchResult  $result,
ViewControlInfos  $view_control_infos 
)
Returns
array{0: ListingPanel, 1: Modal[]}

Implements ILIAS\Search\Presentation\Result\ResultPresenter.

Definition at line 60 of file ResultPresenterImpl.php.

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 }
getItemsForSubitemsFromDirectSearch(int $ref_id, int $obj_id, string $type, array ... $raw_sub_ids)
sortObjectItems(Sortation $sortation, array ... $items_with_sort_data)
$ref_id
Definition: ltiauth.php:66

References $ref_id, ILIAS\Repository\access(), ILIAS\Search\Presentation\Result\ResultPresenterImpl\getItemsForSubitemsFromDirectSearch(), and ILIAS\Search\Presentation\Result\ResultPresenterImpl\MAX_SUBITEMS.

+ Here is the call graph for this function:

◆ getItemsForSubitemsFromDirectSearch()

ILIAS\Search\Presentation\Result\ResultPresenterImpl::getItemsForSubitemsFromDirectSearch ( int  $ref_id,
int  $obj_id,
string  $type,
array ...  $raw_sub_ids 
)
protected
Parameters
array{idint, type: string} ...$raw_sub_ids
Returns
Item[]

Definition at line 126 of file ResultPresenterImpl.php.

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 }

Referenced by ILIAS\Search\Presentation\Result\ResultPresenterImpl\getDirectSearchResultAsPanel().

+ Here is the caller graph for this function:

◆ getItemsForSubitemsFromLuceneSearch()

ILIAS\Search\Presentation\Result\ResultPresenterImpl::getItemsForSubitemsFromLuceneSearch ( ilLuceneHighlighterResultParser  $highlighter,
int  $obj_id,
int  $ref_id,
string  $type,
array ...  $raw_sub_ids 
)
protected
Parameters
array{idint, type: string} ...$raw_sub_ids
Returns
Item[]

Definition at line 221 of file ResultPresenterImpl.php.

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 }
getTitle(int $obj_id, int $sub_id, string $sub_type)
getContent(int $obj_id, int $sub_id, string $sub_type)

◆ getLuceneSearchResultAsPanel()

ILIAS\Search\Presentation\Result\ResultPresenterImpl::getLuceneSearchResultAsPanel ( ilLuceneSearchResultFilter  $result,
ilLuceneHighlighterResultParser  $highlighter,
ViewControlInfos  $view_control_infos 
)
Returns
array{0: ListingPanel, 1: Modal[]}

Implements ILIAS\Search\Presentation\Result\ResultPresenter.

Definition at line 155 of file ResultPresenterImpl.php.

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 }
getItemsForSubitemsFromLuceneSearch(ilLuceneHighlighterResultParser $highlighter, int $obj_id, int $ref_id, string $type, array ... $raw_sub_ids)
getDescription(int $obj_id, int $sub_id, string $sub_type)
getRelevance(int $obj_id, int $sub_id, string $sub_type)

References $ref_id, ILIAS\Repository\access(), ilLuceneHighlighterResultParser\getContent(), ilLuceneHighlighterResultParser\getDescription(), ilLuceneHighlighterResultParser\getRelevance(), ilLuceneHighlighterResultParser\getSubItemIds(), and ilLuceneHighlighterResultParser\getTitle().

+ Here is the call graph for this function:

◆ getViewControlInfos()

ILIAS\Search\Presentation\Result\ResultPresenterImpl::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 
)

Implements ILIAS\Search\Presentation\Result\ResultPresenter.

Definition at line 271 of file ResultPresenterImpl.php.

281 return new ViewControlInfosImpl(
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 }

◆ replacePlaceholders()

ILIAS\Search\Presentation\Result\ResultPresenterImpl::replacePlaceholders ( string  $html)

Implements ILIAS\Search\Presentation\Result\ResultPresenter.

Definition at line 293 of file ResultPresenterImpl.php.

293 : string
294 {
295 return $this->sanitizer->replacePlaceholders($html);
296 }

◆ sortObjectItems()

ILIAS\Search\Presentation\Result\ResultPresenterImpl::sortObjectItems ( Sortation  $sortation,
array ...  $items_with_sort_data 
)
protected
Parameters
array{relevanceint, title: string, creation_date: DateTimeImmutable, item: Item} ...$items_with_sort_data
Returns
Item[]

Definition at line 254 of file ResultPresenterImpl.php.

254 : \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 }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a, Vendor\Package\$b, and ILIAS\Search\Presentation\Result\CREATION_DATE_DESC.

Field Documentation

◆ MAX_SUBITEMS

const int ILIAS\Search\Presentation\Result\ResultPresenterImpl::MAX_SUBITEMS = 49
protected

◆ MAX_SUBITEMS_PER_PAGE

const int ILIAS\Search\Presentation\Result\ResultPresenterImpl::MAX_SUBITEMS_PER_PAGE = 5
protected

Definition at line 44 of file ResultPresenterImpl.php.


The documentation for this class was generated from the following file: