ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSearchResultTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\HTTP\Services as HTTP;
23use ILIAS\Refinery\Factory as Refinery;
24
33{
35
36 protected ilObjUser $user;
39 protected UIServices $ui;
40 protected HTTP $http;
41 protected Refinery $refinery;
42
46 public function __construct($a_parent_obj, $a_parent_cmd, ilSearchResultPresentation $a_presenter)
47 {
48 global $DIC;
49
50 $this->user = $DIC->user();
51 $this->presenter = $a_presenter;
52 $this->objDefinition = $DIC['objDefinition'];
53 $this->ui = $DIC->ui();
54 $this->http = $DIC->http();
55 $this->refinery = $DIC->refinery();
56
57 $this->setId("ilSearchResultsTable");
58
59 $this->setId('search_' . $this->user->getId());
60 parent::__construct($a_parent_obj, $a_parent_cmd);
61 $this->setTitle($this->lng->txt("search_results"));
62 $this->setLimit(999);
63 $this->addColumn($this->lng->txt("type"), "", "1");
64 $this->addColumn($this->lng->txt("search_title_description"), "");
65
66 $all_cols = $this->getSelectableColumns();
67 foreach ($this->getSelectedColumns() as $col) {
68 $this->addColumn($all_cols[$col]['txt'], "", '50px');
69 }
70
71
72 $this->addColumn($this->lng->txt("actions"), "", "10px");
73
74 $this->setEnableHeader(true);
75 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
76 $this->setRowTemplate("tpl.search_result_row.html", "components/ILIAS/Search");
77 $this->setEnableTitle(true);
78 $this->setEnableNumInfo(false);
79 $this->setShowRowsSelector(false);
80 $this->setExternalSorting(true);
81 }
82
87 public function getSelectableColumns(): array
88 {
89 return array('create_date' =>
90 array(
91 'txt' => $this->lng->txt('create_date'),
92 'default' => false
93 )
94 );
95 }
96
97
101 protected function fillRow(array $a_set): void
102 {
103 $obj_id = $a_set["obj_id"];
104 $ref_id = $a_set["ref_id"];
105 $type = $a_set['type'];
106 $title = $a_set['title'];
107 $description = $a_set['description'];
108
109 if (!$type || $this->objDefinition->isSideBlock($type)) {
110 return;
111 }
112
113 $item_list_gui = ilLuceneSearchObjectListGUIFactory::factory($type);
114 $item_list_gui->initItem($ref_id, $obj_id, $type, $title, $description);
115 $item_list_gui->setContainerObject($this->parent_obj);
116 $item_list_gui->setSearchFragment($this->presenter->lookupContent($obj_id, 0));
117 $item_list_gui->setSeparateCommands(true);
118
120
121 $this->presenter->appendAdditionalInformation($item_list_gui, $ref_id, $obj_id, $type);
122
123 $this->tpl->setVariable("ACTION_HTML", $item_list_gui->getCommandsHTML($title));
124
125 if ($html = $item_list_gui->getListItemHTML($ref_id, $obj_id, '#SRC_HIGHLIGHT_TITLE', '#SRC_HIGHLIGHT_DESC')) {
126 // replace highlighted title/description
127 $html = str_replace(
128 [
129 '#SRC_HIGHLIGHT_TITLE',
130 '#SRC_HIGHLIGHT_DESC'
131 ],
132 [
133 $title,
134 strip_tags(
136 ['span']
137 )
138 ],
139 $html
140 );
141 $item_html[$ref_id]['html'] = $html;
142 $item_html[$ref_id]['type'] = $type;
143 }
144
145 $this->tpl->setVariable("ITEM_HTML", $html);
146
147 foreach ($this->getSelectedColumns() as $field) {
148 switch ($field) {
149 case 'create_date':
150 $this->tpl->setCurrentBlock('creation');
151 $this->tpl->setVariable('CREATION_DATE', ilDatePresentation::formatDate(new ilDateTime($a_set['create_date'], IL_CAL_DATETIME)));
152 $this->tpl->parseCurrentBlock();
153 }
154 }
155
156
157
158 if (!$this->objDefinition->isPlugin($type)) {
159 $type_txt = $this->lng->txt('icon') . ' ' . $this->lng->txt('obj_' . $type);
160 $icon = ilObject::_getIcon((int) $obj_id, 'small', $type);
161 } else {
162 $type_txt = ilObjectPlugin::lookupTxtById($type, "obj_" . $type);
163 $icon = ilObject::_getIcon((int) $obj_id, 'small', $type);
164 }
165
166 $this->tpl->setVariable(
167 "TYPE_IMG",
169 $icon,
170 $type_txt,
171 '',
172 '',
173 0,
174 '',
175 'ilIcon'
176 )
177 );
178 }
179
180 public function getHTML(): string
181 {
182 $view_control = $this->ui->renderer()->render($this->buildSortationViewControl());
183 return $view_control . parent::getHTML();
184 }
185
186 public function setDataAndApplySortation(array $set): void
187 {
188 if (in_array('create_date', $this->getSelectedColumns())) {
189 foreach ($set as $key => $row) {
190 $set[$key]['create_date'] = ilObject::_lookupCreationDate($row['obj_id']);
191 }
192 }
193
194 switch ($this->getCurrentSortation()) {
195 case 'relevance':
196 usort($set, function ($a, $b) {
197 return $b['relevance'] <=> $a['relevance'];
198 });
199 break;
200
201 case 'title_desc':
202 usort($set, function ($a, $b) {
203 return [$b['title'], $b['relevance'] ?? ''] <=> [$a['title'], $a['relevance'] ?? ''];
204 });
205 break;
206
207 case 'title_asc':
208 usort($set, function ($a, $b) {
209 return [$a['title'], $b['relevance'] ?? ''] <=> [$b['title'], $a['relevance'] ?? ''];
210 });
211 break;
212
213 case 'creation_date_desc':
214 usort($set, function ($a, $b) {
215 $a_date = \DateTime::createFromFormat('m-d-Y H:i:s', $a['create_date']);
216 $b_date = \DateTime::createFromFormat('m-d-Y H:i:s', $b['create_date']);
217 return [$b_date, $b['relevance'] ?? ''] <=> [$a_date, $a['relevance'] ?? ''];
218 });
219 break;
220
221 case 'creation_date_asc':
222 usort($set, function ($a, $b) {
223 $a_date = \DateTime::createFromFormat('Y-m-d H:i:s', $a['create_date']);
224 $b_date = \DateTime::createFromFormat('Y-m-d H:i:s', $b['create_date']);
225 return [$a_date, $b['relevance'] ?? ''] <=> [$b_date, $a['relevance'] ?? ''];
226 });
227 break;
228 };
229 parent::setData($set);
230 }
231
235 protected function getPossibleSortations(): array
236 {
237 $sorts = [
238 'relevance' => $this->lng->txt('search_sort_relevance'),
239 'title_asc' => $this->lng->txt('search_sort_title_asc'),
240 'title_desc' => $this->lng->txt('search_sort_title_desc')
241 ];
242 if (in_array('create_date', $this->getSelectedColumns())) {
243 $sorts = array_merge($sorts, [
244 'creation_date_desc' => $this->lng->txt('search_sort_creation_date_desc'),
245 'creation_date_asc' => $this->lng->txt('search_sort_creation_date_asc')
246 ]);
247 }
248 return $sorts;
249 }
250
251 protected function getDefaultSortation(): string
252 {
253 return $this->enabledRelevance() ? 'relevance' : 'title_asc';
254 }
255
256 protected function enabledRelevance(): bool
257 {
258 return ilSearchSettings::getInstance()->enabledLucene();
259 }
260}
factory()
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
const IL_CAL_DATETIME
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
User class.
static addListGUIActivationProperty(ilObjectListGUI $list_gui, array &$item)
Get timing details for list gui.
parses the objects.xml it handles the xml-description of all ilias objects
static lookupTxtById(string $plugin_id, string $lang_var)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static _lookupCreationDate(int $obj_id)
Presentation of search results using object list gui.
TableGUI class for search results.
getPossibleSortations()
Returns key => label.
ilSearchResultPresentation $presenter
__construct($a_parent_obj, $a_parent_cmd, ilSearchResultPresentation $a_presenter)
Constructor.
fillRow(array $a_set)
Fill table row.
getSelectableColumns()
Get selectable columns.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setEnableNumInfo(bool $a_val)
setEnableTitle(bool $a_enabletitle)
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setEnableHeader(bool $a_enableheader)
setExternalSorting(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
static img(string $a_src, ?string $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
$ref_id
Definition: ltiauth.php:66
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $DIC
Definition: shib_login.php:26
trait ilSearchResultTableHelper