ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilSearchResult Class Reference
+ Inheritance diagram for ilSearchResult:
+ Collaboration diagram for ilSearchResult:

Public Member Functions

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

Protected Attributes

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

Detailed Description

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

Member Function Documentation

ilSearchResult::__initSearchSettingsObject ( )

Reimplemented in ilShopSearchResult.

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

References preventOverwritingMaxhits(), and setMaxHits().

Referenced by ilSearchResult().

{
include_once 'Services/Search/classes/class.ilSearchSettings.php';
$this->search_settings = new ilSearchSettings();
$this->setMaxHits($this->search_settings->getMaxHits());
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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' private

Reimplemented in ilShopSearchResult.

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

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

{
if($this->entries[$a_obj_id] and is_array($a_childs))
{
foreach($a_childs as $child_id)
{
if($child_id)
{
$this->entries[$a_obj_id]['child'][$child_id] = $child_id;
}
}
return true;
}
return false;
}

+ Here is the caller graph for this function:

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' private

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

Referenced by ilShopSearchResult\filter(), filter(), and filterResults().

{
if($this->results[$a_ref_id] and is_array($a_childs))
{
foreach($a_childs as $child_id)
{
$this->results[$a_ref_id]['child'][$child_id] = $child_id;
}
return true;
}
return false;
}

+ Here is the caller graph for this function:

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 public

Reimplemented in ilShopSearchResult.

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

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

{
// Create new entry if it not exists
if(!$this->entries[$a_obj_id])
{
$this->entries[$a_obj_id]['obj_id'] = $a_obj_id;
$this->entries[$a_obj_id]['type'] = $a_type;
$this->entries[$a_obj_id]['found'] = $found;
if($a_child_id and $a_child_id != $a_obj_id)
{
$this->entries[$a_obj_id]['child'][$a_child_id] = $a_child_id;
}
}
else
{
// replace or add child ('pg','st') id
if($a_child_id and $a_child_id != $a_obj_id)
{
$this->entries[$a_obj_id]['child'][$a_child_id] = $a_child_id;
}
// UPDATE FOUND
$counter = 0;
foreach($found as $position)
{
if($position)
{
$this->entries[$a_obj_id]['found'][$counter] = $position;
}
$counter++;
}
}
return true;
}

+ Here is the caller graph for this function:

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 public

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

{
$this->observers[] = array('class' => $a_class,
'method' => $a_method);
return true;
}
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' ... public

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

Referenced by ilShopSearchResult\filter(), filter(), and filterResults().

{
$this->results[$a_ref_id]['ref_id'] = $a_ref_id;
$this->results[$a_ref_id]['obj_id'] = $a_obj_id;
$this->results[$a_ref_id]['type'] = $a_type;
}

+ Here is the caller graph for this function:

ilSearchResult::callListeners (   $a_ref_id,
$a_data 
)

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

Referenced by ilShopSearchResult\filter(), and filter().

{
foreach($this->observers as $observer)
{
$class =& $observer['class'];
$method = $observer['method'];
if(!$class->$method($a_ref_id,$a_data))
{
return false;
}
}
return true;
}

+ Here is the caller graph for this function:

ilSearchResult::diffEntriesFromResult ( $result_obj)

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

Parameters
objectresult_obj public

Reimplemented in ilShopSearchResult.

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

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

{
$new_entries = $this->getEntries();
$this->entries = array();
// Get all checked objects
foreach($this->search_cache->getCheckedItems() as $ref_id => $obj_id)
{
if(isset($new_entries[$obj_id]))
{
$this->addEntry($new_entries[$obj_id]['obj_id'],
$new_entries[$obj_id]['type'],
$new_entries[$obj_id]['found']);
$this->__updateEntryChilds($new_entries[$obj_id]['obj_id'],
$new_entries[$obj_id]['child']);
}
}
}

+ Here is the call graph for this function:

ilSearchResult::filter (   $a_root_node,
  $check_and 
)

Filter search result.

Do RBAC checks.

Allows paging of results for referenced objects

public

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

Reimplemented in ilShopSearchResult.

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

References $ref_id, __updateResultChilds(), ilObject\_getAllReferences(), ilObject\_lookupType(), addResult(), callListeners(), getEntries(), getMaxHits(), getRequiredPermission(), and isOffsetReached().

{
global $tree;
// get ref_ids and check access
$counter = 0;
$offset_counter = 0;
foreach($this->getEntries() as $entry)
{
// boolean and failed continue
if($check_and and in_array(0,$entry['found']))
{
continue;
}
// Types like role, rolt, user do not need rbac checks
$type = ilObject::_lookupType($entry['obj_id']);
if($type == 'rolt' or $type == 'usr' or $type == 'role')
{
if($this->callListeners($entry['obj_id'],$entry))
{
$this->addResult($entry['obj_id'],$entry['obj_id'],$type);
$counter += count($entry['child']);
// Stop if maximum of hits is reached
if(++$counter > $this->getMaxHits())
{
$this->limit_reached = true;
return true;
}
}
continue;
}
// Check referenced objects
foreach(ilObject::_getAllReferences($entry['obj_id']) as $ref_id)
{
// Failed check: if ref id check is failed by previous search
if($this->search_cache->isFailed($ref_id))
{
continue;
}
// Offset check
if($this->search_cache->isChecked($ref_id) and !$this->isOffsetReached($offset_counter))
{
++$offset_counter;
continue;
}
if(!$this->callListeners($ref_id, $entry))
{
continue;
}
// RBAC check
$type = ilObject::_lookupType($ref_id, true);
if($this->ilAccess->checkAccessOfUser($this->getUserId(),
'',
$type,
$entry['obj_id']))
{
if($a_root_node == ROOT_FOLDER_ID or $tree->isGrandChild($a_root_node,$ref_id))
{
// Call listeners
#if($this->callListeners($ref_id,$entry))
if(1)
{
$this->addResult($ref_id,$entry['obj_id'],$type);
$this->search_cache->appendToChecked($ref_id,$entry['obj_id']);
$this->__updateResultChilds($ref_id,$entry['child']);
$counter++;
$offset_counter++;
// Stop if maximum of hits is reached
if($counter >= $this->getMaxHits())
{
$this->limit_reached = true;
$this->search_cache->setResults($this->results);
return true;
}
}
}
continue;
}
$this->search_cache->appendToFailed($ref_id);
}
}
$this->search_cache->setResults($this->results);
return false;
}

+ Here is the call graph for this function:

ilSearchResult::filterResults (   $a_root_node)

Filter search area of result set public.

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

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

{
global $tree;
$tmp_results = $this->getResults();
$this->results = array();
foreach($tmp_results as $result)
{
if($tree->isGrandChild($a_root_node,$result['ref_id']) and $tree->isInTree($result['ref_id']))
{
$this->addResult($result['ref_id'],$result['obj_id'],$result['type']);
$this->__updateResultChilds($result['ref_id'],$result['child']);
}
}
return true;
}

+ Here is the call graph for this function:

ilSearchResult::getEntries ( )

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

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

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

+ Here is the caller graph for this function:

ilSearchResult::getMaxHits ( )

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

Referenced by filter(), ilShopSearchResult\getResultsForPresentation(), and initUserSearchCache().

{
return $this->max_hits;
}

+ Here is the caller graph for this function:

ilSearchResult::getRequiredPermission ( )

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

References $permission.

Referenced by ilShopSearchResult\filter(), and filter().

{
}

+ Here is the caller graph for this function:

ilSearchResult::getResultIds ( )

get result ids

public

Returns
array result ids

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

References getResults().

{
foreach($this->getResults() as $id => $tmp)
{
$ids[] = $id;
}
return $ids ? $ids : array();
}

+ Here is the call graph for this function:

ilSearchResult::getResults ( )

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

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

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

+ Here is the caller graph for this function:

ilSearchResult::getResultsByObjId ( )

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

References $ref_id, and getResults().

{
$tmp_res = array();
foreach($this->getResults() as $ref_id => $res_data)
{
$tmp_res[$res_data['obj_id']][] = $ref_id;
}
return $tmp_res ? $tmp_res : array();
}

+ Here is the call graph for this function:

ilSearchResult::getResultsForPresentation ( )

Reimplemented in ilShopSearchResult.

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

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

{
$res = array();
foreach($this->getResults() as $result)
{
$res[$result['ref_id']] = $result['obj_id'];
}
return $res;
}

+ Here is the call graph for this function:

ilSearchResult::getSubitemIds ( )

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

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

{
$res = array();
foreach($this->getResults() as $row)
{
$res[$row['obj_id']] = $row['child'];
}
return $res ? $res : array();
}

+ Here is the call graph for this function:

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. public

Reimplemented in ilShopSearchResult.

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

References $result.

{
$obj_ids = array();
foreach($this->results as $result)
{
if(in_array($result['obj_id'],$obj_ids))
{
continue;
}
$obj_ids[] = $result['obj_id'];
$objects[] = $result;
}
return $objects ? $objects : array();
}
ilSearchResult::getUserId ( )

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

References $user_id.

Referenced by initUserSearchCache().

{
}

+ Here is the caller graph for this function:

ilSearchResult::ilSearchResult (   $a_user_id = 0)

Constructor public.

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

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

{
global $ilias,$ilAccess,$ilDB,$ilUser;
$this->ilAccess =& $ilAccess;
if($a_user_id)
{
$this->user_id = $a_user_id;
}
else
{
$this->user_id = $ilUser->getId();
}
$this->db =& $ilDB;
}

+ Here is the call graph for this function:

ilSearchResult::initUserSearchCache ( )
protected

Init user search cache.

private

Reimplemented in ilShopSearchResult.

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

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

Referenced by ilSearchResult().

{
include_once('Services/Search/classes/class.ilUserSearchCache.php');
$this->search_cache = ilUserSearchCache::_getInstance($this->getUserId());
$this->offset = $this->getMaxHits() * ($this->search_cache->getResultPageNumber() - 1) ;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilSearchResult::intersectEntries ( $result_obj)

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

Parameters
objectresult_obj public

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

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

{
$new_entries = $this->getEntries();
$this->entries = array();
foreach($result_obj->getEntries() as $entry)
{
$obj_id = $entry['obj_id'];
if(isset($new_entries[$obj_id]))
{
$this->addEntry($new_entries[$obj_id]['obj_id'],
$new_entries[$obj_id]['type'],
$new_entries[$obj_id]['found']);
$this->__updateEntryChilds($new_entries[$obj_id]['obj_id'],
$new_entries[$obj_id]['child']);
}
}
}

+ Here is the call graph for this function:

ilSearchResult::isLimitReached ( )

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

{
return $this->limit_reached ? true : false;
}
ilSearchResult::isOffsetReached (   $a_counter)

Check if offset is reached.

public

Parameters
intcurrent counter of result
Returns
bool reached or not

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

Referenced by filter().

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

+ Here is the caller graph for this function:

ilSearchResult::mergeEntries ( $result_obj)

merge entries of this instance and another result object

Parameters
objectresult_obj public

Reimplemented in ilShopSearchResult.

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

References __updateEntryChilds(), and addEntry().

{
foreach($result_obj->getEntries() as $entry)
{
$this->addEntry($entry['obj_id'],$entry['type'],$entry['found']);
$this->__updateEntryChilds($entry['obj_id'],$entry['child']);
}
return true;
}

+ Here is the call graph for this function:

ilSearchResult::numEntries ( )

Check number of entries public.

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

References getEntries().

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

+ Here is the call graph for this function:

ilSearchResult::preventOverwritingMaxhits (   $a_flag = null)

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

public

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

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

References $preventOverwritingMaxhits.

Referenced by __initSearchSettingsObject().

{
if(null === $a_flag)
{
}
$this->preventOverwritingMaxhits = $a_flag;
return $this;
}

+ Here is the caller graph for this function:

ilSearchResult::read (   $a_type = DEFAULT_SEARCH)

read search results

Parameters
integerDEFAULT_SEARCH or ADVANCED_SEARCH public

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

Referenced by ilAdvancedSearchGUI\performAdvMDSearch(), ilAdvancedSearchGUI\performSearch(), ilSearchGUI\performSearch(), ilAdvancedSearchGUI\showSavedAdvMDResults(), ilSearchGUI\showSavedResults(), and ilAdvancedSearchGUI\showSavedResults().

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

+ Here is the caller graph for this function:

ilSearchResult::save (   $a_type = DEFAULT_SEARCH)

Save search results.

Parameters
integerDEFAULT_SEARCH or ADVANCED_SEARCH public

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

{
$this->search_cache->save();
return false;
}
ilSearchResult::setMaxHits (   $a_max_hits)

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

Referenced by ilShopSearchResult\__initSearchSettingsObject(), and __initSearchSettingsObject().

{
$this->max_hits = $a_max_hits;
}

+ Here is the caller graph for this function:

ilSearchResult::setRequiredPermission (   $a_permission)

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

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

{
$this->permission = $a_permission;
}
ilSearchResult::setUserId (   $a_user_id)

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

{
$this->user_id = $a_user_id;
}

Field Documentation

ilSearchResult::$entries = array()

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

ilSearchResult::$ilAccess

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

Referenced by ilSearchResult().

ilSearchResult::$ilias

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

Referenced by ilSearchResult().

ilSearchResult::$limit_reached = false

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

ilSearchResult::$observers = array()

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

ilSearchResult::$offset = 0
protected

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

ilSearchResult::$permission = 'visible'

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

Referenced by getRequiredPermission().

ilSearchResult::$preventOverwritingMaxhits = false
protected

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

Referenced by preventOverwritingMaxhits().

ilSearchResult::$results = array()
ilSearchResult::$search_cache = null
protected

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

ilSearchResult::$user_id

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

Referenced by getUserId().


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