ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilSearchResult Class Reference
+ Collaboration diagram for ilSearchResult:

Public Member Functions

 __construct ($a_user_id=0)
 Constructor @access public. More...
 
 setRequiredPermission ($a_permission)
 Set the required permission for the rbac checks in function 'filter()'. More...
 
 getRequiredPermission ()
 
 setUserId ($a_user_id)
 
 getUserId ()
 
 getEntries ()
 
 isLimitReached ()
 
 setMaxHits ($a_max_hits)
 
 getMaxHits ()
 
 isOffsetReached ($a_counter)
 Check if offset is reached. More...
 
 addEntry ($a_obj_id, $a_type, $found, $a_child_id=0)
 add search result entry Entries are stored with 'obj_id'. More...
 
 numEntries ()
 Check number of entries @access public. More...
 
 mergeEntries (&$result_obj)
 merge entries of this instance and another result object More...
 
 diffEntriesFromResult (&$result_obj)
 diff entries of this instance and another result object Used for search in results More...
 
 intersectEntries (&$result_obj)
 Build intersection of entries (all entries that are present in both result sets) More...
 
 addResult ($a_ref_id, $a_obj_id, $a_type)
 add search result Results are stored with 'ref_id'. More...
 
 getResults ()
 
 getResultIds ()
 get result ids More...
 
 getResultsByObjId ()
 
 getUniqueResults ()
 Get unique results. More...
 
 getResultsForPresentation ()
 
 getSubitemIds ()
 
 filter ($a_root_node, $check_and)
 Filter search result. More...
 
 filterResults ($a_root_node)
 Filter search area of result set @access public. More...
 
 save ($a_type=DEFAULT_SEARCH)
 Save search results. More...
 
 read ($a_type=DEFAULT_SEARCH)
 read search results More...
 
 __updateEntryChilds ($a_obj_id, $a_childs)
 Update childs for a specific entry. More...
 
 __updateResultChilds ($a_ref_id, $a_childs)
 Update childs for a specific result. More...
 
 __initSearchSettingsObject ()
 
 preventOverwritingMaxhits ($a_flag=null)
 If you call this function and pass "true" the maxhits setting will not be overwritten in __initSearchSettingsObject() More...
 
 addObserver (&$a_class, $a_method)
 The observer is used to call functions for filtering result. More...
 
 callListeners ($a_ref_id, &$a_data)
 

Data Fields

 $permission = 'visible'
 
 $user_id
 
 $entries = array()
 
 $results = array()
 
 $observers = array()
 
 $ilias
 
 $ilAccess
 
 $limit_reached = false
 
 $result
 

Protected Member Functions

 initUserSearchCache ()
 Init user search cache. More...
 

Protected Attributes

 $search_cache = null
 
 $offset = 0
 
 $preventOverwritingMaxhits = false
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilSearchResult::__construct (   $a_user_id = 0)

Constructor @access public.

Definition at line 66 of file class.ilSearchResult.php.

67 {
69
70 $this->ilAccess = $ilAccess;
71 if ($a_user_id) {
72 $this->user_id = $a_user_id;
73 } else {
74 $this->user_id = $ilUser->getId();
75 }
77 $this->initUserSearchCache();
78
79 $this->db = $ilDB;
80 }
Class ilAccessHandler.
initUserSearchCache()
Init user search cache.
global $ilDB
$ilUser
Definition: imgupload.php:18

References $ilAccess, $ilDB, $ilias, $ilUser, __initSearchSettingsObject(), and initUserSearchCache().

+ Here is the call graph for this function:

Member Function Documentation

◆ __initSearchSettingsObject()

ilSearchResult::__initSearchSettingsObject ( )

Definition at line 523 of file class.ilSearchResult.php.

524 {
525 include_once 'Services/Search/classes/class.ilSearchSettings.php';
526
527 $this->search_settings = new ilSearchSettings();
528 if (!$this->preventOverwritingMaxhits()) {
529 $this->setMaxHits($this->search_settings->getMaxHits());
530 }
531 }
preventOverwritingMaxhits($a_flag=null)
If you call this function and pass "true" the maxhits setting will not be overwritten in __initSearch...

References preventOverwritingMaxhits(), and setMaxHits().

Referenced by __construct().

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

◆ __updateEntryChilds()

ilSearchResult::__updateEntryChilds (   $a_obj_id,
  $a_childs 
)

Update childs for a specific entry.

Parameters
integerobject object_id
arrayarray of child ids. E.g 'pg', 'st' @access private

Definition at line 491 of file class.ilSearchResult.php.

492 {
493 if ($this->entries[$a_obj_id] and is_array($a_childs)) {
494 foreach ($a_childs as $child_id) {
495 if ($child_id) {
496 $this->entries[$a_obj_id]['child'][$child_id] = $child_id;
497 }
498 }
499 return true;
500 }
501 return false;
502 }

Referenced by diffEntriesFromResult(), intersectEntries(), and mergeEntries().

+ Here is the caller graph for this function:

◆ __updateResultChilds()

ilSearchResult::__updateResultChilds (   $a_ref_id,
  $a_childs 
)

Update childs for a specific result.

Parameters
integerobject ref_id
arrayarray of child ids. E.g 'pg', 'st' @access private

Definition at line 510 of file class.ilSearchResult.php.

511 {
512 if ($this->results[$a_ref_id] and is_array($a_childs)) {
513 foreach ($a_childs as $child_id) {
514 $this->results[$a_ref_id]['child'][$child_id] = $child_id;
515 }
516 return true;
517 }
518 return false;
519 }

Referenced by filter(), and filterResults().

+ Here is the caller graph for this function:

◆ addEntry()

ilSearchResult::addEntry (   $a_obj_id,
  $a_type,
  $found,
  $a_child_id = 0 
)

add search result entry Entries are stored with 'obj_id'.

This method is typically called to store db query results.

Parameters
integerobject object_id
stringobj_type 'lm' or 'crs' ...
arrayvalue position of query parser words in query string
integerchild id e.g id of page or chapter @access public

Definition at line 146 of file class.ilSearchResult.php.

147 {
148 // Create new entry if it not exists
149 if (!$this->entries[$a_obj_id]) {
150 $this->entries[$a_obj_id]['obj_id'] = $a_obj_id;
151 $this->entries[$a_obj_id]['type'] = $a_type;
152 $this->entries[$a_obj_id]['found'] = $found;
153 $this->entries[$a_obj_id]['child'] = [];
154
155 if ($a_child_id and $a_child_id != $a_obj_id) {
156 $this->entries[$a_obj_id]['child'][$a_child_id] = $a_child_id;
157 }
158 } else {
159 // replace or add child ('pg','st') id
160 if ($a_child_id and $a_child_id != $a_obj_id) {
161 $this->entries[$a_obj_id]['child'][$a_child_id] = $a_child_id;
162 }
163
164 // UPDATE FOUND
165 $counter = 0;
166 foreach ($found as $position) {
167 if ($position) {
168 $this->entries[$a_obj_id]['found'][$counter] = $position;
169 }
170 $counter++;
171 }
172 }
173 return true;
174 }
$counter
$a_type
Definition: workflow.php:92

References $a_type, and $counter.

Referenced by diffEntriesFromResult(), intersectEntries(), and mergeEntries().

+ Here is the caller graph for this function:

◆ addObserver()

ilSearchResult::addObserver ( $a_class,
  $a_method 
)

The observer is used to call functions for filtering result.

Every callback function should support the following parameters: array of ids. E.g: ref_id = 5,array(obj_id = 1,type = 'crs'), The function should return true or false.

Parameters
objectclass of callback function
stringname of callback method @access public

Definition at line 575 of file class.ilSearchResult.php.

576 {
577 $this->observers[] = array('class' => $a_class,
578 'method' => $a_method);
579 return true;
580 }

◆ addResult()

ilSearchResult::addResult (   $a_ref_id,
  $a_obj_id,
  $a_type 
)

add search result Results are stored with 'ref_id'.

This method is typically called after checking access of entries.

Parameters
integerref_id
integerobj_id
stringobj_type 'lm' or 'crs' ... @access public

Definition at line 267 of file class.ilSearchResult.php.

268 {
269 $this->results[$a_ref_id]['ref_id'] = $a_ref_id;
270 $this->results[$a_ref_id]['obj_id'] = $a_obj_id;
271 $this->results[$a_ref_id]['type'] = $a_type;
272 }

References $a_type.

Referenced by filter(), and filterResults().

+ Here is the caller graph for this function:

◆ callListeners()

ilSearchResult::callListeners (   $a_ref_id,
$a_data 
)

Definition at line 581 of file class.ilSearchResult.php.

582 {
583 foreach ($this->observers as $observer) {
584 $class =&$observer['class'];
585 $method = $observer['method'];
586
587 if (!$class->$method($a_ref_id, $a_data)) {
588 return false;
589 }
590 }
591 return true;
592 }

Referenced by filter().

+ Here is the caller graph for this function:

◆ diffEntriesFromResult()

ilSearchResult::diffEntriesFromResult ( $result_obj)

diff entries of this instance and another result object Used for search in results

Parameters
objectresult_obj @access public

Definition at line 208 of file class.ilSearchResult.php.

209 {
210 $new_entries = $this->getEntries();
211 $this->entries = array();
212
213 // Get all checked objects
214 foreach ($this->search_cache->getCheckedItems() as $ref_id => $obj_id) {
215 if (isset($new_entries[$obj_id])) {
216 $this->addEntry(
217 $new_entries[$obj_id]['obj_id'],
218 $new_entries[$obj_id]['type'],
219 $new_entries[$obj_id]['found']
220 );
221 $this->__updateEntryChilds(
222 $new_entries[$obj_id]['obj_id'],
223 $new_entries[$obj_id]['child']
224 );
225 }
226 }
227 }
addEntry($a_obj_id, $a_type, $found, $a_child_id=0)
add search result entry Entries are stored with 'obj_id'.
__updateEntryChilds($a_obj_id, $a_childs)
Update childs for a specific entry.

References __updateEntryChilds(), addEntry(), and getEntries().

+ Here is the call graph for this function:

◆ filter()

ilSearchResult::filter (   $a_root_node,
  $check_and 
)

Filter search result.

Do RBAC checks.

Allows paging of results for referenced objects

@access public

Parameters
introot node id
boolcheck and boolean search
Returns
bool success status

Definition at line 355 of file class.ilSearchResult.php.

356 {
357 global $tree;
358
359 // get ref_ids and check access
360 $counter = 0;
361 $offset_counter = 0;
362 foreach ($this->getEntries() as $entry) {
363 // boolean and failed continue
364 if ($check_and and in_array(0, $entry['found'])) {
365 continue;
366 }
367 // Types like role, rolt, user do not need rbac checks
368 $type = ilObject::_lookupType($entry['obj_id']);
369 if ($type == 'rolt' or $type == 'usr' or $type == 'role') {
370 if ($this->callListeners($entry['obj_id'], $entry)) {
371 $this->addResult($entry['obj_id'], $entry['obj_id'], $type);
372 if (is_array($entry['child'])) {
373 $counter += count($entry['child']);
374 }
375 // Stop if maximum of hits is reached
376 if (++$counter > $this->getMaxHits()) {
377 $this->limit_reached = true;
378 return true;
379 }
380 }
381 continue;
382 }
383 // Check referenced objects
384 foreach (ilObject::_getAllReferences($entry['obj_id']) as $ref_id) {
385 // Failed check: if ref id check is failed by previous search
386 if ($this->search_cache->isFailed($ref_id)) {
387 continue;
388 }
389 // Offset check
390 if ($this->search_cache->isChecked($ref_id) and !$this->isOffsetReached($offset_counter)) {
391 ++$offset_counter;
392 continue;
393 }
394
395 if (!$this->callListeners($ref_id, $entry)) {
396 continue;
397 }
398
399
400
401 // RBAC check
402 $type = ilObject::_lookupType($ref_id, true);
403 if ($this->ilAccess->checkAccessOfUser(
404 $this->getUserId(),
405 $this->getRequiredPermission(),
406 '',
407 $ref_id,
408 $type,
409 $entry['obj_id']
410 )) {
411 if ($a_root_node == ROOT_FOLDER_ID or $tree->isGrandChild($a_root_node, $ref_id)) {
412 // Call listeners
413 #if($this->callListeners($ref_id,$entry))
414 if (1) {
415 $this->addResult($ref_id, $entry['obj_id'], $type);
416 $this->search_cache->appendToChecked($ref_id, $entry['obj_id']);
417 $this->__updateResultChilds($ref_id, $entry['child']);
418
419 $counter++;
420 $offset_counter++;
421 // Stop if maximum of hits is reached
422
423 if ($counter >= $this->getMaxHits()) {
424 $this->limit_reached = true;
425 $this->search_cache->setResults($this->results);
426 return true;
427 }
428 }
429 }
430 continue;
431 }
432 $this->search_cache->appendToFailed($ref_id);
433 }
434 }
435 $this->search_cache->setResults($this->results);
436 return false;
437 }
checkAccessOfUser($a_user_id, $a_permission, $a_cmd, $a_ref_id, $a_type="", $a_obj_id="", $a_tree_id="")
check access for an object (provide $a_type and $a_obj_id if available for better performance)
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
callListeners($a_ref_id, &$a_data)
addResult($a_ref_id, $a_obj_id, $a_type)
add search result Results are stored with 'ref_id'.
__updateResultChilds($a_ref_id, $a_childs)
Update childs for a specific result.
$type

References $counter, $type, __updateResultChilds(), ilObject\_getAllReferences(), ilObject\_lookupType(), addResult(), callListeners(), ilAccess\checkAccessOfUser(), getEntries(), and getMaxHits().

+ Here is the call graph for this function:

◆ filterResults()

ilSearchResult::filterResults (   $a_root_node)

Filter search area of result set @access public.

Definition at line 444 of file class.ilSearchResult.php.

445 {
446 global $tree;
447
448 $tmp_results = $this->getResults();
449 $this->results = array();
450 foreach ($tmp_results as $result) {
451 if ($tree->isGrandChild($a_root_node, $result['ref_id']) and $tree->isInTree($result['ref_id'])) {
452 $this->addResult($result['ref_id'], $result['obj_id'], $result['type']);
453 $this->__updateResultChilds($result['ref_id'], $result['child']);
454 }
455 }
456
457 return true;
458 }

References $result, __updateResultChilds(), addResult(), and getResults().

+ Here is the call graph for this function:

◆ getEntries()

ilSearchResult::getEntries ( )

Definition at line 105 of file class.ilSearchResult.php.

106 {
107 return $this->entries ? $this->entries : array();
108 }

Referenced by diffEntriesFromResult(), filter(), intersectEntries(), and numEntries().

+ Here is the caller graph for this function:

◆ getMaxHits()

ilSearchResult::getMaxHits ( )

Definition at line 119 of file class.ilSearchResult.php.

120 {
121 return $this->max_hits;
122 }

Referenced by filter(), and initUserSearchCache().

+ Here is the caller graph for this function:

◆ getRequiredPermission()

ilSearchResult::getRequiredPermission ( )

Definition at line 90 of file class.ilSearchResult.php.

91 {
92 return $this->permission;
93 }

References $permission.

◆ getResultIds()

ilSearchResult::getResultIds ( )

get result ids

@access public

Returns
array result ids

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

286 {
287 foreach ($this->getResults() as $id => $tmp) {
288 $ids[] = $id;
289 }
290 return $ids ? $ids : array();
291 }
if(!array_key_exists('StateId', $_REQUEST)) $id

References $id, and getResults().

+ Here is the call graph for this function:

◆ getResults()

ilSearchResult::getResults ( )

Definition at line 274 of file class.ilSearchResult.php.

275 {
276 return $this->results ? $this->results : array();
277 }

Referenced by filterResults(), getResultIds(), getResultsByObjId(), getResultsForPresentation(), and getSubitemIds().

+ Here is the caller graph for this function:

◆ getResultsByObjId()

ilSearchResult::getResultsByObjId ( )

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

294 {
295 $tmp_res = array();
296 foreach ($this->getResults() as $ref_id => $res_data) {
297 $tmp_res[$res_data['obj_id']][] = $ref_id;
298 }
299 return $tmp_res ? $tmp_res : array();
300 }

References getResults().

+ Here is the call graph for this function:

◆ getResultsForPresentation()

ilSearchResult::getResultsForPresentation ( )

Definition at line 322 of file class.ilSearchResult.php.

323 {
324 $res = array();
325
326 foreach ($this->getResults() as $result) {
327 $res[$result['ref_id']] = $result['obj_id'];
328 }
329 return $res;
330 }
foreach($_POST as $key=> $value) $res

References $res, $result, and getResults().

+ Here is the call graph for this function:

◆ getSubitemIds()

ilSearchResult::getSubitemIds ( )

Definition at line 332 of file class.ilSearchResult.php.

333 {
334 $res = array();
335 foreach ($this->getResults() as $row) {
336 $res[$row['obj_id']] = $row['child'];
337 }
338 return $res ? $res : array();
339 }

References $res, $row, and getResults().

+ Here is the call graph for this function:

◆ getUniqueResults()

ilSearchResult::getUniqueResults ( )

Get unique results.

Return an array of obj_id (No multiple results for references) Results are stored with 'ref_id'. This method is typically called after checking access of entries. @access public

Definition at line 309 of file class.ilSearchResult.php.

310 {
311 $obj_ids = array();
312 foreach ($this->results as $result) {
313 if (in_array($result['obj_id'], $obj_ids)) {
314 continue;
315 }
316 $obj_ids[] = $result['obj_id'];
317 $objects[] = $result;
318 }
319 return $objects ? $objects : array();
320 }

References $result.

◆ getUserId()

ilSearchResult::getUserId ( )

Definition at line 100 of file class.ilSearchResult.php.

101 {
102 return $this->user_id;
103 }

References $user_id.

Referenced by initUserSearchCache().

+ Here is the caller graph for this function:

◆ initUserSearchCache()

ilSearchResult::initUserSearchCache ( )
protected

Init user search cache.

@access private

Definition at line 539 of file class.ilSearchResult.php.

540 {
541 include_once('Services/Search/classes/class.ilUserSearchCache.php');
542 $this->search_cache = ilUserSearchCache::_getInstance($this->getUserId());
543 $this->offset = $this->getMaxHits() * ($this->search_cache->getResultPageNumber() - 1) ;
544 }
static _getInstance($a_usr_id)
Get singleton instance.

References ilUserSearchCache\_getInstance(), getMaxHits(), and getUserId().

Referenced by __construct().

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

◆ intersectEntries()

ilSearchResult::intersectEntries ( $result_obj)

Build intersection of entries (all entries that are present in both result sets)

Parameters
objectresult_obj @access public

Definition at line 235 of file class.ilSearchResult.php.

236 {
237 $new_entries = $this->getEntries();
238 $this->entries = array();
239
240 foreach ($result_obj->getEntries() as $entry) {
241 $obj_id = $entry['obj_id'];
242 if (isset($new_entries[$obj_id])) {
243 $this->addEntry(
244 $new_entries[$obj_id]['obj_id'],
245 $new_entries[$obj_id]['type'],
246 $new_entries[$obj_id]['found']
247 );
248
249 $this->__updateEntryChilds(
250 $new_entries[$obj_id]['obj_id'],
251 $new_entries[$obj_id]['child']
252 );
253 }
254 }
255 }

References __updateEntryChilds(), addEntry(), and getEntries().

+ Here is the call graph for this function:

◆ isLimitReached()

ilSearchResult::isLimitReached ( )

Definition at line 110 of file class.ilSearchResult.php.

111 {
112 return $this->limit_reached ? true : false;
113 }

◆ isOffsetReached()

ilSearchResult::isOffsetReached (   $a_counter)

Check if offset is reached.

@access public

Parameters
intcurrent counter of result
Returns
bool reached or not

Definition at line 131 of file class.ilSearchResult.php.

132 {
133 return ($a_counter < $this->offset) ? false : true;
134 }

◆ mergeEntries()

ilSearchResult::mergeEntries ( $result_obj)

merge entries of this instance and another result object

Parameters
objectresult_obj @access public

Definition at line 192 of file class.ilSearchResult.php.

193 {
194 foreach ($result_obj->getEntries() as $entry) {
195 $this->addEntry($entry['obj_id'], $entry['type'], $entry['found']);
196 $this->__updateEntryChilds($entry['obj_id'], $entry['child']);
197 }
198 return true;
199 }

References __updateEntryChilds(), and addEntry().

+ Here is the call graph for this function:

◆ numEntries()

ilSearchResult::numEntries ( )

Check number of entries @access public.

Definition at line 181 of file class.ilSearchResult.php.

182 {
183 return count($this->getEntries());
184 }

References getEntries().

+ Here is the call graph for this function:

◆ preventOverwritingMaxhits()

ilSearchResult::preventOverwritingMaxhits (   $a_flag = null)

If you call this function and pass "true" the maxhits setting will not be overwritten in __initSearchSettingsObject()

@access public

Parameters
boolean$a_flagtrue or false to set the flag or leave blank to get the status of the flag @returmn boolean if called without parameter the status of the flag will be returned, otherwise $this

Definition at line 555 of file class.ilSearchResult.php.

556 {
557 if (null === $a_flag) {
559 }
560
561 $this->preventOverwritingMaxhits = $a_flag;
562
563 return $this;
564 }

References $preventOverwritingMaxhits, and preventOverwritingMaxhits().

Referenced by __initSearchSettingsObject(), and preventOverwritingMaxhits().

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

◆ read()

ilSearchResult::read (   $a_type = DEFAULT_SEARCH)

read search results

Parameters
integerDEFAULT_SEARCH or ADVANCED_SEARCH @access public

Definition at line 478 of file class.ilSearchResult.php.

479 {
480 $this->results = $this->search_cache->getResults();
481 }

◆ save()

ilSearchResult::save (   $a_type = DEFAULT_SEARCH)

Save search results.

Parameters
integerDEFAULT_SEARCH or ADVANCED_SEARCH @access public

Definition at line 467 of file class.ilSearchResult.php.

468 {
469 $this->search_cache->save();
470 return false;
471 }

◆ setMaxHits()

ilSearchResult::setMaxHits (   $a_max_hits)

Definition at line 115 of file class.ilSearchResult.php.

116 {
117 $this->max_hits = $a_max_hits;
118 }

Referenced by __initSearchSettingsObject().

+ Here is the caller graph for this function:

◆ setRequiredPermission()

ilSearchResult::setRequiredPermission (   $a_permission)

Set the required permission for the rbac checks in function 'filter()'.

Definition at line 85 of file class.ilSearchResult.php.

86 {
87 $this->permission = $a_permission;
88 }

◆ setUserId()

ilSearchResult::setUserId (   $a_user_id)

Definition at line 96 of file class.ilSearchResult.php.

97 {
98 $this->user_id = $a_user_id;
99 }

Field Documentation

◆ $entries

ilSearchResult::$entries = array()

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

◆ $ilAccess

ilSearchResult::$ilAccess

Definition at line 54 of file class.ilSearchResult.php.

Referenced by __construct().

◆ $ilias

ilSearchResult::$ilias

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

Referenced by __construct().

◆ $limit_reached

ilSearchResult::$limit_reached = false

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

◆ $observers

ilSearchResult::$observers = array()

Definition at line 47 of file class.ilSearchResult.php.

◆ $offset

ilSearchResult::$offset = 0
protected

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

◆ $permission

ilSearchResult::$permission = 'visible'

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

Referenced by getRequiredPermission().

◆ $preventOverwritingMaxhits

ilSearchResult::$preventOverwritingMaxhits = false
protected

Definition at line 60 of file class.ilSearchResult.php.

Referenced by preventOverwritingMaxhits().

◆ $result

ilSearchResult::$result

◆ $results

ilSearchResult::$results = array()

Definition at line 46 of file class.ilSearchResult.php.

◆ $search_cache

ilSearchResult::$search_cache = null
protected

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

◆ $user_id

ilSearchResult::$user_id

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

Referenced by getUserId().


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