34 include_once(
'Services/Search/classes/class.ilUserSearchCache.php');
36 define(
'DEFAULT_SEARCH', 0);
37 define(
'ADVANCED_SEARCH', 1);
38 define(
'ADVANCED_MD_SEARCH', 4);
77 $this->user_id = $a_user_id;
79 $this->user_id =
$ilUser->getId();
92 $this->permission = $a_permission;
103 $this->user_id = $a_user_id;
112 return $this->entries ? $this->entries : array();
117 return $this->limit_reached ? true :
false;
122 $this->max_hits = $a_max_hits;
126 return $this->max_hits;
138 return ($a_counter < $this->offset) ? false :
true;
154 if (!$this->entries[$a_obj_id]) {
155 $this->entries[$a_obj_id][
'obj_id'] = $a_obj_id;
156 $this->entries[$a_obj_id][
'type'] =
$a_type;
157 $this->entries[$a_obj_id][
'found'] = $found;
158 $this->entries[$a_obj_id][
'child'] = [];
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;
165 if ($a_child_id
and $a_child_id != $a_obj_id) {
166 $this->entries[$a_obj_id][
'child'][$a_child_id] = $a_child_id;
171 foreach ($found as $position) {
173 $this->entries[$a_obj_id][
'found'][$counter] = $position;
199 foreach ($result_obj->getEntries() as $entry) {
200 $this->
addEntry($entry[
'obj_id'], $entry[
'type'], $entry[
'found']);
216 $this->entries = array();
219 foreach ($this->search_cache->getCheckedItems() as $ref_id => $obj_id) {
220 if (isset($new_entries[$obj_id])) {
222 $new_entries[$obj_id][
'obj_id'],
223 $new_entries[$obj_id][
'type'],
224 $new_entries[$obj_id][
'found']
227 $new_entries[$obj_id][
'obj_id'],
228 $new_entries[$obj_id][
'child']
243 $this->entries = array();
245 foreach ($result_obj->getEntries() as $entry) {
246 $obj_id = $entry[
'obj_id'];
247 if (isset($new_entries[$obj_id])) {
249 $new_entries[$obj_id][
'obj_id'],
250 $new_entries[$obj_id][
'type'],
251 $new_entries[$obj_id][
'found']
255 $new_entries[$obj_id][
'obj_id'],
256 $new_entries[$obj_id][
'child']
274 $this->results[$a_ref_id][
'ref_id'] = $a_ref_id;
275 $this->results[$a_ref_id][
'obj_id'] = $a_obj_id;
276 $this->results[$a_ref_id][
'type'] =
$a_type;
281 return $this->results ? $this->results : array();
295 return $ids ? $ids : array();
301 foreach ($this->
getResults() as $ref_id => $res_data) {
302 $tmp_res[$res_data[
'obj_id']][] = $ref_id;
304 return $tmp_res ? $tmp_res : array();
317 foreach ($this->results as
$result) {
318 if (in_array($result[
'obj_id'], $obj_ids)) {
321 $obj_ids[] = $result[
'obj_id'];
324 return $objects ? $objects : array();
332 $res[$result[
'ref_id']] = $result[
'obj_id'];
341 $res[$row[
'obj_id']] = $row[
'child'];
360 public function filter($a_root_node, $check_and)
364 $tree = $DIC[
'tree'];
371 if ($check_and
and in_array(0, $entry[
'found'])) {
379 if (is_array($entry[
'child'])) {
380 $counter += count($entry[
'child']);
384 $this->limit_reached =
true;
393 if ($this->search_cache->isFailed($ref_id)) {
397 if ($this->search_cache->isChecked($ref_id)
and !$this->
isOffsetReached($offset_counter)) {
418 if ($a_root_node == ROOT_FOLDER_ID
or $tree->isGrandChild($a_root_node, $ref_id)) {
420 #if($this->callListeners($ref_id,$entry)) 422 $this->
addResult($ref_id, $entry[
'obj_id'], $type);
423 $this->search_cache->appendToChecked($ref_id, $entry[
'obj_id']);
431 $this->limit_reached =
true;
432 $this->search_cache->setResults($this->results);
439 $this->search_cache->appendToFailed($ref_id);
442 $this->search_cache->setResults($this->results);
455 $tree = $DIC[
'tree'];
458 $this->results = array();
459 foreach ($tmp_results as
$result) {
460 if (
$tree->isGrandChild($a_root_node, $result[
'ref_id'])
and $tree->isInTree($result[
'ref_id'])) {
461 $this->
addResult($result[
'ref_id'], $result[
'obj_id'], $result[
'type']);
478 $this->search_cache->save();
489 $this->results = $this->search_cache->getResults();
502 if ($this->entries[$a_obj_id]
and is_array($a_childs)) {
503 foreach ($a_childs as $child_id) {
505 $this->entries[$a_obj_id][
'child'][$child_id] = $child_id;
521 if ($this->results[$a_ref_id]
and is_array($a_childs)) {
522 foreach ($a_childs as $child_id) {
523 $this->results[$a_ref_id][
'child'][$child_id] = $child_id;
534 include_once
'Services/Search/classes/class.ilSearchSettings.php';
538 $this->
setMaxHits($this->search_settings->getMaxHits());
550 include_once(
'Services/Search/classes/class.ilUserSearchCache.php');
552 $this->offset = $this->
getMaxHits() * ($this->search_cache->getResultPageNumber() - 1) ;
566 if (null === $a_flag) {
586 $this->observers[] = array(
'class' => $a_class,
587 'method' => $a_method);
592 foreach ($this->observers as $observer) {
593 $class = &$observer[
'class'];
594 $method = $observer[
'method'];
596 if (!$class->$method($a_ref_id, $a_data)) {
read($a_type=DEFAULT_SEARCH)
read search results
isOffsetReached($a_counter)
Check if offset is reached.
getResultIds()
get result ids
addEntry($a_obj_id, $a_type, $found, $a_child_id=0)
add search result entry Entries are stored with 'obj_id'.
filterResults($a_root_node)
Filter search area of result set public.
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)(option...
if(!array_key_exists('StateId', $_REQUEST)) $id
initUserSearchCache()
Init user search cache.
addObserver(&$a_class, $a_method)
The observer is used to call functions for filtering result.
getResultsForPresentation()
getUniqueResults()
Get unique results.
static _getAllReferences($a_id)
get all reference ids of object
__construct($a_user_id=0)
Constructor public.
diffEntriesFromResult(&$result_obj)
diff entries of this instance and another result object Used for search in results ...
static _getInstance($a_usr_id)
Get singleton instance.
foreach($_POST as $key=> $value) $res
__initSearchSettingsObject()
__updateResultChilds($a_ref_id, $a_childs)
Update childs for a specific result.
addResult($a_ref_id, $a_obj_id, $a_type)
add search result Results are stored with 'ref_id'.
__updateEntryChilds($a_obj_id, $a_childs)
Update childs for a specific entry.
static _lookupType($a_id, $a_reference=false)
lookup object type
intersectEntries(&$result_obj)
Build intersection of entries (all entries that are present in both result sets)
setRequiredPermission($a_permission)
Set the required permission for the rbac checks in function 'filter()'.
mergeEntries(&$result_obj)
merge entries of this instance and another result object
numEntries()
Check number of entries public.
filter($a_root_node, $check_and)
Filter search result.
$preventOverwritingMaxhits
callListeners($a_ref_id, &$a_data)
save($a_type=DEFAULT_SEARCH)
Save search results.
preventOverwritingMaxhits($a_flag=null)
If you call this function and pass "true" the maxhits setting will not be overwritten in __initSearch...