ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
ComponentFactoryImpl.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use DateTimeImmutable;
29use ILIAS\UI\Component\ViewControl\Sortation as SortationViewControl;
30use ILIAS\UI\Factory as UIFactory;
31use ilLanguage;
32use ilDateTime;
38
40{
41 protected const int MAX_DESCRIPTION_LENGTH = 128;
42
43 public function __construct(
44 protected UIFactory $ui_factory,
45 protected ilLanguage $lng,
46 protected Sanitizer $sanitizer
47 ) {
48 }
49
50 public function getPanel(
51 ViewControlInfos $view_control_infos,
52 Item ...$items
53 ): ListingPanel {
54 $item_group = $this->ui_factory->item()->group('', $items);
55 $view_controls = [
57 $view_control_infos->currentPage(),
58 $view_control_infos->maxPages(),
59 $view_control_infos->pageSize(),
60 $view_control_infos->paginationAction(),
61 $view_control_infos->pageParam()
62 ),
64 $view_control_infos->sortation(),
65 $view_control_infos->sortationAction(),
66 $view_control_infos->sortationParam()
67 )
68 ];
69
70 return $this->ui_factory->panel()->listing()->standard(
71 $this->lng->txt("search_results"),
72 [$item_group]
73 )->withViewControls($view_controls);
74 }
75
76 protected function getPaginationViewControl(
77 int $current_page,
78 int $max_pages,
79 int $page_size,
80 URI $action,
81 Param $page_param
82 ): Pagination {
83 // pages in the view control are 0-indexed, in search 1-indexed
84 return $this->ui_factory->viewControl()->pagination()
85 ->withTargetURL((string) $action, $page_param->value)
86 ->withCurrentPage($current_page - 1)
87 ->withPageSize($page_size)
88 ->withTotalEntries($page_size * $max_pages);
89 }
90
91 protected function getSortationViewControl(
92 Sortation $sortation,
93 URI $action,
94 Param $sortation_param
95 ): SortationViewControl {
96 $options = [
97 Sortation::RELEVANCE_DESC->value => $this->lng->txt('search_sort_relevance'),
98 Sortation::TITLE_ASC->value => $this->lng->txt('search_sort_title_asc'),
99 Sortation::TITLE_DESC->value => $this->lng->txt('search_sort_title_desc'),
100 Sortation::CREATION_DATE_DESC->value => $this->lng->txt('search_sort_creation_date_desc'),
101 Sortation::CREATION_DATE_ASC->value => $this->lng->txt('search_sort_creation_date_asc')
102 ];
103
104 return $this->ui_factory->viewControl()
105 ->sortation($options, $sortation->value)
106 ->withLabelPrefix($this->lng->txt('search_sort_by'))
107 ->withTargetURL((string) $action, $sortation_param->value);
108 }
109
110 public function getModalForSubitems(
111 string $object_title,
112 int $items_per_page,
113 bool $show_too_many_items_warning,
114 Item ...$items
115 ): ?Modal {
116 if ($items === []) {
117 return null;
118 }
119
120 if ($show_too_many_items_warning) {
121 $items[] = $this->ui_factory->item()->shy($this->lng->txt('search_results_too_many_subitems'));
122 }
123
124 $title = sprintf(
125 $this->lng->txt('search_detailed_results_title'),
126 $this->sanitizer->sanitize($object_title)
127 );
128
129 $pages = [];
130 foreach (array_chunk($items, $items_per_page) as $chunk_of_items) {
131 $card = $this->ui_factory->card()->standard($title)->withSections($chunk_of_items);
132 $pages[] = $this->ui_factory->modal()->lightboxCardPage($card);
133 }
134 return $this->ui_factory->modal()->lightbox($pages);
135 }
136
137 public function getItemForObject(
138 string $type_icon_path,
139 string $type_icon_label,
140 string $title,
141 ?URI $link,
142 string $description,
143 string $content,
144 string $path,
145 DateTimeImmutable $created_on,
146 string $copyright,
147 ?Signal $subitem_show_signal
148 ): Item {
149 $item_title = $this->sanitizer->sanitizeAndSetUpPlaceholders($title);
150 if ($link !== null) {
151 $item_title = $this->ui_factory->link()->standard($item_title, (string) $link);
152 }
153
154 $type_icon = $this->ui_factory->symbol()->icon()->custom(
155 $type_icon_path,
156 $this->sanitizer->sanitize($type_icon_label)
157 );
158
159 $properties = [
160 $this->lng->txt('path') => $this->sanitizer->sanitize($path),
161 $this->lng->txt('create_date') => $this->formatDate($created_on)
162 ];
163 if ($copyright !== '') {
164 $properties[$this->lng->txt('search_copyright')] = $this->sanitizer->sanitize($copyright);
165 }
166 if ($description !== '') {
167 if (mb_strlen($description) >= self::MAX_DESCRIPTION_LENGTH) {
168 $description = mb_substr($description, 0, self::MAX_DESCRIPTION_LENGTH) . '...';
169 }
170 $properties[$this->lng->txt('description')] = $this->sanitizer->sanitizeAndSetUpPlaceholders($description);
171 }
172
173 $item = $this->ui_factory->item()->standard($item_title)
174 ->withLeadIcon($type_icon);
175 if ($subitem_show_signal !== null) {
176 $button = $this->ui_factory->button()->standard(
177 $this->lng->txt('search_results_show_subitems'),
178 $subitem_show_signal
179 );
180 $item = $item->withMainAction($button);
181 }
182 return $item->withDescription($this->sanitizer->sanitizeAndSetUpPlaceholders($content))
183 ->withProperties($properties);
184 }
185
186 protected function formatDate(DateTimeImmutable $date): string
187 {
190 $res = ilDatePresentation::formatDate(new ilDateTime($date->getTimestamp(), IL_CAL_UNIX));
192 return $res;
193 }
194
195 public function getItemForSubitem(
196 string $title,
197 ?URI $link,
198 bool $open_link_in_new_viewport,
199 string $content,
200 string $type,
201 string $copyright
202 ): Item {
203 $item_title = $this->sanitizer->sanitizeAndSetUpPlaceholders($title);
204 if ($link !== null) {
205 $item_title = $this->ui_factory->link()->standard($item_title, (string) $link)
206 ->withOpenInNewViewport($open_link_in_new_viewport);
207 }
208 $properties = [$this->lng->txt('type') => $this->sanitizer->sanitize($type)];
209 if ($copyright !== '') {
210 $properties[$this->lng->txt('search_copyright')] = $this->sanitizer->sanitize($copyright);
211 }
212 return $this->ui_factory->item()->standard($item_title)
213 ->withDescription($this->sanitizer->sanitizeAndSetUpPlaceholders($content))
214 ->withProperties($properties);
215 }
216}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
getItemForSubitem(string $title, ?URI $link, bool $open_link_in_new_viewport, string $content, string $type, string $copyright)
getPaginationViewControl(int $current_page, int $max_pages, int $page_size, URI $action, Param $page_param)
getItemForObject(string $type_icon_path, string $type_icon_label, string $title, ?URI $link, string $description, string $content, string $path, DateTimeImmutable $created_on, string $copyright, ?Signal $subitem_show_signal)
__construct(protected UIFactory $ui_factory, protected ilLanguage $lng, protected Sanitizer $sanitizer)
getPanel(ViewControlInfos $view_control_infos, Item ... $items)
getSortationViewControl(Sortation $sortation, URI $action, Param $sortation_param)
getModalForSubitems(string $object_title, int $items_per_page, bool $show_too_many_items_warning, Item ... $items)
const IL_CAL_UNIX
Class for date presentation.
static setUseRelativeDates(bool $a_status)
set use relative dates
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
language handling
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
withDescription(string $description)
Create a new item with an attached description.
This describes commonalities between the different modals.
Definition: Modal.php:35
This describes a Pagination Control.
Definition: Pagination.php:33
This describes a Sortation Control.
Definition: Sortation.php:32
$path
Definition: ltiservices.php:30
$res
Definition: ltiservices.php:69
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))