ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilSearchResultPresentation.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
34 {
35  const MODE_LUCENE = 1;
36  const MODE_STANDARD = 2;
37 
38  protected $mode;
39 
40  protected $tpl;
41  protected $lng;
42 
43  private $results = array();
44  private $subitem_ids = array();
45  private $has_more_ref_ids = array();
46  private $all_references = null;
47  private $searcher = null;
48 
49  private $container = null;
50 
55  public function __construct($container = null, $a_mode = self::MODE_LUCENE)
56  {
57  global $DIC;
58 
59  $tpl = $DIC['tpl'];
60  $lng = $DIC['lng'];
61  $ilCtrl = $DIC['ilCtrl'];
62 
63  $this->mode = $a_mode;
64  $this->lng = $lng;
65  $this->container = $container;
66  $this->ctrl = $ilCtrl;
67 
68  $this->initReferences();
69 
70  if (isset($_GET['details'])) {
71  include_once './Services/Object/classes/class.ilSubItemListGUI.php';
72  ilSubItemListGUI::setShowDetails((int) $_GET['details']);
73  }
74  }
75 
79  public function getContainer()
80  {
81  return $this->container;
82  }
83 
84  public function getMode()
85  {
86  return $this->mode;
87  }
88 
93  public function setResults($a_result_data)
94  {
95  $this->results = $a_result_data;
96  }
97 
102  public function getResults()
103  {
104  return $this->results ? $this->results : array();
105  }
106 
113  public function setSubitemIds($a_subids)
114  {
115  $this->subitem_ids = $a_subids;
116  }
117 
122  public function getSubitemIds()
123  {
124  return $this->subitem_ids ? $this->subitem_ids : array();
125  }
126 
132  public function getSubitemIdsByObject($a_obj_id)
133  {
134  return (isset($this->subitem_ids[$a_obj_id]) and $this->subitem_ids[$a_obj_id]) ?
135  $this->subitem_ids[$a_obj_id] :
136  array();
137  }
138 
139 
140 
144  protected function parseResultReferences()
145  {
146  global $DIC;
147 
148  $ilAccess = $DIC['ilAccess'];
149 
150  foreach ($this->getResults() as $ref_id => $obj_id) {
151  $this->all_references[$ref_id][] = $ref_id;
152  $counter = 0;
153  foreach (ilObject::_getAllReferences($obj_id) as $new_ref) {
154  if ($new_ref == $ref_id) {
155  continue;
156  }
157  if (!$ilAccess->checkAccess('read', '', $new_ref)) {
158  continue;
159  }
160  $this->all_references[$ref_id][] = $new_ref;
161  ++$counter;
162  }
163  $this->has_more_ref_ids[$ref_id] = $counter;
164  }
165  }
166 
167  protected function hasMoreReferences($a_ref_id)
168  {
169  if (!isset($this->has_more_ref_ids[$a_ref_id]) or
170  !$this->has_more_ref_ids[$a_ref_id] or
171  isset($_SESSION['vis_references'][$a_ref_id])) {
172  return false;
173  }
174 
175  return $this->has_more_ref_ids[$a_ref_id];
176  }
177 
178  protected function getAllReferences($a_ref_id)
179  {
180  if (isset($_SESSION['vis_references'][$a_ref_id])) {
181  return $this->all_references[$a_ref_id] ? $this->all_references[$a_ref_id] : array();
182  } else {
183  return array($a_ref_id);
184  }
185  }
186 
191  public function getHTML($a_new = false)
192  {
193  return $this->thtml;
194  }
195 
201  public function setSearcher($a_searcher)
202  {
203  $this->searcher = $a_searcher;
204  }
205 
211  public function render()
212  {
213  return $this->renderItemList();
214  }
215 
219  public function setPreviousNext($a_p, $a_n)
220  {
221  $this->prev = $a_p;
222  $this->next = $a_n;
223  }
224 
225 
230  protected function renderItemList()
231  {
232  global $DIC;
233 
234  $tree = $DIC['tree'];
235  $ilBench = $DIC['ilBench'];
236  $lng = $DIC['lng'];
237 
238  $this->html = '';
239 
240  $ilBench->start('Lucene', '2000_pr');
241  $this->parseResultReferences();
242  $ilBench->stop('Lucene', '2000_pr');
243 
244  $lng->loadLanguageModule("cntr"); // #16834
245 
246  include_once("./Services/Object/classes/class.ilObjectListGUIPreloader.php");
248 
249  $set = array();
250  foreach ($this->getResults() as $c_ref_id => $obj_id) {
251  $ilBench->start('Lucene', '2100_res');
252  foreach ($this->getAllReferences($c_ref_id) as $ref_id) {
253  $ilBench->start('Lucene', '2120_tree');
254  if (!$tree->isInTree($ref_id)) {
255  continue;
256  }
257  $ilBench->stop('Lucene', '2120_tree');
258 
259  $obj_type = ilObject::_lookupType($obj_id);
260 
261  $set[] = array(
262  "ref_id" => $ref_id,
263  "obj_id" => $obj_id,
264  "title" => $this->lookupTitle($obj_id, 0),
265  "title_sort" => ilObject::_lookupTitle($obj_id),
266  "description" => $this->lookupDescription($obj_id, 0),
267  "type" => $obj_type,
268  "relevance" => $this->getRelevance($obj_id),
269  "s_relevance" => sprintf("%03d", $this->getRelevance($obj_id)),
270  'create_date' => ilObject::_lookupCreationDate($obj_id)
271  );
272 
273  $preloader->addItem($obj_id, $obj_type, $ref_id);
274  }
275  $ilBench->stop('Lucene', '2100_res');
276  }
277 
278  if (!count($set)) {
279  return false;
280  }
281 
282  $preloader->preload();
283  unset($preloader);
284 
285  $ilBench->start('Lucene', '2900_tb');
286  include_once("./Services/Search/classes/class.ilSearchResultTableGUI.php");
287  $result_table = new ilSearchResultTableGUI($this->container, "showSavedResults", $this);
288  $result_table->setCustomPreviousNext($this->prev, $this->next);
289 
290  $result_table->setData($set);
291  $this->thtml = $result_table->getHTML();
292  $ilBench->stop('Lucene', '2900_tb');
293 
294  return true;
295  }
296 
297 
298  // searcher
304  public function getRelevance($a_obj_id)
305  {
306  if ($this->getMode() == self::MODE_LUCENE) {
307  return $this->searcher->getResult()->getRelevance($a_obj_id);
308  }
309  return 0;
310  }
311 
317  public function lookupTitle($a_obj_id, $a_sub_id)
318  {
319  if ($this->getMode() != self::MODE_LUCENE or !is_object($this->searcher->getHighlighter())) {
320  return ilObject::_lookupTitle($a_obj_id);
321  }
322  if (strlen($title = $this->searcher->getHighlighter()->getTitle($a_obj_id, $a_sub_id))) {
323  return $title;
324  }
325  return ilObject::_lookupTitle($a_obj_id);
326  }
327 
333  public function lookupDescription($a_obj_id, $a_sub_id)
334  {
335  if ($this->getMode() != self::MODE_LUCENE or !is_object($this->searcher->getHighlighter())) {
336  return ilObject::_lookupDescription($a_obj_id);
337  }
338  if (strlen($title = $this->searcher->getHighlighter()->getDescription($a_obj_id, $a_sub_id))) {
339  return $title;
340  }
341  return ilObject::_lookupDescription($a_obj_id);
342  }
343 
349  public function lookupContent($a_obj_id, $a_sub_id)
350  {
351  if ($this->getMode() != self::MODE_LUCENE or !is_object($this->searcher->getHighlighter())) {
352  return '';
353  }
354  return $this->searcher->getHighlighter()->getContent($a_obj_id, $a_sub_id);
355  }
356 
360  public function appendAdditionalInformation($item_list_gui, $ref_id, $obj_id, $type)
361  {
362  $sub = $this->appendSubItems($item_list_gui, $ref_id, $obj_id, $type);
363  $path = $this->appendPath($ref_id);
364  $more = $this->appendMorePathes($ref_id);
365  #$rel = $this->appendRelevance($obj_id);
366 
367  if (!strlen($sub) and
368  !strlen($path) and
369  !strlen($more) and
370  !strlen($rel)) {
371  return '';
372  }
373  $tpl = new ilTemplate('tpl.lucene_additional_information.html', true, true, 'Services/Search');
374  $tpl->setVariable('SUBITEM', $sub);
375  if (strlen($path)) {
376  $tpl->setVariable('PATH', $path);
377  }
378  if (strlen($more)) {
379  $tpl->setVariable('MORE_PATH', $more);
380  }
381  if (strlen($rel)) {
382  $tpl->setVariable('RELEVANCE', $rel);
383  }
384 
385  $item_list_gui->setAdditionalInformation($tpl->get());
386  //$item_list_gui->setAdditionalInformation("Hello");
387  }
388 
389 
394  protected function appendPath($a_ref_id)
395  {
396  include_once './Services/Tree/classes/class.ilPathGUI.php';
397  $path_gui = new ilPathGUI();
398  $path_gui->enableTextOnly(false);
399  $path_gui->setUseImages(false);
400 
401  $tpl = new ilTemplate('tpl.lucene_path.html', true, true, 'Services/Search');
402  $tpl->setVariable('PATH_ITEM', $path_gui->getPath(ROOT_FOLDER_ID, $a_ref_id));
403  return $tpl->get();
404  }
405 
410  protected function appendMorePathes($a_ref_id)
411  {
412  if ($this->getMode() != self::MODE_LUCENE) {
413  return '';
414  }
415 
416 
417  if (!$num_refs = $this->hasMoreReferences($a_ref_id)) {
418  return '';
419  }
420  $tpl = new ilTemplate('tpl.lucene_more_references.html', true, true, 'Services/Search');
421  $this->ctrl->setParameter($this->getContainer(), 'refs', $a_ref_id);
422  $tpl->setVariable('MORE_REFS_LINK', $this->ctrl->getLinkTarget($this->getContainer(), ''));
423  $this->ctrl->clearParameters($this->getContainer());
424 
425  $tpl->setVariable('TXT_MORE_REFS', sprintf($this->lng->txt('lucene_all_occurrences'), $num_refs));
426  return $tpl->get();
427  }
428 
433  protected function appendRelevance($a_obj_id)
434  {
435  if ($this->getMode() != self::MODE_LUCENE) {
436  return '';
437  }
438 
439  if (!((int) $this->getRelevance($a_obj_id))) {
440  return '';
441  }
442 
443  include_once './Services/Search/classes/class.ilSearchSettings.php';
444  if (!ilSearchSettings::getInstance()->isRelevanceVisible()) {
445  return '';
446  }
447 
448  $tpl = new ilTemplate('tpl.lucene_relevance.html', true, true, 'Services/Search');
449 
450  include_once "Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
451  $pbar = ilProgressBar::getInstance();
452  $pbar->setCurrent($this->getRelevance());
453 
454  $this->tpl->setCurrentBlock('relevance');
455  $this->tpl->setVariable('REL_PBAR', $pbar->render());
456  $this->tpl->parseCurrentBlock();
457 
458  $html = $tpl->get();
459  return $html;
460  }
461 
466  protected function appendSubItems($item_list_gui, $ref_id, $obj_id, $a_type)
467  {
468  $subitem_ids = array();
469  if ($this->getMode() == self::MODE_STANDARD) {
470  $subitem_ids = $this->getSubitemIdsByObject($obj_id);
471  $highlighter = null;
472  } elseif (is_object($this->searcher->getHighlighter())) {
473  $subitem_ids = $this->searcher->getHighlighter()->getSubitemIds($obj_id);
474  $highlighter = $this->searcher->getHighlighter();
475  }
476 
477  if (!count($subitem_ids)) {
478  return;
479  }
480 
481  // Build subitem list
482  include_once './Services/Search/classes/Lucene/class.ilLuceneSubItemListGUIFactory.php';
484  $sub_list->setHighlighter($highlighter);
485  $sub_list->init($item_list_gui, $ref_id, $subitem_ids);
486  return $sub_list->getHTML();
487  }
488 
489  protected function initReferences()
490  {
491  if (isset($_REQUEST['refs'])) {
492  $_SESSION['vis_references'][(int) $_REQUEST['refs']] = (int) $_REQUEST['refs'];
493  }
494  }
495 }
appendMorePathes($a_ref_id)
Append more occurences link.
Creates a path for a start and endnode.
parseResultReferences()
Check if more than one reference is visible.
$path
Definition: aliased.php:25
$_SESSION["AccountId"]
static getInstanceByType($a_type, $a_cmd_class)
get instance by type
$type
global $DIC
Definition: saml.php:7
$_GET["client_id"]
TableGUI class for search results.
static _lookupTitle($a_id)
lookup object title
appendAdditionalInformation($item_list_gui, $ref_id, $obj_id, $type)
Append path, relevance information.
static _getAllReferences($a_id)
get all reference ids of object
appendRelevance($a_obj_id)
Append relevance.
global $ilCtrl
Definition: ilias.php:18
Preloader for object list GUIs.
$a_type
Definition: workflow.php:92
static getInstance()
Factory.
Presentation of search results using object list gui.
static _lookupCreationDate($a_id)
Lookup creation date.
setResults($a_result_data)
Set result array.
static _lookupDescription($a_id)
lookup object description
appendSubItems($item_list_gui, $ref_id, $obj_id, $a_type)
Append subitems.
special template class to simplify handling of ITX/PEAR
static setShowDetails($a_obj_id)
set show details.
setPreviousNext($a_p, $a_n)
Set previous next.
static _lookupType($a_id, $a_reference=false)
lookup object type
__construct($container=null, $a_mode=self::MODE_LUCENE)
Constructor.
lookupContent($a_obj_id, $a_sub_id)
get content
global $ilBench
Definition: ilias.php:18
setSubitemIds($a_subids)
Set subitem ids Used for like and fulltext search.
html()
getSubitemIdsByObject($a_obj_id)
Get subitem ids for an object.
$html
Definition: example_001.php:87