ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilSearchResultTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 {
30  protected ilObjUser $user;
33 
37  public function __construct($a_parent_obj, $a_parent_cmd, ilSearchResultPresentation $a_presenter)
38  {
39  global $DIC;
40 
41  $this->user = $DIC->user();
42  $this->presenter = $a_presenter;
43  $this->objDefinition = $DIC['objDefinition'];
44 
45  $this->setId("ilSearchResultsTable");
46 
47  $this->setId('search_' . $this->user->getId());
48  parent::__construct($a_parent_obj, $a_parent_cmd);
49  $this->setTitle($this->lng->txt("search_results"));
50  $this->setLimit(999);
51  $this->addColumn($this->lng->txt("type"), "type", "1");
52  $this->addColumn($this->lng->txt("search_title_description"), "title");
53 
54  $all_cols = $this->getSelectableColumns();
55  foreach ($this->getSelectedColumns() as $col) {
56  $this->addColumn($all_cols[$col]['txt'], $col, '50px');
57  }
58 
59  if ($this->enabledRelevance()) {
60  $this->addColumn($this->lng->txt('lucene_relevance_short'), 'relevance', '50px');
61  $this->setDefaultOrderField("s_relevance");
62  $this->setDefaultOrderDirection("desc");
63  }
64 
65 
66  $this->addColumn($this->lng->txt("actions"), "", "10px");
67 
68  $this->setEnableHeader(true);
69  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
70  $this->setRowTemplate("tpl.search_result_row.html", "Services/Search");
71  $this->setEnableTitle(true);
72  $this->setEnableNumInfo(false);
73  $this->setShowRowsSelector(false);
74  }
75 
76  public function numericOrdering(string $a_field): bool
77  {
78  switch ($a_field) {
79  case 'relevance':
80  return true;
81  }
82  return parent::numericOrdering($a_field);
83  }
84 
89  public function getSelectableColumns(): array
90  {
91  return array('create_date' =>
92  array(
93  'txt' => $this->lng->txt('create_date'),
94  'default' => false
95  )
96  );
97  }
98 
99 
103  protected function fillRow(array $a_set): void
104  {
105  $obj_id = $a_set["obj_id"];
106  $ref_id = $a_set["ref_id"];
107  $type = $a_set['type'];
108  $title = $a_set['title'];
109  $description = $a_set['description'];
110  $relevance = $a_set['relevance'];
111 
112  if (!$type || $this->objDefinition->isSideBlock($type)) {
113  return;
114  }
115 
116  $item_list_gui = ilLuceneSearchObjectListGUIFactory::factory($type);
117  $item_list_gui->initItem($ref_id, $obj_id, $type, $title, $description);
118  $item_list_gui->setContainerObject($this->parent_obj);
119  $item_list_gui->setSearchFragment($this->presenter->lookupContent($obj_id, 0));
120  $item_list_gui->setSeparateCommands(true);
121 
122  ilObjectActivation::addListGUIActivationProperty($item_list_gui, $a_set);
123 
124  $this->presenter->appendAdditionalInformation($item_list_gui, $ref_id, $obj_id, $type);
125 
126  $this->tpl->setVariable("ACTION_HTML", $item_list_gui->getCommandsHTML());
127 
128  if ($html = $item_list_gui->getListItemHTML($ref_id, $obj_id, '#SRC_HIGHLIGHT_TITLE', '#SRC_HIGHLIGHT_DESC')) {
129  // replace highlighted title/description
130  $html = str_replace(
131  [
132  '#SRC_HIGHLIGHT_TITLE',
133  '#SRC_HIGHLIGHT_DESC'
134  ],
135  [
136  $title,
137  strip_tags(
138  $description,
139  ['span']
140  )
141  ],
142  $html
143  );
144  $item_html[$ref_id]['html'] = $html;
145  $item_html[$ref_id]['type'] = $type;
146  }
147 
148 
149  if ($this->enabledRelevance()) {
150  $pbar = ilProgressBar::getInstance();
151  $pbar->setCurrent($relevance);
152 
153  $this->tpl->setCurrentBlock('relev');
154  $this->tpl->setVariable('REL_PBAR', $pbar->render());
155  $this->tpl->parseCurrentBlock();
156  }
157 
158 
159  $this->tpl->setVariable("ITEM_HTML", $html);
160 
161  foreach ($this->getSelectedColumns() as $field) {
162  switch ($field) {
163  case 'create_date':
164  $this->tpl->setCurrentBlock('creation');
165  $this->tpl->setVariable('CREATION_DATE', ilDatePresentation::formatDate(new ilDateTime(ilObject::_lookupCreationDate($obj_id), IL_CAL_DATETIME)));
166  $this->tpl->parseCurrentBlock();
167  }
168  }
169 
170 
171 
172  if (!$this->objDefinition->isPlugin($type)) {
173  $type_txt = $this->lng->txt('icon') . ' ' . $this->lng->txt('obj_' . $type);
174  $icon = ilObject::_getIcon((int) $obj_id, 'small', $type);
175  } else {
176  $type_txt = ilObjectPlugin::lookupTxtById($type, "obj_" . $type);
177  $icon = ilObject::_getIcon((int) $obj_id, 'small', $type);
178  }
179 
180  $this->tpl->setVariable(
181  "TYPE_IMG",
182  ilUtil::img(
183  $icon,
184  $type_txt,
185  '',
186  '',
187  0,
188  '',
189  'ilIcon'
190  )
191  );
192  }
193 
194  protected function enabledRelevance(): bool
195  {
196  return
197  ilSearchSettings::getInstance()->enabledLucene() &&
198  ilSearchSettings::getInstance()->isRelevanceVisible();
199  }
200 }
const IL_CAL_DATETIME
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
setFormAction(string $a_form_action, bool $a_multipart=false)
$type
setEnableTitle(bool $a_enabletitle)
getSelectableColumns()
Get selectable columns.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
TableGUI class for search results.
static img(string $a_src, ?string $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
setId(string $a_val)
global $DIC
Definition: feed.php:28
parses the objects.xml it handles the xml-description of all ilias objects
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
$ref_id
Definition: ltiauth.php:67
setDefaultOrderField(string $a_defaultorderfield)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
static addListGUIActivationProperty(ilObjectListGUI $list_gui, array &$item)
Get timing details for list gui.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
static lookupTxtById(string $plugin_id, string $lang_var)
fillRow(array $a_set)
Fill table row.
setEnableNumInfo(bool $a_val)
static _lookupCreationDate(int $obj_id)
__construct(Container $dic, ilPlugin $plugin)
setLimit(int $a_limit=0, int $a_default_limit=0)
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)
ilSearchResultPresentation $presenter
__construct($a_parent_obj, $a_parent_cmd, ilSearchResultPresentation $a_presenter)
Constructor.
setEnableHeader(bool $a_enableheader)