ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
ilUserSearchCache Class Reference

Class for storing search result. More...

+ Collaboration diagram for ilUserSearchCache:

Public Member Functions

 isAnonymous ()
 Check if current user is anonymous user. More...
 
 switchSearchType (int $a_type)
 switch to search type reads entries from database More...
 
 getResults ()
 Get results. More...
 
 setResults (array $a_results)
 Set results. More...
 
 addResult (array $a_result_item)
 Append result. More...
 
 appendToFailed (int $a_ref_id)
 Append failed id. More...
 
 isFailed (int $a_ref_id)
 check if reference has failed access More...
 
 appendToChecked (int $a_ref_id, int $a_obj_id)
 Append checked id. More...
 
 isChecked (int $a_ref_id)
 Check if reference was already checked. More...
 
 getCheckedItems ()
 Get all checked items @access public. More...
 
 setResultPageNumber (int $a_number)
 Set result page number. More...
 
 getResultPageNumber ()
 get result page number More...
 
 setQuery ($a_query)
 set query More...
 
 getQuery ()
 
 getUrlEncodedQuery ()
 Urlencode query for further use in e.g glossariers (highlighting off search terms). More...
 
 setRoot (int $a_root)
 set root node of search More...
 
 getRoot ()
 get root node More...
 
 setItemFilter (array $a_filter)
 
 getItemFilter ()
 
 setMimeFilter (array $a_filter)
 
 getMimeFilter ()
 
 setCreationFilter (array $a_filter)
 
 getCreationFilter ()
 
 deleteCachedEntries ()
 delete cached entries More...
 
 deleteCachedEntriesAnonymous ()
 Delete cached entries for anonymous user. More...
 
 delete ()
 
 save ()
 
 saveForAnonymous ()
 

Static Public Member Functions

static _getInstance (int $a_usr_id)
 

Data Fields

const DEFAULT_SEARCH = 0
 
const ADVANCED_SEARCH = 1
 
const ADVANCED_MD_SEARCH = 4
 
const LUCENE_DEFAULT = 5
 
const LUCENE_ADVANCED = 6
 
const LAST_QUERY = 7
 
const LUCENE_USER_SEARCH = 8
 

Protected Attributes

ilDBInterface $db
 

Private Member Functions

 __construct (int $a_usr_id)
 Constructor. More...
 
 read ()
 Read user entries. More...
 
 readAnonymous ()
 Read from session for anonymous user. More...
 

Private Attributes

int $usr_id
 
int $search_type = self::DEFAULT_SEARCH
 
array $search_result = array()
 
array $checked = array()
 
array $failed = array()
 
int $page_number = 1
 
 $query
 
int $root
 
array $item_filter = array()
 
bool $isAnonymous = false
 
array $mime_filter = array()
 
array $creation_filter = array()
 

Static Private Attributes

static ilUserSearchCache $instance = null
 

Detailed Description

Class for storing search result.

Allows paging of result sets

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

@ilCtrl_Calls

Definition at line 36 of file class.ilUserSearchCache.php.

Constructor & Destructor Documentation

◆ __construct()

ilUserSearchCache::__construct ( int  $a_usr_id)
private

Constructor.

@access private

Definition at line 77 of file class.ilUserSearchCache.php.

78 {
79 global $DIC;
80
81 $this->db = $DIC->database();
82
83 if ($a_usr_id == ANONYMOUS_USER_ID) {
84 $this->isAnonymous = true;
85 }
86
87 $this->root = ROOT_FOLDER_ID;
88 $this->usr_id = $a_usr_id;
89 $this->search_type = self::DEFAULT_SEARCH;
90 $this->read();
91 }
isAnonymous()
Check if current user is anonymous user.
read()
Read user entries.
const ANONYMOUS_USER_ID
Definition: constants.php:27
const ROOT_FOLDER_ID
Definition: constants.php:32
global $DIC
Definition: feed.php:28

References $DIC, ANONYMOUS_USER_ID, DEFAULT_SEARCH, isAnonymous(), read(), and ROOT_FOLDER_ID.

+ Here is the call graph for this function:

Member Function Documentation

◆ _getInstance()

static ilUserSearchCache::_getInstance ( int  $a_usr_id)
static

◆ addResult()

ilUserSearchCache::addResult ( array  $a_result_item)

Append result.

@access public

Parameters
array(int,int,string)array(ref_id,obj_id,type)

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

151 : bool
152 {
153 $this->search_result[$a_result_item['ref_id']]['ref_id'] = $a_result_item['ref_id'];
154 $this->search_result[$a_result_item['ref_id']]['obj_id'] = $a_result_item['obj_id'];
155 $this->search_result[$a_result_item['ref_id']]['type'] = $a_result_item['type'];
156 return true;
157 }

◆ appendToChecked()

ilUserSearchCache::appendToChecked ( int  $a_ref_id,
int  $a_obj_id 
)

Append checked id.

@access public

Parameters
intchecked reference id
intchecked obj_id

Definition at line 183 of file class.ilUserSearchCache.php.

183 : void
184 {
185 $this->checked[$a_ref_id] = $a_obj_id;
186 }

◆ appendToFailed()

ilUserSearchCache::appendToFailed ( int  $a_ref_id)

Append failed id.

Definition at line 162 of file class.ilUserSearchCache.php.

162 : void
163 {
164 $this->failed[$a_ref_id] = $a_ref_id;
165 }

◆ delete()

ilUserSearchCache::delete ( )

Definition at line 377 of file class.ilUserSearchCache.php.

377 : bool
378 {
379 $query = "DELETE FROM usr_search " .
380 "WHERE usr_id = " . $this->db->quote($this->usr_id, 'integer') . " " .
381 "AND search_type = " . $this->db->quote($this->search_type, 'integer');
382 $res = $this->db->manipulate($query);
383
384 $this->read();
385 return true;
386 }
$res
Definition: ltiservices.php:69

References $query, $res, and read().

+ Here is the call graph for this function:

◆ deleteCachedEntries()

ilUserSearchCache::deleteCachedEntries ( )

delete cached entries

Definition at line 316 of file class.ilUserSearchCache.php.

316 : void
317 {
318 if ($this->isAnonymous()) {
320 return;
321 }
322 $query = "SELECT COUNT(*) num FROM usr_search " .
323 "WHERE usr_id = " . $this->db->quote($this->usr_id, 'integer') . " " .
324 "AND search_type = " . $this->db->quote($this->search_type, 'integer');
325 $res = $this->db->query($query);
326 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
327
328 if ($row->num > 0) {
329 $this->db->update(
330 'usr_search',
331 array(
332 'search_result' => array('clob',serialize(array(0))),
333 'checked' => array('clob',serialize(array(0))),
334 'failed' => array('clob',serialize(array(0))),
335 'page' => array('integer',0)),
336 array(
337 'usr_id' => array('integer', $this->usr_id),
338 'search_type' => array('integer', $this->search_type)
339 )
340 );
341 } else {
342 $this->db->insert(
343 'usr_search',
344 array(
345 'search_result' => array('clob',serialize(array(0))),
346 'checked' => array('clob',serialize(array(0))),
347 'failed' => array('clob',serialize(array(0))),
348 'page' => array('integer',0),
349 'usr_id' => array('integer', $this->usr_id),
350 'search_type' => array('integer', $this->search_type)
351 )
352 );
353 }
354
355 $this->setResultPageNumber(1);
356 $this->search_result = array();
357 $this->checked = array();
358 $this->failed = array();
359 }
deleteCachedEntriesAnonymous()
Delete cached entries for anonymous user.
setResultPageNumber(int $a_number)
Set result page number.

References $query, $res, deleteCachedEntriesAnonymous(), ilDBConstants\FETCHMODE_OBJECT, isAnonymous(), and setResultPageNumber().

+ Here is the call graph for this function:

◆ deleteCachedEntriesAnonymous()

ilUserSearchCache::deleteCachedEntriesAnonymous ( )

Delete cached entries for anonymous user.

Returns
bool

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

365 : bool
366 {
367 $this->setResultPageNumber(1);
368 $this->search_result = array();
369 $this->checked = array();
370 $this->failed = array();
371
372 return true;
373 }

References setResultPageNumber().

Referenced by deleteCachedEntries().

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

◆ getCheckedItems()

ilUserSearchCache::getCheckedItems ( )

Get all checked items @access public.

Returns
array array(ref_id => obj_id)

Definition at line 205 of file class.ilUserSearchCache.php.

205 : array
206 {
207 return $this->checked ?: array();
208 }

◆ getCreationFilter()

ilUserSearchCache::getCreationFilter ( )

Definition at line 307 of file class.ilUserSearchCache.php.

307 : array
308 {
310 }

References $creation_filter.

Referenced by save(), and saveForAnonymous().

+ Here is the caller graph for this function:

◆ getItemFilter()

ilUserSearchCache::getItemFilter ( )

Definition at line 287 of file class.ilUserSearchCache.php.

287 : array
288 {
289 return $this->item_filter;
290 }

References $item_filter.

Referenced by save(), and saveForAnonymous().

+ Here is the caller graph for this function:

◆ getMimeFilter()

ilUserSearchCache::getMimeFilter ( )

Definition at line 297 of file class.ilUserSearchCache.php.

297 : array
298 {
299 return $this->mime_filter;
300 }

References $mime_filter.

Referenced by save(), and saveForAnonymous().

+ Here is the caller graph for this function:

◆ getQuery()

ilUserSearchCache::getQuery ( )
Returns
string|array query string or array (for advanced search)

Definition at line 244 of file class.ilUserSearchCache.php.

245 {
246 if (is_array($this->query)) {
247 return $this->query;
248 }
249 return $this->query ?? '';
250 }

References $query.

Referenced by getUrlEncodedQuery(), save(), and saveForAnonymous().

+ Here is the caller graph for this function:

◆ getResultPageNumber()

ilUserSearchCache::getResultPageNumber ( )

get result page number

Definition at line 226 of file class.ilUserSearchCache.php.

226 : int
227 {
228 return $this->page_number ?: 1;
229 }

◆ getResults()

ilUserSearchCache::getResults ( )

Get results.

@access public

Definition at line 127 of file class.ilUserSearchCache.php.

127 : array
128 {
129 return $this->search_result ?: array();
130 }

◆ getRoot()

ilUserSearchCache::getRoot ( )

get root node

Returns
int

Definition at line 277 of file class.ilUserSearchCache.php.

277 : int
278 {
279 return $this->root ?: ROOT_FOLDER_ID;
280 }

References ROOT_FOLDER_ID.

Referenced by save(), and saveForAnonymous().

+ Here is the caller graph for this function:

◆ getUrlEncodedQuery()

ilUserSearchCache::getUrlEncodedQuery ( )

Urlencode query for further use in e.g glossariers (highlighting off search terms).

Definition at line 255 of file class.ilUserSearchCache.php.

255 : string
256 {
257 if (is_array($this->getQuery())) {
258 $query = $this->getQuery();
259
260 return urlencode(str_replace('"', '.', $query['lom_content']));
261 }
262 return urlencode(str_replace('"', '.', $this->getQuery()));
263 }

References $query, and getQuery().

+ Here is the call graph for this function:

◆ isAnonymous()

ilUserSearchCache::isAnonymous ( )

Check if current user is anonymous user.

Returns
bool

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

105 : bool
106 {
107 return $this->isAnonymous;
108 }

References $isAnonymous.

Referenced by __construct(), deleteCachedEntries(), read(), and save().

+ Here is the caller graph for this function:

◆ isChecked()

ilUserSearchCache::isChecked ( int  $a_ref_id)

Check if reference was already checked.

@access public

Parameters
intref_id

Definition at line 195 of file class.ilUserSearchCache.php.

195 : bool
196 {
197 return array_key_exists($a_ref_id, $this->checked) and $this->checked[$a_ref_id];
198 }

◆ isFailed()

ilUserSearchCache::isFailed ( int  $a_ref_id)

check if reference has failed access

Definition at line 170 of file class.ilUserSearchCache.php.

170 : bool
171 {
172 return in_array($a_ref_id, $this->failed);
173 }

◆ read()

ilUserSearchCache::read ( )
private

Read user entries.

@access private

Definition at line 451 of file class.ilUserSearchCache.php.

451 : void
452 {
453 $this->failed = array();
454 $this->checked = array();
455 $this->search_result = array();
456 $this->page_number = 0;
457
458 if ($this->isAnonymous()) {
459 $this->readAnonymous();
460 return;
461 }
462
463 $query = "SELECT * FROM usr_search " .
464 "WHERE usr_id = " . $this->db->quote($this->usr_id, 'integer') . " " .
465 "AND search_type = " . $this->db->quote($this->search_type, 'integer');
466
467 $res = $this->db->query($query);
468 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
469 $this->search_result = (array) unserialize((string) $row->search_result);
470 if (strlen((string) $row->checked)) {
471 $this->checked = (array) unserialize((string) $row->checked);
472 }
473 if (strlen((string) $row->failed)) {
474 $this->failed = (array) unserialize((string) $row->failed);
475 }
476 $this->page_number = (int) $row->page;
477 $this->setQuery(unserialize((string) $row->query));
478 $this->setRoot((int) $row->root);
479 $this->setItemFilter((array) unserialize((string) $row->item_filter));
480 $this->setCreationFilter((array) unserialize((string) $row->creation_filter));
481 }
482 }
setCreationFilter(array $a_filter)
readAnonymous()
Read from session for anonymous user.
setItemFilter(array $a_filter)
setRoot(int $a_root)
set root node of search

References $query, $res, ilDBConstants\FETCHMODE_OBJECT, ILIAS\Repository\int(), isAnonymous(), readAnonymous(), setCreationFilter(), setItemFilter(), and setRoot().

Referenced by __construct(), delete(), and switchSearchType().

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

◆ readAnonymous()

ilUserSearchCache::readAnonymous ( )
private

Read from session for anonymous user.

Definition at line 487 of file class.ilUserSearchCache.php.

487 : void
488 {
489 $usr_search_cache = ilSession::get('usr_search_cache') ?? [];
490
491 $this->search_result = (array) ($usr_search_cache[$this->search_type]['search_result'] ?? []);
492 $this->checked = (array) ($usr_search_cache[$this->search_type]['checked'] ?? []);
493 $this->failed = (array) ($usr_search_cache[$this->search_type]['failed'] ?? []);
494 $this->page_number = (int) ($usr_search_cache[$this->search_type]['page_number'] ?? 1);
495 $this->setQuery((string) ($usr_search_cache[$this->search_type]['query'] ?? ''));
496 $this->setRoot((int) ($usr_search_cache[$this->search_type]['root'] ?? ROOT_FOLDER_ID));
497 $this->setItemFilter((array) ($usr_search_cache[$this->search_type]['item_filter'] ?? []));
498 $this->setMimeFilter((array) ($usr_search_cache[$this->search_type]['mime_filter'] ?? []));
499 $this->setCreationFilter((array) ($usr_search_cache[$this->search_type]['creation_filter'] ?? []));
500 }
static get(string $a_var)
setMimeFilter(array $a_filter)
setQuery($a_query)
set query

References ilSession\get(), ILIAS\Repository\int(), ROOT_FOLDER_ID, setCreationFilter(), setItemFilter(), setMimeFilter(), setQuery(), and setRoot().

Referenced by read().

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

◆ save()

ilUserSearchCache::save ( )

Definition at line 388 of file class.ilUserSearchCache.php.

388 : void
389 {
390 if ($this->isAnonymous()) {
391 $this->saveForAnonymous();
392 return;
393 }
394
395 $query = "DELETE FROM usr_search " .
396 "WHERE usr_id = " . $this->db->quote($this->usr_id, 'integer') . " " .
397 "AND ( search_type = " . $this->db->quote($this->search_type, 'integer') . ' ' .
398 "OR search_type = " . $this->db->quote(self::LAST_QUERY, 'integer') . ')';
399 $res = $this->db->manipulate($query);
400
401 $this->db->insert('usr_search', array(
402 'usr_id' => array('integer', $this->usr_id),
403 'search_result' => array('clob',serialize($this->search_result)),
404 'checked' => array('clob',serialize($this->checked)),
405 'failed' => array('clob',serialize($this->failed)),
406 'page' => array('integer', $this->page_number),
407 'search_type' => array('integer', $this->search_type),
408 'query' => array('clob',serialize($this->getQuery())),
409 'root' => array('integer',$this->getRoot()),
410 'item_filter' => array('text',serialize($this->getItemFilter())),
411 'mime_filter' => array('text', serialize($this->getMimeFilter())),
412 'creation_filter' => array('text', serialize($this->getCreationFilter()))
413 ));
414
415
416 // Write last query information
417 $this->db->insert(
418 'usr_search',
419 array(
420 'usr_id' => array('integer',$this->usr_id),
421 'search_type' => array('integer',self::LAST_QUERY),
422 'query' => array('text',serialize($this->getQuery()))
423 )
424 );
425 }

References $query, $res, getCreationFilter(), getItemFilter(), getMimeFilter(), getQuery(), getRoot(), isAnonymous(), and saveForAnonymous().

+ Here is the call graph for this function:

◆ saveForAnonymous()

ilUserSearchCache::saveForAnonymous ( )

Definition at line 427 of file class.ilUserSearchCache.php.

427 : void
428 {
429 ilSession::clear('usr_search_cache');
430 $session_usr_search = [];
431 $session_usr_search[$this->search_type]['search_result'] = $this->search_result;
432 $session_usr_search[$this->search_type]['checked'] = $this->checked;
433 $session_usr_search[$this->search_type]['failed'] = $this->failed;
434 $session_usr_search[$this->search_type]['page'] = $this->page_number;
435 $session_usr_search[$this->search_type]['query'] = $this->getQuery();
436 $session_usr_search[$this->search_type]['root'] = $this->getRoot();
437 $session_usr_search[$this->search_type]['item_filter'] = $this->getItemFilter();
438 $session_usr_search[$this->search_type]['mime_filter'] = $this->getMimeFilter();
439 $session_usr_search[$this->search_type]['creation_filter'] = $this->getCreationFilter();
440 $session_usr_search[self::LAST_QUERY]['query'] = $this->getQuery();
441 ilSession::set('usr_search_cache', $session_usr_search);
442 }
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.

References $checked, $failed, $page_number, $search_result, $search_type, ilSession\clear(), getCreationFilter(), getItemFilter(), getMimeFilter(), getQuery(), getRoot(), LAST_QUERY, and ilSession\set().

Referenced by save().

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

◆ setCreationFilter()

ilUserSearchCache::setCreationFilter ( array  $a_filter)

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

302 : void
303 {
304 $this->creation_filter = $a_filter;
305 }

Referenced by read(), and readAnonymous().

+ Here is the caller graph for this function:

◆ setItemFilter()

ilUserSearchCache::setItemFilter ( array  $a_filter)

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

282 : void
283 {
284 $this->item_filter = $a_filter;
285 }

Referenced by read(), and readAnonymous().

+ Here is the caller graph for this function:

◆ setMimeFilter()

ilUserSearchCache::setMimeFilter ( array  $a_filter)

Definition at line 292 of file class.ilUserSearchCache.php.

292 : void
293 {
294 $this->mime_filter = $a_filter;
295 }

Referenced by readAnonymous().

+ Here is the caller graph for this function:

◆ setQuery()

ilUserSearchCache::setQuery (   $a_query)

set query

Parameters
mixedquery string or array (for advanced search)
Returns
void

Definition at line 236 of file class.ilUserSearchCache.php.

236 : void
237 {
238 $this->query = $a_query;
239 }

Referenced by readAnonymous().

+ Here is the caller graph for this function:

◆ setResultPageNumber()

ilUserSearchCache::setResultPageNumber ( int  $a_number)

Set result page number.

@access public

Definition at line 216 of file class.ilUserSearchCache.php.

216 : void
217 {
218 if ($a_number) {
219 $this->page_number = $a_number;
220 }
221 }

Referenced by deleteCachedEntries(), and deleteCachedEntriesAnonymous().

+ Here is the caller graph for this function:

◆ setResults()

ilUserSearchCache::setResults ( array  $a_results)

Set results.

@access public

Parameters
array(int=> array(int,int,string)) array(ref_id => array(ref_id,obj_id,type))

Definition at line 139 of file class.ilUserSearchCache.php.

139 : void
140 {
141 $this->search_result = $a_results;
142 }

◆ setRoot()

ilUserSearchCache::setRoot ( int  $a_root)

set root node of search

Definition at line 268 of file class.ilUserSearchCache.php.

268 : void
269 {
270 $this->root = $a_root;
271 }

Referenced by read(), and readAnonymous().

+ Here is the caller graph for this function:

◆ switchSearchType()

ilUserSearchCache::switchSearchType ( int  $a_type)

switch to search type reads entries from database

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

114 : bool
115 {
116 $this->search_type = $a_type;
117 $this->read();
118 return true;
119 }

References read().

+ Here is the call graph for this function:

Field Documentation

◆ $checked

array ilUserSearchCache::$checked = array()
private

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

Referenced by saveForAnonymous().

◆ $creation_filter

array ilUserSearchCache::$creation_filter = array()
private

Definition at line 67 of file class.ilUserSearchCache.php.

Referenced by getCreationFilter().

◆ $db

ilDBInterface ilUserSearchCache::$db
protected

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

◆ $failed

array ilUserSearchCache::$failed = array()
private

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

Referenced by saveForAnonymous().

◆ $instance

ilUserSearchCache ilUserSearchCache::$instance = null
staticprivate

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

Referenced by _getInstance().

◆ $isAnonymous

bool ilUserSearchCache::$isAnonymous = false
private

Definition at line 65 of file class.ilUserSearchCache.php.

Referenced by isAnonymous().

◆ $item_filter

array ilUserSearchCache::$item_filter = array()
private

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

Referenced by getItemFilter().

◆ $mime_filter

array ilUserSearchCache::$mime_filter = array()
private

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

Referenced by getMimeFilter().

◆ $page_number

int ilUserSearchCache::$page_number = 1
private

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

Referenced by saveForAnonymous().

◆ $query

string array ilUserSearchCache::$query
private

◆ $root

int ilUserSearchCache::$root
private

Definition at line 63 of file class.ilUserSearchCache.php.

◆ $search_result

array ilUserSearchCache::$search_result = array()
private

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

Referenced by saveForAnonymous().

◆ $search_type

int ilUserSearchCache::$search_type = self::DEFAULT_SEARCH
private

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

Referenced by saveForAnonymous().

◆ $usr_id

int ilUserSearchCache::$usr_id
private

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

◆ ADVANCED_MD_SEARCH

◆ ADVANCED_SEARCH

const ilUserSearchCache::ADVANCED_SEARCH = 1

◆ DEFAULT_SEARCH

const ilUserSearchCache::DEFAULT_SEARCH = 0

Definition at line 38 of file class.ilUserSearchCache.php.

Referenced by __construct().

◆ LAST_QUERY

const ilUserSearchCache::LAST_QUERY = 7

◆ LUCENE_ADVANCED

const ilUserSearchCache::LUCENE_ADVANCED = 6

◆ LUCENE_DEFAULT

const ilUserSearchCache::LUCENE_DEFAULT = 5

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

Referenced by ilLuceneSearchGUI\initUserSearchCache().

◆ LUCENE_USER_SEARCH

const ilUserSearchCache::LUCENE_USER_SEARCH = 8

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