ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilSearchResultPresentation Class Reference

Presentation of search results using object list gui. More...

+ Collaboration diagram for ilSearchResultPresentation:

Public Member Functions

 __construct (?object $container=null, int $a_mode=self::MODE_LUCENE)
 Constructor. More...
 
 getContainer ()
 Get container gui. More...
 
 getMode ()
 
 setResults (array $a_result_data)
 Set result array. More...
 
 getResults ()
 get results More...
 
 setSubitemIds (array $a_subids)
 Set subitem ids Used for like and fulltext search. More...
 
 getSubitemIds ()
 Get subitem ids. More...
 
 getSubitemIdsByObject (int $a_obj_id)
 Get subitem ids for an object. More...
 
 getHTML ()
 Get HTML. More...
 
 setSearcher (ilLuceneSearcher $a_searcher)
 set searcher More...
 
 render ()
 Parse results. More...
 
 setPreviousNext (string $a_p, string $a_n)
 Set previous next. More...
 
 getRelevance (int $a_obj_id)
 
 lookupTitle (int $a_obj_id, int $a_sub_id)
 
 lookupDescription (int $a_obj_id, int $a_sub_id)
 
 lookupContent (int $a_obj_id, int $a_sub_id)
 
 appendAdditionalInformation (ilObjectListGUI $item_list_gui, int $ref_id, int $obj_id, string $type)
 Append path, relevance information. More...
 

Data Fields

const MODE_LUCENE = 1
 
const MODE_STANDARD = 2
 

Protected Member Functions

 parseResultReferences ()
 Check if more than one reference is visible. More...
 
 getMoreReferencesCounter (int $a_ref_id)
 
 getAllReferences (int $a_ref_id)
 
 renderItemList ()
 Render item list. More...
 
 appendPath (int $a_ref_id)
 
 appendMorePathes (int $a_ref_id)
 
 appendSubItems (ilObjectListGUI $item_list_gui, int $ref_id, int $obj_id, string $a_type)
 
 initReferences ()
 

Protected Attributes

int $mode
 
ilGlobalTemplateInterface $tpl
 
ilLanguage $lng
 
ilCtrl $ctrl
 
ilAccess $access
 
ilTree $tree
 
GlobalHttpState $http
 
Factory $refinery
 
string $prev
 
string $next
 
string $html
 
string $thtml
 

Private Attributes

array $results = []
 
array $subitem_ids = []
 
array $has_more_ref_ids = []
 
array $all_references = []
 
ilLuceneSearcher $searcher = null
 
object $container = null
 

Detailed Description

Presentation of search results using object list gui.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 32 of file class.ilSearchResultPresentation.php.

Constructor & Destructor Documentation

◆ __construct()

ilSearchResultPresentation::__construct ( ?object  $container = null,
int  $a_mode = self::MODE_LUCENE 
)

Constructor.

Parameters
object$containercontainer gui object

Definition at line 64 of file class.ilSearchResultPresentation.php.

65 {
66 global $DIC;
67
68 $this->tpl = $DIC->ui()->mainTemplate();
69 $this->lng = $DIC->language();
70 $this->ctrl = $DIC->ctrl();
71 $this->access = $DIC->access();
72 $this->tree = $DIC->repositoryTree();
73 $this->http = $DIC->http();
74 $this->refinery = $DIC->refinery();
75 $this->mode = $a_mode;
76 $this->container = $container;
77
78 $this->initReferences();
79
80 if ($this->http->wrapper()->query()->has('details')) {
82 $this->http->wrapper()->query()->retrieve(
83 'details',
84 $this->refinery->kindlyTo()->int()
85 )
86 );
87 }
88 }
static setShowDetails(int $obj_id)
set show details.
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26

References $container, $DIC, ILIAS\Repository\access(), ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), initReferences(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ilSubItemListGUI\setShowDetails().

+ Here is the call graph for this function:

Member Function Documentation

◆ appendAdditionalInformation()

ilSearchResultPresentation::appendAdditionalInformation ( ilObjectListGUI  $item_list_gui,
int  $ref_id,
int  $obj_id,
string  $type 
)

Append path, relevance information.

Definition at line 326 of file class.ilSearchResultPresentation.php.

331 : void {
332 $sub = $this->appendSubItems($item_list_gui, $ref_id, $obj_id, $type);
333 $path = $this->appendPath($ref_id);
334 $more = $this->appendMorePathes($ref_id);
335
336 if (!strlen($sub) and
337 !strlen($path) and
338 !strlen($more)) {
339 return;
340 }
341 $tpl = new ilTemplate('tpl.lucene_additional_information.html', true, true, 'components/ILIAS/Search');
342 $tpl->setVariable('SUBITEM', $sub);
343 if (strlen($path)) {
344 $tpl->setVariable('PATH', $path);
345 }
346 if (strlen($more)) {
347 $tpl->setVariable('MORE_PATH', $more);
348 }
349
350 $item_list_gui->setAdditionalInformation($tpl->get());
351 }
setAdditionalInformation(?string $val)
appendSubItems(ilObjectListGUI $item_list_gui, int $ref_id, int $obj_id, string $a_type)
special template class to simplify handling of ITX/PEAR
setVariable(string $variable, $value='')
Sets the given variable to the given value.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
$ref_id
Definition: ltiauth.php:66
$path
Definition: ltiservices.php:30

◆ appendMorePathes()

ilSearchResultPresentation::appendMorePathes ( int  $a_ref_id)
protected

Definition at line 365 of file class.ilSearchResultPresentation.php.

365 : string
366 {
367 if ($this->getMode() != self::MODE_LUCENE) {
368 return '';
369 }
370
371
372 if (!$num_refs = $this->getMoreReferencesCounter($a_ref_id)) {
373 return '';
374 }
375 $tpl = new ilTemplate('tpl.lucene_more_references.html', true, true, 'components/ILIAS/Search');
376 $this->ctrl->setParameter($this->getContainer(), 'refs', $a_ref_id);
377 $tpl->setVariable('MORE_REFS_LINK', $this->ctrl->getLinkTarget($this->getContainer(), ''));
378 $this->ctrl->clearParameters($this->getContainer());
379
380 $tpl->setVariable('TXT_MORE_REFS', sprintf($this->lng->txt('lucene_all_occurrences'), $num_refs));
381 return $tpl->get();
382 }

References ILIAS\Repository\ctrl(), ILIAS\UICore\GlobalTemplate\get(), ILIAS\Repository\lng(), and ILIAS\UICore\GlobalTemplate\setVariable().

+ Here is the call graph for this function:

◆ appendPath()

ilSearchResultPresentation::appendPath ( int  $a_ref_id)
protected

Definition at line 354 of file class.ilSearchResultPresentation.php.

354 : string
355 {
356 $path_gui = new ilPathGUI();
357 $path_gui->enableTextOnly(false);
358 $path_gui->setUseImages(false);
359
360 $tpl = new ilTemplate('tpl.lucene_path.html', true, true, 'components/ILIAS/Search');
361 $tpl->setVariable('PATH_ITEM', $path_gui->getPath(ROOT_FOLDER_ID, $a_ref_id));
362 return $tpl->get();
363 }
const ROOT_FOLDER_ID
Definition: constants.php:32

References ILIAS\UICore\GlobalTemplate\get(), ROOT_FOLDER_ID, and ILIAS\UICore\GlobalTemplate\setVariable().

+ Here is the call graph for this function:

◆ appendSubItems()

ilSearchResultPresentation::appendSubItems ( ilObjectListGUI  $item_list_gui,
int  $ref_id,
int  $obj_id,
string  $a_type 
)
protected

Definition at line 385 of file class.ilSearchResultPresentation.php.

390 : string {
391 $subitem_ids = array();
392 $highlighter = null;
393 if ($this->getMode() == self::MODE_STANDARD) {
394 $subitem_ids = $this->getSubitemIdsByObject($obj_id);
395 } elseif (is_object($this->searcher->getHighlighter())) {
396 $subitem_ids = $this->searcher->getHighlighter()->getSubitemIds($obj_id);
397 $highlighter = $this->searcher->getHighlighter();
398 }
399
400 if (!count($subitem_ids)) {
401 return '';
402 }
403
404 // Build subitem list
406 $sub_list->setHighlighter($highlighter);
407 $sub_list->init($item_list_gui, $ref_id, $subitem_ids);
408 return $sub_list->getHTML();
409 }
static getInstanceByType(string $a_type, object $a_cmd_class)
get instance by type
getSubitemIdsByObject(int $a_obj_id)
Get subitem ids for an object.

◆ getAllReferences()

ilSearchResultPresentation::getAllReferences ( int  $a_ref_id)
protected

Definition at line 184 of file class.ilSearchResultPresentation.php.

184 : array
185 {
186 $references = ilSession::get('vis_references') ?? [];
187 if (array_key_exists($a_ref_id, $references)) {
188 return $this->all_references[$a_ref_id] ?: array();
189 } else {
190 return array($a_ref_id);
191 }
192 }
static get(string $a_var)

References ilSession\get().

Referenced by renderItemList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getContainer()

ilSearchResultPresentation::getContainer ( )

Get container gui.

Definition at line 93 of file class.ilSearchResultPresentation.php.

93 : object
94 {
95 return $this->container;
96 }

References $container.

◆ getHTML()

ilSearchResultPresentation::getHTML ( )

Get HTML.

Returns
string HTML

Definition at line 198 of file class.ilSearchResultPresentation.php.

198 : string
199 {
200 return $this->thtml;
201 }

References $thtml.

◆ getMode()

ilSearchResultPresentation::getMode ( )

Definition at line 98 of file class.ilSearchResultPresentation.php.

98 : int
99 {
100 return $this->mode;
101 }

References $mode.

Referenced by getRelevance(), lookupContent(), lookupDescription(), and lookupTitle().

+ Here is the caller graph for this function:

◆ getMoreReferencesCounter()

ilSearchResultPresentation::getMoreReferencesCounter ( int  $a_ref_id)
protected

Definition at line 173 of file class.ilSearchResultPresentation.php.

173 : int
174 {
175 $references = ilSession::get('vis_references') ?? [];
176 if (!isset($this->has_more_ref_ids[$a_ref_id]) or
177 !$this->has_more_ref_ids[$a_ref_id] or
178 array_key_exists($a_ref_id, $references)) {
179 return 0;
180 }
181 return (int) $this->has_more_ref_ids[$a_ref_id];
182 }

References ilSession\get().

+ Here is the call graph for this function:

◆ getRelevance()

ilSearchResultPresentation::getRelevance ( int  $a_obj_id)

Definition at line 285 of file class.ilSearchResultPresentation.php.

285 : float
286 {
287 if ($this->getMode() == self::MODE_LUCENE) {
288 return $this->searcher->getResult()->getRelevance($a_obj_id);
289 }
290 return 0;
291 }

References getMode().

Referenced by renderItemList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getResults()

ilSearchResultPresentation::getResults ( )

get results

Definition at line 114 of file class.ilSearchResultPresentation.php.

114 : array
115 {
116 return $this->results;
117 }

References $results.

Referenced by parseResultReferences(), and renderItemList().

+ Here is the caller graph for this function:

◆ getSubitemIds()

ilSearchResultPresentation::getSubitemIds ( )

Get subitem ids.

Returns
array

Definition at line 134 of file class.ilSearchResultPresentation.php.

134 : array
135 {
136 return $this->subitem_ids;
137 }

References $subitem_ids.

◆ getSubitemIdsByObject()

ilSearchResultPresentation::getSubitemIdsByObject ( int  $a_obj_id)

Get subitem ids for an object.

Definition at line 142 of file class.ilSearchResultPresentation.php.

142 : array
143 {
144 return (isset($this->subitem_ids[$a_obj_id]) && $this->subitem_ids[$a_obj_id]) ?
145 $this->subitem_ids[$a_obj_id] :
146 array();
147 }

◆ initReferences()

ilSearchResultPresentation::initReferences ( )
protected

Definition at line 411 of file class.ilSearchResultPresentation.php.

411 : void
412 {
413 $session_references = ilSession::get('vis_references') ?? [];
414 if ($this->http->wrapper()->post()->has('refs')) {
415 $refs = $this->http->wrapper()->post()->retrieve(
416 'refs',
417 $this->refinery->kindlyTo()->int()
418 );
419 $session_references[$refs] = $refs;
420 ilSession::set('vis_references', $session_references);
421 }
422 }
static set(string $a_var, $a_val)
Set a value.

References ilSession\get(), ILIAS\FileDelivery\http(), ILIAS\Repository\refinery(), and ilSession\set().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupContent()

ilSearchResultPresentation::lookupContent ( int  $a_obj_id,
int  $a_sub_id 
)

Definition at line 315 of file class.ilSearchResultPresentation.php.

315 : string
316 {
317 if ($this->getMode() != self::MODE_LUCENE or !is_object($this->searcher->getHighlighter())) {
318 return '';
319 }
320 return $this->searcher->getHighlighter()->getContent($a_obj_id, $a_sub_id);
321 }

References getMode().

+ Here is the call graph for this function:

◆ lookupDescription()

ilSearchResultPresentation::lookupDescription ( int  $a_obj_id,
int  $a_sub_id 
)

Definition at line 304 of file class.ilSearchResultPresentation.php.

304 : string
305 {
306 if ($this->getMode() != self::MODE_LUCENE or !is_object($this->searcher->getHighlighter())) {
307 return ilObject::_lookupDescription($a_obj_id);
308 }
309 if (strlen($title = $this->searcher->getHighlighter()->getDescription($a_obj_id, $a_sub_id))) {
310 return $title;
311 }
312 return ilObject::_lookupDescription($a_obj_id);
313 }
static _lookupDescription(int $obj_id)

References ilObject\_lookupDescription(), and getMode().

Referenced by renderItemList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupTitle()

ilSearchResultPresentation::lookupTitle ( int  $a_obj_id,
int  $a_sub_id 
)

Definition at line 293 of file class.ilSearchResultPresentation.php.

293 : string
294 {
295 if ($this->getMode() != self::MODE_LUCENE or !is_object($this->searcher->getHighlighter())) {
296 return ilObject::_lookupTitle($a_obj_id);
297 }
298 if (strlen($title = $this->searcher->getHighlighter()->getTitle($a_obj_id, $a_sub_id))) {
299 return $title;
300 }
301 return ilObject::_lookupTitle($a_obj_id);
302 }
static _lookupTitle(int $obj_id)

References ilObject\_lookupTitle(), and getMode().

Referenced by renderItemList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseResultReferences()

ilSearchResultPresentation::parseResultReferences ( )
protected

Check if more than one reference is visible.

Definition at line 154 of file class.ilSearchResultPresentation.php.

154 : void
155 {
156 foreach ($this->getResults() as $ref_id => $obj_id) {
157 $this->all_references[$ref_id][] = $ref_id;
158 $counter = 0;
159 foreach (ilObject::_getAllReferences((int) $obj_id) as $new_ref) {
160 if ($new_ref == $ref_id) {
161 continue;
162 }
163 if (!$this->access->checkAccess('read', '', $new_ref)) {
164 continue;
165 }
166 $this->all_references[$ref_id][] = $new_ref;
167 ++$counter;
168 }
169 $this->has_more_ref_ids[$ref_id] = $counter;
170 }
171 }
static _getAllReferences(int $id)
get all reference ids for object ID
$counter

References $counter, $ref_id, ilObject\_getAllReferences(), ILIAS\Repository\access(), and getResults().

Referenced by renderItemList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ render()

ilSearchResultPresentation::render ( )

Parse results.

Definition at line 214 of file class.ilSearchResultPresentation.php.

214 : bool
215 {
216 return $this->renderItemList();
217 }

References renderItemList().

+ Here is the call graph for this function:

◆ renderItemList()

ilSearchResultPresentation::renderItemList ( )
protected

Render item list.

Definition at line 232 of file class.ilSearchResultPresentation.php.

232 : bool
233 {
234 $this->html = '';
235
236 $this->parseResultReferences();
237
238 $this->lng->loadLanguageModule("cntr"); // #16834
239
241
242 $set = array();
243 foreach ($this->getResults() as $c_ref_id => $obj_id) {
244 $c_ref_id = (int) $c_ref_id;
245 $obj_id = (int) $obj_id;
246 foreach ($this->getAllReferences($c_ref_id) as $ref_id) {
247 if (!$this->tree->isInTree($ref_id)) {
248 continue;
249 }
250
251 $obj_type = ilObject::_lookupType($obj_id);
252
253 $set[] = array(
254 "ref_id" => $ref_id,
255 "obj_id" => $obj_id,
256 "title" => $this->lookupTitle($obj_id, 0),
257 "title_sort" => ilObject::_lookupTitle((int) $obj_id),
258 "description" => $this->lookupDescription((int) $obj_id, 0),
259 "type" => $obj_type,
260 "relevance" => $this->getRelevance($obj_id),
261 "s_relevance" => sprintf("%03d", $this->getRelevance($obj_id)),
262 'create_date' => ilObject::_lookupCreationDate($obj_id)
263 );
264
265 $preloader->addItem($obj_id, $obj_type, $ref_id);
266 }
267 }
268
269 if (!count($set)) {
270 return false;
271 }
272
273 $preloader->preload();
274 unset($preloader);
275
276 $result_table = new ilSearchResultTableGUI($this->container, "showSavedResults", $this);
277 $result_table->setCustomPreviousNext($this->prev, $this->next);
278
279 $result_table->setDataAndApplySortation($set);
280 $this->thtml = $result_table->getHTML();
281 return true;
282 }
Preloader for object list GUIs.
static _lookupType(int $id, bool $reference=false)
static _lookupCreationDate(int $obj_id)
lookupTitle(int $a_obj_id, int $a_sub_id)
parseResultReferences()
Check if more than one reference is visible.
lookupDescription(int $a_obj_id, int $a_sub_id)
TableGUI class for search results.

References $ref_id, ilObject\_lookupCreationDate(), ilObject\_lookupTitle(), ilObject\_lookupType(), ilObjectListGUI\CONTEXT_SEARCH, getAllReferences(), getRelevance(), getResults(), ILIAS\Repository\html(), ILIAS\Repository\int(), ILIAS\Repository\lng(), lookupDescription(), lookupTitle(), ILIAS\User\Profile\ChangeMail\next, and parseResultReferences().

Referenced by render().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setPreviousNext()

ilSearchResultPresentation::setPreviousNext ( string  $a_p,
string  $a_n 
)

Set previous next.

Definition at line 222 of file class.ilSearchResultPresentation.php.

222 : void
223 {
224 $this->prev = $a_p;
225 $this->next = $a_n;
226 }

References ILIAS\User\Profile\ChangeMail\next.

◆ setResults()

ilSearchResultPresentation::setResults ( array  $a_result_data)

Set result array.

Definition at line 106 of file class.ilSearchResultPresentation.php.

106 : void
107 {
108 $this->results = $a_result_data;
109 }

◆ setSearcher()

ilSearchResultPresentation::setSearcher ( ilLuceneSearcher  $a_searcher)

set searcher

Definition at line 206 of file class.ilSearchResultPresentation.php.

206 : void
207 {
208 $this->searcher = $a_searcher;
209 }

◆ setSubitemIds()

ilSearchResultPresentation::setSubitemIds ( array  $a_subids)

Set subitem ids Used for like and fulltext search.

Parameters
array$a_subidsarray ($obj_id => array(page1_id,page2_id);
Returns
void

Definition at line 125 of file class.ilSearchResultPresentation.php.

125 : void
126 {
127 $this->subitem_ids = $a_subids;
128 }

Field Documentation

◆ $access

ilAccess ilSearchResultPresentation::$access
protected

Definition at line 42 of file class.ilSearchResultPresentation.php.

◆ $all_references

array ilSearchResultPresentation::$all_references = []
private

Definition at line 51 of file class.ilSearchResultPresentation.php.

◆ $container

object ilSearchResultPresentation::$container = null
private

Definition at line 53 of file class.ilSearchResultPresentation.php.

Referenced by __construct(), and getContainer().

◆ $ctrl

ilCtrl ilSearchResultPresentation::$ctrl
protected

Definition at line 41 of file class.ilSearchResultPresentation.php.

◆ $has_more_ref_ids

array ilSearchResultPresentation::$has_more_ref_ids = []
private

Definition at line 50 of file class.ilSearchResultPresentation.php.

◆ $html

string ilSearchResultPresentation::$html
protected

Definition at line 57 of file class.ilSearchResultPresentation.php.

◆ $http

GlobalHttpState ilSearchResultPresentation::$http
protected

Definition at line 44 of file class.ilSearchResultPresentation.php.

◆ $lng

ilLanguage ilSearchResultPresentation::$lng
protected

Definition at line 40 of file class.ilSearchResultPresentation.php.

◆ $mode

int ilSearchResultPresentation::$mode
protected

Definition at line 37 of file class.ilSearchResultPresentation.php.

Referenced by getMode().

◆ $next

string ilSearchResultPresentation::$next
protected

Definition at line 56 of file class.ilSearchResultPresentation.php.

◆ $prev

string ilSearchResultPresentation::$prev
protected

Definition at line 55 of file class.ilSearchResultPresentation.php.

◆ $refinery

Factory ilSearchResultPresentation::$refinery
protected

Definition at line 45 of file class.ilSearchResultPresentation.php.

◆ $results

array ilSearchResultPresentation::$results = []
private

Definition at line 48 of file class.ilSearchResultPresentation.php.

Referenced by getResults().

◆ $searcher

ilLuceneSearcher ilSearchResultPresentation::$searcher = null
private

Definition at line 52 of file class.ilSearchResultPresentation.php.

◆ $subitem_ids

array ilSearchResultPresentation::$subitem_ids = []
private

Definition at line 49 of file class.ilSearchResultPresentation.php.

Referenced by getSubitemIds().

◆ $thtml

string ilSearchResultPresentation::$thtml
protected

Definition at line 58 of file class.ilSearchResultPresentation.php.

Referenced by getHTML().

◆ $tpl

ilGlobalTemplateInterface ilSearchResultPresentation::$tpl
protected

Definition at line 39 of file class.ilSearchResultPresentation.php.

◆ $tree

ilTree ilSearchResultPresentation::$tree
protected

Definition at line 43 of file class.ilSearchResultPresentation.php.

◆ MODE_LUCENE

const ilSearchResultPresentation::MODE_LUCENE = 1

Definition at line 34 of file class.ilSearchResultPresentation.php.

◆ MODE_STANDARD

const ilSearchResultPresentation::MODE_STANDARD = 2

The documentation for this class was generated from the following file: