ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
68 include_once './Services/Object/classes/class.ilSubItemListGUI.php';
70 }
71 }
72
76 public function getContainer()
77 {
78 return $this->container;
79 }
80
81 public function getMode()
82 {
83 return $this->mode;
84 }
85
90 public function setResults($a_result_data)
91 {
92 $this->results = $a_result_data;
93 }
94
99 public function getResults()
100 {
101 return $this->results ? $this->results : array();
102 }
103
110 public function setSubitemIds($a_subids)
111 {
112 $this->subitem_ids = $a_subids;
113 }
114
119 public function getSubitemIds()
120 {
121 return $this->subitem_ids ? $this->subitem_ids : array();
122 }
123
129 public function getSubitemIdsByObject($a_obj_id)
130 {
131 return (isset($this->subitem_ids[$a_obj_id]) and $this->subitem_ids[$a_obj_id]) ?
132 $this->subitem_ids[$a_obj_id] :
133 array();
134 }
135
136
137
141 protected function parseResultReferences()
142 {
143 global $ilAccess;
144
145 foreach($this->getResults() as $ref_id => $obj_id)
146 {
147 $this->all_references[$ref_id][] = $ref_id;
148 $counter = 0;
149 foreach(ilObject::_getAllReferences($obj_id) as $new_ref)
150 {
151 if($new_ref == $ref_id)
152 {
153 continue;
154 }
155 if(!$ilAccess->checkAccess('read','',$new_ref))
156 {
157 continue;
158 }
159 $this->all_references[$ref_id][] = $new_ref;
160 ++$counter;
161 }
162 $this->has_more_ref_ids[$ref_id] = $counter;
163 }
164 }
165
166 protected function hasMoreReferences($a_ref_id)
167 {
168 if(!isset($this->has_more_ref_ids[$a_ref_id]) or
169 !$this->has_more_ref_ids[$a_ref_id] or
170 isset($_SESSION['vis_references'][$a_ref_id]))
171 {
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 {
182 return $this->all_references[$a_ref_id] ? $this->all_references[$a_ref_id] : array();
183 }
184 else
185 {
186 return array($a_ref_id);
187 }
188 }
189
194 public function getHTML($a_new = false)
195 {
196 return $this->thtml;
197 }
198
204 public function setSearcher($a_searcher)
205 {
206 $this->searcher = $a_searcher;
207 }
208
214 public function render()
215 {
216 return $this->renderItemList();
217 }
218
222 function setPreviousNext($a_p, $a_n)
223 {
224 $this->prev = $a_p;
225 $this->next = $a_n;
226 }
227
228
233 protected function renderItemList()
234 {
235 global $tree,$ilBench, $lng;
236
237 $this->html = '';
238
239 $ilBench->start('Lucene','2000_pr');
240 $this->parseResultReferences();
241 $ilBench->stop('Lucene','2000_pr');
242
243 $lng->loadLanguageModule("cntr"); // #16834
244
245 include_once("./Services/Object/classes/class.ilObjectListGUIPreloader.php");
247
248 $set = array();
249 foreach($this->getResults() as $c_ref_id => $obj_id)
250 {
251 $ilBench->start('Lucene','2100_res');
252 foreach($this->getAllReferences($c_ref_id) as $ref_id)
253 {
254 $ilBench->start('Lucene','2120_tree');
255 if(!$tree->isInTree($ref_id))
256 {
257 continue;
258 }
259 $ilBench->stop('Lucene','2120_tree');
260
261 $obj_type = ilObject::_lookupType($obj_id);
262
263 $set[] = array(
264 "ref_id" => $ref_id,
265 "obj_id" => $obj_id,
266 "title" => $this->lookupTitle($obj_id,0),
267 "title_sort" => ilObject::_lookupTitle($obj_id),
268 "description" => $this->lookupDescription($obj_id,0),
269 "type" => $obj_type,
270 "relevance" => $this->getRelevance($obj_id),
271 "s_relevance" => sprintf("%03d",$this->getRelevance($obj_id))
272 );
273
274 $preloader->addItem($obj_id, $obj_type, $ref_id);
275 }
276 $ilBench->stop('Lucene','2100_res');
277 }
278
279 if(!count($set))
280 {
281 return false;
282 }
283
284 $preloader->preload();
285 unset($preloader);
286
287 $ilBench->start('Lucene','2900_tb');
288 include_once("./Services/Search/classes/class.ilSearchResultTableGUI.php");
289 $result_table = new ilSearchResultTableGUI($this->container, "showSavedResults", $this);
290 $result_table->setCustomPreviousNext($this->prev, $this->next);
291
292 $result_table->setData($set);
293 $this->thtml = $result_table->getHTML();
294 $ilBench->stop('Lucene','2900_tb');
295
296 return true;
297 }
298
299
300 // searcher
306 public function getRelevance($a_obj_id)
307 {
308 if($this->getMode() == self::MODE_LUCENE)
309 {
310 return $this->searcher->getResult()->getRelevance($a_obj_id);
311 }
312 return 0;
313 }
314
320 public function lookupTitle($a_obj_id,$a_sub_id)
321 {
322 if($this->getMode() != self::MODE_LUCENE or !is_object($this->searcher->getHighlighter()))
323 {
324 return ilObject::_lookupTitle($a_obj_id);
325 }
326 if(strlen($title = $this->searcher->getHighlighter()->getTitle($a_obj_id,$a_sub_id)))
327 {
328 return $title;
329 }
330 return ilObject::_lookupTitle($a_obj_id);
331 }
332
338 public function lookupDescription($a_obj_id,$a_sub_id)
339 {
340 if($this->getMode() != self::MODE_LUCENE or !is_object($this->searcher->getHighlighter()))
341 {
342 return ilObject::_lookupDescription($a_obj_id);
343 }
344 if(strlen($title = $this->searcher->getHighlighter()->getDescription($a_obj_id,$a_sub_id)))
345 {
346 return $title;
347 }
348 return ilObject::_lookupDescription($a_obj_id);
349 }
350
356 public function lookupContent($a_obj_id,$a_sub_id)
357 {
358 if($this->getMode() != self::MODE_LUCENE or !is_object($this->searcher->getHighlighter()))
359 {
360 return '';
361 }
362 return $this->searcher->getHighlighter()->getContent($a_obj_id,$a_sub_id);
363 }
364
368 public function appendAdditionalInformation($item_list_gui,$ref_id,$obj_id,$type)
369 {
370 $sub = $this->appendSubItems($item_list_gui,$ref_id,$obj_id,$type);
371 $path = $this->appendPath($ref_id);
372 $more = $this->appendMorePathes($ref_id);
373 #$rel = $this->appendRelevance($obj_id);
374
375 if(!strlen($sub) and
376 !strlen($path) and
377 !strlen($more) and
378 !strlen($rel))
379 {
380 return '';
381 }
382 $tpl = new ilTemplate('tpl.lucene_additional_information.html',true,true,'Services/Search');
383 $tpl->setVariable('SUBITEM',$sub);
384 if(strlen($path)) {
385 $tpl->setVariable('PATH',$path);
386 }
387 if(strlen($more)) {
388 $tpl->setVariable('MORE_PATH',$more);
389 }
390 if(strlen($rel)) {
391 $tpl->setVariable('RELEVANCE',$rel);
392 }
393
394 $item_list_gui->setAdditionalInformation($tpl->get());
395 //$item_list_gui->setAdditionalInformation("Hello");
396 }
397
398
403 protected function appendPath($a_ref_id)
404 {
405 include_once './Services/Tree/classes/class.ilPathGUI.php';
406 $path_gui = new ilPathGUI();
407 $path_gui->enableTextOnly(false);
408 $path_gui->setUseImages(false);
409
410 $tpl = new ilTemplate('tpl.lucene_path.html',true,true,'Services/Search');
411 $tpl->setVariable('PATH_ITEM',$path_gui->getPath(ROOT_FOLDER_ID,$a_ref_id));
412 return $tpl->get();
413 }
414
419 protected function appendMorePathes($a_ref_id)
420 {
421 if($this->getMode() != self::MODE_LUCENE)
422 {
423 return '';
424 }
425
426
427 if(!$num_refs = $this->hasMoreReferences($a_ref_id))
428 {
429 return '';
430 }
431 $tpl = new ilTemplate('tpl.lucene_more_references.html',true,true,'Services/Search');
432 $this->ctrl->setParameter($this->getContainer(),'refs',$a_ref_id);
433 $tpl->setVariable('MORE_REFS_LINK',$this->ctrl->getLinkTarget($this->getContainer(),''));
434 $this->ctrl->clearParameters($this->getContainer());
435
436 $tpl->setVariable('TXT_MORE_REFS',sprintf($this->lng->txt('lucene_all_occurrences'),$num_refs));
437 return $tpl->get();
438 }
439
444 protected function appendRelevance($a_obj_id)
445 {
446 if($this->getMode() != self::MODE_LUCENE)
447 {
448 return '';
449 }
450
451 if(!((int) $this->getRelevance($a_obj_id)))
452 {
453 return '';
454 }
455
456 include_once './Services/Search/classes/class.ilSearchSettings.php';
457 if(!ilSearchSettings::getInstance()->isRelevanceVisible())
458 {
459 return '';
460 }
461
462 $tpl = new ilTemplate('tpl.lucene_relevance.html',true,true,'Services/Search');
463
464 include_once "Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
466 $pbar->setCurrent($this->getRelevance());
467
468 $this->tpl->setCurrentBlock('relevance');
469 $this->tpl->setVariable('REL_PBAR', $pbar->render());
470 $this->tpl->parseCurrentBlock();
471
472 $html = $tpl->get();
473 return $html;
474 }
475
480 protected function appendSubItems($item_list_gui,$ref_id,$obj_id,$a_type)
481 {
482 $subitem_ids = array();
483 if($this->getMode() == self::MODE_STANDARD)
484 {
485 $subitem_ids = $this->getSubitemIdsByObject($obj_id);
486 $highlighter = null;
487 }
488 elseif(is_object($this->searcher->getHighlighter()))
489 {
490 $subitem_ids = $this->searcher->getHighlighter()->getSubitemIds($obj_id);
491 $highlighter = $this->searcher->getHighlighter();
492 }
493
494 if(!count($subitem_ids))
495 {
496 return;
497 }
498
499 // Build subitem list
500 include_once './Services/Search/classes/Lucene/class.ilLuceneSubItemListGUIFactory.php';
502 $sub_list->setHighlighter($highlighter);
503 $sub_list->init($item_list_gui,$ref_id,$subitem_ids);
504 return $sub_list->getHTML();
505
506 }
507
508 protected function initReferences()
509 {
510 if(isset($_REQUEST['refs']))
511 {
512 $_SESSION['vis_references'][(int) $_REQUEST['refs']] = (int) $_REQUEST['refs'];
513 }
514 }
515}
516?>
$_GET["client_id"]
$_SESSION["AccountId"]
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
$html
Definition: example_001.php:87
global $ilBench
Definition: ilias.php:18
global $ilCtrl
Definition: ilias.php:18
$ref_id
Definition: sahs_server.php:39
$path
Definition: index.php:22
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7