ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $tpl,$lng,$ilCtrl;
58
59 $this->mode = $a_mode;
60 $this->lng = $lng;
61 $this->container = $container;
62 $this->ctrl = $ilCtrl;
63
64 $this->initReferences();
65
66 if (isset($_GET['details'])) {
67 include_once './Services/Object/classes/class.ilSubItemListGUI.php';
69 }
70 }
71
75 public function getContainer()
76 {
77 return $this->container;
78 }
79
80 public function getMode()
81 {
82 return $this->mode;
83 }
84
89 public function setResults($a_result_data)
90 {
91 $this->results = $a_result_data;
92 }
93
98 public function getResults()
99 {
100 return $this->results ? $this->results : array();
101 }
102
109 public function setSubitemIds($a_subids)
110 {
111 $this->subitem_ids = $a_subids;
112 }
113
118 public function getSubitemIds()
119 {
120 return $this->subitem_ids ? $this->subitem_ids : array();
121 }
122
128 public function getSubitemIdsByObject($a_obj_id)
129 {
130 return (isset($this->subitem_ids[$a_obj_id]) and $this->subitem_ids[$a_obj_id]) ?
131 $this->subitem_ids[$a_obj_id] :
132 array();
133 }
134
135
136
140 protected function parseResultReferences()
141 {
142 global $ilAccess;
143
144 foreach ($this->getResults() as $ref_id => $obj_id) {
145 $this->all_references[$ref_id][] = $ref_id;
146 $counter = 0;
147 foreach (ilObject::_getAllReferences($obj_id) as $new_ref) {
148 if ($new_ref == $ref_id) {
149 continue;
150 }
151 if (!$ilAccess->checkAccess('read', '', $new_ref)) {
152 continue;
153 }
154 $this->all_references[$ref_id][] = $new_ref;
155 ++$counter;
156 }
157 $this->has_more_ref_ids[$ref_id] = $counter;
158 }
159 }
160
161 protected function hasMoreReferences($a_ref_id)
162 {
163 if (!isset($this->has_more_ref_ids[$a_ref_id]) or
164 !$this->has_more_ref_ids[$a_ref_id] or
165 isset($_SESSION['vis_references'][$a_ref_id])) {
166 return false;
167 }
168
169 return $this->has_more_ref_ids[$a_ref_id];
170 }
171
172 protected function getAllReferences($a_ref_id)
173 {
174 if (isset($_SESSION['vis_references'][$a_ref_id])) {
175 return $this->all_references[$a_ref_id] ? $this->all_references[$a_ref_id] : array();
176 } else {
177 return array($a_ref_id);
178 }
179 }
180
185 public function getHTML($a_new = false)
186 {
187 return $this->thtml;
188 }
189
195 public function setSearcher($a_searcher)
196 {
197 $this->searcher = $a_searcher;
198 }
199
205 public function render()
206 {
207 return $this->renderItemList();
208 }
209
213 public function setPreviousNext($a_p, $a_n)
214 {
215 $this->prev = $a_p;
216 $this->next = $a_n;
217 }
218
219
224 protected function renderItemList()
225 {
226 global $tree,$ilBench, $lng;
227
228 $this->html = '';
229
230 $ilBench->start('Lucene', '2000_pr');
231 $this->parseResultReferences();
232 $ilBench->stop('Lucene', '2000_pr');
233
234 $lng->loadLanguageModule("cntr"); // #16834
235
236 include_once("./Services/Object/classes/class.ilObjectListGUIPreloader.php");
238
239 $set = array();
240 foreach ($this->getResults() as $c_ref_id => $obj_id) {
241 $ilBench->start('Lucene', '2100_res');
242 foreach ($this->getAllReferences($c_ref_id) as $ref_id) {
243 $ilBench->start('Lucene', '2120_tree');
244 if (!$tree->isInTree($ref_id)) {
245 continue;
246 }
247 $ilBench->stop('Lucene', '2120_tree');
248
249 $obj_type = ilObject::_lookupType($obj_id);
250
251 $set[] = array(
252 "ref_id" => $ref_id,
253 "obj_id" => $obj_id,
254 "title" => $this->lookupTitle($obj_id, 0),
255 "title_sort" => ilObject::_lookupTitle($obj_id),
256 "description" => $this->lookupDescription($obj_id, 0),
257 "type" => $obj_type,
258 "relevance" => $this->getRelevance($obj_id),
259 "s_relevance" => sprintf("%03d", $this->getRelevance($obj_id))
260 );
261
262 $preloader->addItem($obj_id, $obj_type, $ref_id);
263 }
264 $ilBench->stop('Lucene', '2100_res');
265 }
266
267 if (!count($set)) {
268 return false;
269 }
270
271 $preloader->preload();
272 unset($preloader);
273
274 $ilBench->start('Lucene', '2900_tb');
275 include_once("./Services/Search/classes/class.ilSearchResultTableGUI.php");
276 $result_table = new ilSearchResultTableGUI($this->container, "showSavedResults", $this);
277 $result_table->setCustomPreviousNext($this->prev, $this->next);
278
279 $result_table->setData($set);
280 $this->thtml = $result_table->getHTML();
281 $ilBench->stop('Lucene', '2900_tb');
282
283 return true;
284 }
285
286
287 // searcher
293 public function getRelevance($a_obj_id)
294 {
295 if ($this->getMode() == self::MODE_LUCENE) {
296 return $this->searcher->getResult()->getRelevance($a_obj_id);
297 }
298 return 0;
299 }
300
306 public function lookupTitle($a_obj_id, $a_sub_id)
307 {
308 if ($this->getMode() != self::MODE_LUCENE or !is_object($this->searcher->getHighlighter())) {
309 return ilObject::_lookupTitle($a_obj_id);
310 }
311 if (strlen($title = $this->searcher->getHighlighter()->getTitle($a_obj_id, $a_sub_id))) {
312 return $title;
313 }
314 return ilObject::_lookupTitle($a_obj_id);
315 }
316
322 public function lookupDescription($a_obj_id, $a_sub_id)
323 {
324 if ($this->getMode() != self::MODE_LUCENE or !is_object($this->searcher->getHighlighter())) {
325 return ilObject::_lookupDescription($a_obj_id);
326 }
327 if (strlen($title = $this->searcher->getHighlighter()->getDescription($a_obj_id, $a_sub_id))) {
328 return $title;
329 }
330 return ilObject::_lookupDescription($a_obj_id);
331 }
332
338 public function lookupContent($a_obj_id, $a_sub_id)
339 {
340 if ($this->getMode() != self::MODE_LUCENE or !is_object($this->searcher->getHighlighter())) {
341 return '';
342 }
343 return $this->searcher->getHighlighter()->getContent($a_obj_id, $a_sub_id);
344 }
345
349 public function appendAdditionalInformation($item_list_gui, $ref_id, $obj_id, $type)
350 {
351 $sub = $this->appendSubItems($item_list_gui, $ref_id, $obj_id, $type);
352 $path = $this->appendPath($ref_id);
353 $more = $this->appendMorePathes($ref_id);
354 #$rel = $this->appendRelevance($obj_id);
355
356 if (!strlen($sub) and
357 !strlen($path) and
358 !strlen($more) and
359 !strlen($rel)) {
360 return '';
361 }
362 $tpl = new ilTemplate('tpl.lucene_additional_information.html', true, true, 'Services/Search');
363 $tpl->setVariable('SUBITEM', $sub);
364 if (strlen($path)) {
365 $tpl->setVariable('PATH', $path);
366 }
367 if (strlen($more)) {
368 $tpl->setVariable('MORE_PATH', $more);
369 }
370 if (strlen($rel)) {
371 $tpl->setVariable('RELEVANCE', $rel);
372 }
373
374 $item_list_gui->setAdditionalInformation($tpl->get());
375 //$item_list_gui->setAdditionalInformation("Hello");
376 }
377
378
383 protected function appendPath($a_ref_id)
384 {
385 include_once './Services/Tree/classes/class.ilPathGUI.php';
386 $path_gui = new ilPathGUI();
387 $path_gui->enableTextOnly(false);
388 $path_gui->setUseImages(false);
389
390 $tpl = new ilTemplate('tpl.lucene_path.html', true, true, 'Services/Search');
391 $tpl->setVariable('PATH_ITEM', $path_gui->getPath(ROOT_FOLDER_ID, $a_ref_id));
392 return $tpl->get();
393 }
394
399 protected function appendMorePathes($a_ref_id)
400 {
401 if ($this->getMode() != self::MODE_LUCENE) {
402 return '';
403 }
404
405
406 if (!$num_refs = $this->hasMoreReferences($a_ref_id)) {
407 return '';
408 }
409 $tpl = new ilTemplate('tpl.lucene_more_references.html', true, true, 'Services/Search');
410 $this->ctrl->setParameter($this->getContainer(), 'refs', $a_ref_id);
411 $tpl->setVariable('MORE_REFS_LINK', $this->ctrl->getLinkTarget($this->getContainer(), ''));
412 $this->ctrl->clearParameters($this->getContainer());
413
414 $tpl->setVariable('TXT_MORE_REFS', sprintf($this->lng->txt('lucene_all_occurrences'), $num_refs));
415 return $tpl->get();
416 }
417
422 protected function appendRelevance($a_obj_id)
423 {
424 if ($this->getMode() != self::MODE_LUCENE) {
425 return '';
426 }
427
428 if (!((int) $this->getRelevance($a_obj_id))) {
429 return '';
430 }
431
432 include_once './Services/Search/classes/class.ilSearchSettings.php';
433 if (!ilSearchSettings::getInstance()->isRelevanceVisible()) {
434 return '';
435 }
436
437 $tpl = new ilTemplate('tpl.lucene_relevance.html', true, true, 'Services/Search');
438
439 include_once "Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
441 $pbar->setCurrent($this->getRelevance());
442
443 $this->tpl->setCurrentBlock('relevance');
444 $this->tpl->setVariable('REL_PBAR', $pbar->render());
445 $this->tpl->parseCurrentBlock();
446
447 $html = $tpl->get();
448 return $html;
449 }
450
455 protected function appendSubItems($item_list_gui, $ref_id, $obj_id, $a_type)
456 {
457 $subitem_ids = array();
458 if ($this->getMode() == self::MODE_STANDARD) {
459 $subitem_ids = $this->getSubitemIdsByObject($obj_id);
460 $highlighter = null;
461 } elseif (is_object($this->searcher->getHighlighter())) {
462 $subitem_ids = $this->searcher->getHighlighter()->getSubitemIds($obj_id);
463 $highlighter = $this->searcher->getHighlighter();
464 }
465
466 if (!count($subitem_ids)) {
467 return;
468 }
469
470 // Build subitem list
471 include_once './Services/Search/classes/Lucene/class.ilLuceneSubItemListGUIFactory.php';
473 $sub_list->setHighlighter($highlighter);
474 $sub_list->init($item_list_gui, $ref_id, $subitem_ids);
475 return $sub_list->getHTML();
476 }
477
478 protected function initReferences()
479 {
480 if (isset($_REQUEST['refs'])) {
481 $_SESSION['vis_references'][(int) $_REQUEST['refs']] = (int) $_REQUEST['refs'];
482 }
483 }
484}
sprintf('%.4f', $callTime)
html()
$_GET["client_id"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
static getInstanceByType($a_type, $a_cmd_class)
get instance by type
Preloader for object list GUIs.
static _lookupTitle($a_id)
lookup object title
static _lookupDescription($a_id)
lookup object description
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
Creates a path for a start and endnode.
static getInstance()
Factory.
Presentation of search results using object list gui.
appendAdditionalInformation($item_list_gui, $ref_id, $obj_id, $type)
Append path, relevance information.
appendSubItems($item_list_gui, $ref_id, $obj_id, $a_type)
Append subitems.
setPreviousNext($a_p, $a_n)
Set previous next.
appendRelevance($a_obj_id)
Append relevance.
lookupContent($a_obj_id, $a_sub_id)
get content
parseResultReferences()
Check if more than one reference is visible.
setSubitemIds($a_subids)
Set subitem ids Used for like and fulltext search.
setResults($a_result_data)
Set result array.
__construct($container=null, $a_mode=self::MODE_LUCENE)
Constructor.
appendMorePathes($a_ref_id)
Append more occurences link.
getSubitemIdsByObject($a_obj_id)
Get subitem ids for an object.
TableGUI class for search results.
static setShowDetails($a_obj_id)
set show details.
special template class to simplify handling of ITX/PEAR
$counter
$html
Definition: example_001.php:87
global $ilBench
Definition: ilias.php:18
global $ilCtrl
Definition: ilias.php:18
$type
$a_type
Definition: workflow.php:92