67 $this->
logger = $DIC->logger()->src();
69 $this->db = $DIC->database();
70 $this->tree = $DIC->repositoryTree();
71 $this->
user = $DIC->user();
74 $this->user_id = $a_user_id;
76 $this->user_id = $this->
user->getId();
87 $this->permission = $a_permission;
98 $this->user_id = $a_user_id;
117 $this->max_hits = $a_max_hits;
142 public function addEntry(
int $a_obj_id,
string $a_type, array $found,
int $a_child_id = 0): void
145 if (!isset($this->entries[$a_obj_id])) {
146 $this->entries[$a_obj_id][
'obj_id'] = $a_obj_id;
147 $this->entries[$a_obj_id][
'type'] = $a_type;
148 $this->entries[$a_obj_id][
'found'] = $found;
149 $this->entries[$a_obj_id][
'child'] = [];
151 if ($a_child_id and $a_child_id != $a_obj_id) {
152 $this->entries[$a_obj_id][
'child'][$a_child_id] = $a_child_id;
156 if ($a_child_id and $a_child_id != $a_obj_id) {
157 $this->entries[$a_obj_id][
'child'][$a_child_id] = $a_child_id;
160 foreach ($found as $position) {
162 $this->entries[$a_obj_id][
'found'][$counter] = $position;
187 foreach ($result_obj->
getEntries() as $obj_id => $entry) {
188 $this->
addEntry($entry[
'obj_id'], $entry[
'type'], $entry[
'found']);
200 $this->entries = array();
203 foreach ($this->search_cache->getCheckedItems() as
$ref_id => $obj_id) {
204 if (isset($new_entries[$obj_id])) {
206 $new_entries[$obj_id][
'obj_id'],
207 $new_entries[$obj_id][
'type'],
208 $new_entries[$obj_id][
'found']
211 $new_entries[$obj_id][
'obj_id'],
212 $new_entries[$obj_id][
'child']
225 foreach ($result_obj->
getEntries() as $entry) {
226 $obj_id = $entry[
'obj_id'];
227 if (isset($new_entries[$obj_id])) {
229 $new_entries[$obj_id][
'obj_id'],
230 $new_entries[$obj_id][
'type'],
231 $new_entries[$obj_id][
'found']
235 $new_entries[$obj_id][
'obj_id'],
236 $new_entries[$obj_id][
'child']
242 public function addResult(
int $a_ref_id,
int $a_obj_id,
string $a_type): void
244 $this->results[$a_ref_id][
'ref_id'] = $a_ref_id;
245 $this->results[$a_ref_id][
'obj_id'] = $a_obj_id;
246 $this->results[$a_ref_id][
'type'] = $a_type;
271 $tmp_res[$res_data[
'obj_id']][] =
$ref_id;
285 foreach ($this->results as $result) {
286 if (in_array($result[
'obj_id'], $obj_ids)) {
289 $obj_ids[] = $result[
'obj_id'];
290 $objects[] = $result;
299 if (!is_array($result)) {
303 $res[(
int) $result[
'ref_id']] = (
int) $result[
'obj_id'];
312 $res[$row[
'obj_id']] = $row[
'child'] ?? [];
327 ilDate $creation_filter_date = null,
328 int $creation_filter_operator = null
335 if ($check_and and in_array(0, $entry[
'found'])) {
340 if ($type ==
'rolt' or $type ==
'usr' or $type ==
'role') {
342 $this->
addResult($entry[
'obj_id'], $entry[
'obj_id'], $type);
343 if (is_array($entry[
'child'])) {
344 $counter += count($entry[
'child']);
348 $this->limit_reached =
true;
359 if (!is_null($creation_filter_date) && !is_null($creation_filter_operator)) {
366 $creation_date =
new ilDate(
367 date(
'Y-m-d', strtotime($creation_date_string)),
371 switch ($creation_filter_operator) {
395 if ($this->search_cache->isFailed($ref_id)) {
399 if ($this->search_cache->isChecked($ref_id) and !$this->
isOffsetReached($offset_counter)) {
412 if ($this->
ilAccess->checkAccessOfUser(
420 if ($a_root_node ==
ROOT_FOLDER_ID or $this->tree->isGrandChild($a_root_node, $ref_id)) {
422 #if($this->callListeners($ref_id,$entry)) 424 $this->
addResult($ref_id, $entry[
'obj_id'], $type);
425 $this->search_cache->appendToChecked($ref_id, $entry[
'obj_id']);
433 $this->limit_reached =
true;
434 $this->search_cache->setResults($this->results);
441 $this->search_cache->appendToFailed($ref_id);
444 $this->search_cache->setResults($this->results);
456 $this->results = array();
457 foreach ($tmp_results as $result) {
458 if ($this->tree->isGrandChild($a_root_node, $result[
'ref_id']) && $this->tree->isInTree($result[
'ref_id'])) {
459 $this->
addResult($result[
'ref_id'], $result[
'obj_id'], $result[
'type']);
473 $this->search_cache->save();
483 $this->results = $this->search_cache->getResults();
496 if ($this->entries[$a_obj_id] and is_array($a_childs)) {
497 foreach ($a_childs as $child_id) {
499 $this->entries[$a_obj_id][
'child'][$child_id] = $child_id;
511 if ($this->results[$a_ref_id] and is_array($a_childs)) {
512 foreach ($a_childs as $child_id) {
513 $this->results[$a_ref_id][
'child'][$child_id] = $child_id;
526 $this->
setMaxHits($this->search_settings->getMaxHits());
539 $this->offset = $this->
getMaxHits() * ($this->search_cache->getResultPageNumber() - 1) ;
551 if (null === $a_flag) {
568 public function addObserver(
object $a_class,
string $a_method): bool
570 $this->observers[] = array(
'class' => $a_class,
571 'method' => $a_method);
578 foreach ($this->observers as $observer) {
579 $class = &$observer[
'class'];
580 $method = $observer[
'method'];
582 if (!$class->$method($a_ref_id, $a_data)) {
setMaxHits(int $a_max_hits)
read(int $a_type=ilUserSearchCache::DEFAULT_SEARCH)
read search results
callListeners(int $a_ref_id, array $a_data)
diffEntriesFromResult()
diff entries of this instance and another result object Used for search in results ...
getResultIds()
get result ids
static _before(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
const CDATE_OPERATOR_BEFORE
addObserver(object $a_class, string $a_method)
The observer is used to call functions for filtering result.
static _getInstance(int $a_usr_id)
static _getAllReferences(int $id)
get all reference ids for object ID
bool $preventOverwritingMaxhits
initUserSearchCache()
Init user search cache.
ilSearchSettings $search_settings
getResultsForPresentation()
intersectEntries(ilSearchResult $result_obj)
Build intersection of entries (all entries that are present in both result sets)
getUniqueResults()
Get unique results.
const CDATE_OPERATOR_AFTER
addResult(int $a_ref_id, int $a_obj_id, string $a_type)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
setRequiredPermission(string $a_permission)
Set the required permission for the rbac checks in function 'filter()'.
static _after(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
filter(int $a_root_node, bool $check_and, ilDate $creation_filter_date=null, int $creation_filter_operator=null)
Filter search result.
addEntry(int $a_obj_id, string $a_type, array $found, int $a_child_id=0)
add search result entry Entries are stored with 'obj_id'.
__updateResultChilds(int $a_ref_id, array $a_childs)
Update child ids for a specific result.
save(int $a_type=ilUserSearchCache::DEFAULT_SEARCH)
Save search results.
__initSearchSettingsObject()
__construct(int $a_user_id=0)
Constructor public.
isOffsetReached(int $a_counter)
Check if offset is reached.
ilUserSearchCache $search_cache
static _lookupCreationDate(int $obj_id)
mergeEntries(ilSearchResult $result_obj)
merge entries of this instance and another result object
setUserId(int $a_user_id)
Class for storing search result.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
numEntries()
Check number of entries public.
static _equals(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check if two date are equal.
__updateEntryChilds(int $a_obj_id, array $a_childs)
Update childs for a specific entry.
filterResults(int $a_root_node)
Filter search area of result set public.
static _lookupType(int $id, bool $reference=false)
preventOverwritingMaxhits(?bool $a_flag=null)
If you call this function and pass "true" the maxhits setting will not be overwritten in __initSearch...