ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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)
 
 isChecked (int $a_ref_id)
 
 getCheckedItems ()
 Get all checked items @access public. More...
 
 setResultPageNumber (int $a_number)
 Set result page number. More...
 
 getResultPageNumber ()
 get result page number More...
 
 setQuery (string $a_query)
 
 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 ()
 
 setItemFilter (array $a_filter)
 
 getItemFilter ()
 
 setMimeFilter (array $a_filter)
 
 getMimeFilter ()
 
 setCreationFilter (array $a_filter)
 
 getCreationFilter ()
 
 deleteCachedEntries ()
 
 deleteCachedEntriesAnonymous ()
 
 delete ()
 
 save ()
 
 saveForAnonymous ()
 

Static Public Member Functions

static _getInstance (int $a_usr_id)
 

Data Fields

const int DEFAULT_SEARCH = 0
 
const int LUCENE_DEFAULT = 5
 
const int LAST_QUERY = 7
 
const int LUCENE_USER_SEARCH = 8
 

Protected Attributes

ilDBInterface $db
 

Private Member Functions

 __construct (int $a_usr_id)
 Constructor. More...
 
 read ()
 
 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

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

Constructor & Destructor Documentation

◆ __construct()

ilUserSearchCache::__construct ( int  $a_usr_id)
private

Constructor.

@access private

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

65 {
66 global $DIC;
67
68 $this->db = $DIC->database();
69
70 if ($a_usr_id == ANONYMOUS_USER_ID) {
71 $this->isAnonymous = true;
72 }
73
74 $this->root = ROOT_FOLDER_ID;
75 $this->usr_id = $a_usr_id;
76 $this->search_type = self::DEFAULT_SEARCH;
77 $this->read();
78 }
isAnonymous()
Check if current user is anonymous user.
const ANONYMOUS_USER_ID
Definition: constants.php:27
const ROOT_FOLDER_ID
Definition: constants.php:32
global $DIC
Definition: shib_login.php:26

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$a_result_item(int,int,string) array(ref_id,obj_id,type)

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

138 : bool
139 {
140 $this->search_result[$a_result_item['ref_id']]['ref_id'] = $a_result_item['ref_id'];
141 $this->search_result[$a_result_item['ref_id']]['obj_id'] = $a_result_item['obj_id'];
142 $this->search_result[$a_result_item['ref_id']]['type'] = $a_result_item['type'];
143 return true;
144 }

◆ appendToChecked()

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

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

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

References ILIAS\UI\examples\Symbol\Glyph\Checked\checked().

+ Here is the call graph for this function:

◆ appendToFailed()

ilUserSearchCache::appendToFailed ( int  $a_ref_id)

Append failed id.

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

149 : void
150 {
151 $this->failed[$a_ref_id] = $a_ref_id;
152 }

◆ delete()

ilUserSearchCache::delete ( )

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

320 : bool
321 {
322 $query = "DELETE 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->manipulate($query);
326
327 $this->read();
328 return true;
329 }
$res
Definition: ltiservices.php:69

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

+ Here is the call graph for this function:

◆ deleteCachedEntries()

ilUserSearchCache::deleteCachedEntries ( )

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

264 : void
265 {
266 if ($this->isAnonymous()) {
268 return;
269 }
270 $query = "SELECT COUNT(*) num FROM usr_search " .
271 "WHERE usr_id = " . $this->db->quote($this->usr_id, 'integer') . " " .
272 "AND search_type = " . $this->db->quote($this->search_type, 'integer');
273 $res = $this->db->query($query);
274 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
275
276 if ($row->num > 0) {
277 $this->db->update(
278 'usr_search',
279 array(
280 'search_result' => array('clob',serialize(array(0))),
281 'checked' => array('clob',serialize(array(0))),
282 'failed' => array('clob',serialize(array(0))),
283 'page' => array('integer',0)),
284 array(
285 'usr_id' => array('integer', $this->usr_id),
286 'search_type' => array('integer', $this->search_type)
287 )
288 );
289 } else {
290 $this->db->insert(
291 'usr_search',
292 array(
293 'search_result' => array('clob',serialize(array(0))),
294 'checked' => array('clob',serialize(array(0))),
295 'failed' => array('clob',serialize(array(0))),
296 'page' => array('integer',0),
297 'usr_id' => array('integer', $this->usr_id),
298 'search_type' => array('integer', $this->search_type),
299 'query' => array('clob',serialize(''))
300 )
301 );
302 }
303
304 $this->setResultPageNumber(1);
305 $this->search_result = array();
306 $this->checked = array();
307 $this->failed = array();
308 }
setResultPageNumber(int $a_number)
Set result page number.

References $query, $res, ILIAS\UI\examples\Symbol\Glyph\Checked\checked(), deleteCachedEntriesAnonymous(), ilDBConstants\FETCHMODE_OBJECT, isAnonymous(), and setResultPageNumber().

+ Here is the call graph for this function:

◆ deleteCachedEntriesAnonymous()

ilUserSearchCache::deleteCachedEntriesAnonymous ( )

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

310 : bool
311 {
312 $this->setResultPageNumber(1);
313 $this->search_result = array();
314 $this->checked = array();
315 $this->failed = array();
316
317 return true;
318 }

References ILIAS\UI\examples\Symbol\Glyph\Checked\checked(), and 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 177 of file class.ilUserSearchCache.php.

177 : array
178 {
179 return $this->checked ?: array();
180 }

References ILIAS\UI\examples\Symbol\Glyph\Checked\checked().

+ Here is the call graph for this function:

◆ getCreationFilter()

ilUserSearchCache::getCreationFilter ( )

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

259 : array
260 {
262 }

References $creation_filter.

Referenced by save(), and saveForAnonymous().

+ Here is the caller graph for this function:

◆ getItemFilter()

ilUserSearchCache::getItemFilter ( )

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

239 : array
240 {
241 return $this->item_filter;
242 }

References $item_filter.

Referenced by save(), and saveForAnonymous().

+ Here is the caller graph for this function:

◆ getMimeFilter()

ilUserSearchCache::getMimeFilter ( )

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

249 : array
250 {
251 return $this->mime_filter;
252 }

References $mime_filter.

Referenced by save(), and saveForAnonymous().

+ Here is the caller graph for this function:

◆ getQuery()

ilUserSearchCache::getQuery ( )

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

208 : string
209 {
210 return $this->query ?? '';
211 }

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

+ Here is the caller graph for this function:

◆ getResultPageNumber()

ilUserSearchCache::getResultPageNumber ( )

get result page number

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

198 : int
199 {
200 return $this->page_number ?: 1;
201 }

◆ getResults()

ilUserSearchCache::getResults ( )

Get results.

@access public

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

114 : array
115 {
116 return $this->search_result ?: array();
117 }

◆ getRoot()

ilUserSearchCache::getRoot ( )

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

229 : int
230 {
231 return $this->root ?: ROOT_FOLDER_ID;
232 }

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 216 of file class.ilUserSearchCache.php.

216 : string
217 {
218 return urlencode(str_replace('"', '.', $this->getQuery()));
219 }

References getQuery().

+ Here is the call graph for this function:

◆ isAnonymous()

ilUserSearchCache::isAnonymous ( )

Check if current user is anonymous user.

Returns
bool

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

92 : bool
93 {
94 return $this->isAnonymous;
95 }

References $isAnonymous.

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

+ Here is the caller graph for this function:

◆ isChecked()

ilUserSearchCache::isChecked ( int  $a_ref_id)

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

167 : bool
168 {
169 return array_key_exists($a_ref_id, $this->checked) and $this->checked[$a_ref_id];
170 }

References ILIAS\UI\examples\Symbol\Glyph\Checked\checked().

+ Here is the call graph for this function:

◆ isFailed()

ilUserSearchCache::isFailed ( int  $a_ref_id)

check if reference has failed access

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

157 : bool
158 {
159 return in_array($a_ref_id, $this->failed);
160 }

◆ read()

ilUserSearchCache::read ( )
private

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

387 : void
388 {
389 $this->failed = array();
390 $this->checked = array();
391 $this->search_result = array();
392 $this->page_number = 0;
393
394 if ($this->isAnonymous()) {
395 $this->readAnonymous();
396 return;
397 }
398
399 $query = "SELECT * FROM usr_search " .
400 "WHERE usr_id = " . $this->db->quote($this->usr_id, 'integer') . " " .
401 "AND search_type = " . $this->db->quote($this->search_type, 'integer');
402
403 $res = $this->db->query($query);
404 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
405 $this->search_result = (array) unserialize((string) $row->search_result);
406 if (strlen((string) $row->checked)) {
407 $this->checked = (array) unserialize((string) $row->checked);
408 }
409 if (strlen((string) $row->failed)) {
410 $this->failed = (array) unserialize((string) $row->failed);
411 }
412 $this->page_number = (int) $row->page;
413 $this->setQuery(unserialize((string) $row->query));
414 $this->setRoot((int) $row->root);
415 $this->setItemFilter((array) unserialize((string) $row->item_filter));
416 $this->setCreationFilter((array) unserialize((string) $row->creation_filter));
417 }
418 }
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, ILIAS\UI\examples\Symbol\Glyph\Checked\checked(), 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 423 of file class.ilUserSearchCache.php.

423 : void
424 {
425 $usr_search_cache = ilSession::get('usr_search_cache') ?? [];
426
427 $this->search_result = (array) ($usr_search_cache[$this->search_type]['search_result'] ?? []);
428 $this->checked = (array) ($usr_search_cache[$this->search_type]['checked'] ?? []);
429 $this->failed = (array) ($usr_search_cache[$this->search_type]['failed'] ?? []);
430 $this->page_number = (int) ($usr_search_cache[$this->search_type]['page_number'] ?? 1);
431 $this->setQuery((string) ($usr_search_cache[$this->search_type]['query'] ?? ''));
432 $this->setRoot((int) ($usr_search_cache[$this->search_type]['root'] ?? ROOT_FOLDER_ID));
433 $this->setItemFilter((array) ($usr_search_cache[$this->search_type]['item_filter'] ?? []));
434 $this->setMimeFilter((array) ($usr_search_cache[$this->search_type]['mime_filter'] ?? []));
435 $this->setCreationFilter((array) ($usr_search_cache[$this->search_type]['creation_filter'] ?? []));
436 }
static get(string $a_var)
setMimeFilter(array $a_filter)

References ILIAS\UI\examples\Symbol\Glyph\Checked\checked(), 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 331 of file class.ilUserSearchCache.php.

331 : void
332 {
333 if ($this->isAnonymous()) {
334 $this->saveForAnonymous();
335 return;
336 }
337
338 $query = "DELETE FROM usr_search " .
339 "WHERE usr_id = " . $this->db->quote($this->usr_id, 'integer') . " " .
340 "AND ( search_type = " . $this->db->quote($this->search_type, 'integer') . ' ' .
341 "OR search_type = " . $this->db->quote(self::LAST_QUERY, 'integer') . ')';
342 $res = $this->db->manipulate($query);
343
344 $this->db->insert('usr_search', array(
345 'usr_id' => array('integer', $this->usr_id),
346 'search_result' => array('clob',serialize($this->search_result)),
347 'checked' => array('clob',serialize($this->checked)),
348 'failed' => array('clob',serialize($this->failed)),
349 'page' => array('integer', $this->page_number),
350 'search_type' => array('integer', $this->search_type),
351 'query' => array('clob',serialize($this->getQuery())),
352 'root' => array('integer',$this->getRoot()),
353 'item_filter' => array('text',serialize($this->getItemFilter())),
354 'mime_filter' => array('text', serialize($this->getMimeFilter())),
355 'creation_filter' => array('text', serialize($this->getCreationFilter()))
356 ));
357
358
359 // Write last query information
360 $this->db->insert(
361 'usr_search',
362 array(
363 'usr_id' => array('integer',$this->usr_id),
364 'search_type' => array('integer',self::LAST_QUERY),
365 'query' => array('text',serialize($this->getQuery()))
366 )
367 );
368 }

References $query, $res, ILIAS\UI\examples\Symbol\Glyph\Checked\checked(), getCreationFilter(), getItemFilter(), getMimeFilter(), getQuery(), getRoot(), isAnonymous(), and saveForAnonymous().

+ Here is the call graph for this function:

◆ saveForAnonymous()

ilUserSearchCache::saveForAnonymous ( )

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

370 : void
371 {
372 ilSession::clear('usr_search_cache');
373 $session_usr_search = [];
374 $session_usr_search[$this->search_type]['search_result'] = $this->search_result;
375 $session_usr_search[$this->search_type]['checked'] = $this->checked;
376 $session_usr_search[$this->search_type]['failed'] = $this->failed;
377 $session_usr_search[$this->search_type]['page'] = $this->page_number;
378 $session_usr_search[$this->search_type]['query'] = $this->getQuery();
379 $session_usr_search[$this->search_type]['root'] = $this->getRoot();
380 $session_usr_search[$this->search_type]['item_filter'] = $this->getItemFilter();
381 $session_usr_search[$this->search_type]['mime_filter'] = $this->getMimeFilter();
382 $session_usr_search[$this->search_type]['creation_filter'] = $this->getCreationFilter();
383 $session_usr_search[self::LAST_QUERY]['query'] = $this->getQuery();
384 ilSession::set('usr_search_cache', $session_usr_search);
385 }
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 254 of file class.ilUserSearchCache.php.

254 : void
255 {
256 $this->creation_filter = $a_filter;
257 }

Referenced by read(), and readAnonymous().

+ Here is the caller graph for this function:

◆ setItemFilter()

ilUserSearchCache::setItemFilter ( array  $a_filter)

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

234 : void
235 {
236 $this->item_filter = $a_filter;
237 }

Referenced by read(), and readAnonymous().

+ Here is the caller graph for this function:

◆ setMimeFilter()

ilUserSearchCache::setMimeFilter ( array  $a_filter)

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

244 : void
245 {
246 $this->mime_filter = $a_filter;
247 }

Referenced by readAnonymous().

+ Here is the caller graph for this function:

◆ setQuery()

ilUserSearchCache::setQuery ( string  $a_query)

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

203 : void
204 {
205 $this->query = $a_query;
206 }

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 188 of file class.ilUserSearchCache.php.

188 : void
189 {
190 if ($a_number) {
191 $this->page_number = $a_number;
192 }
193 }

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$a_results(int => array(int,int,string)) array(ref_id => array(ref_id,obj_id,type))

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

126 : void
127 {
128 $this->search_result = $a_results;
129 }

◆ setRoot()

ilUserSearchCache::setRoot ( int  $a_root)

set root node of search

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

224 : void
225 {
226 $this->root = $a_root;
227 }

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 101 of file class.ilUserSearchCache.php.

101 : bool
102 {
103 $this->search_type = $a_type;
104 $this->read();
105 return true;
106 }

References read().

+ Here is the call graph for this function:

Field Documentation

◆ $checked

array ilUserSearchCache::$checked = array()
private

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

Referenced by saveForAnonymous().

◆ $creation_filter

array ilUserSearchCache::$creation_filter = array()
private

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

Referenced by getCreationFilter().

◆ $db

ilDBInterface ilUserSearchCache::$db
protected

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

◆ $failed

array ilUserSearchCache::$failed = array()
private

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

Referenced by saveForAnonymous().

◆ $instance

ilUserSearchCache ilUserSearchCache::$instance = null
staticprivate

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

Referenced by _getInstance().

◆ $isAnonymous

bool ilUserSearchCache::$isAnonymous = false
private

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

Referenced by isAnonymous().

◆ $item_filter

array ilUserSearchCache::$item_filter = array()
private

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

Referenced by getItemFilter().

◆ $mime_filter

array ilUserSearchCache::$mime_filter = array()
private

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

Referenced by getMimeFilter().

◆ $page_number

int ilUserSearchCache::$page_number = 1
private

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

Referenced by saveForAnonymous().

◆ $query

string array ilUserSearchCache::$query
private

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

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

◆ $root

int ilUserSearchCache::$root
private

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

◆ $search_result

array ilUserSearchCache::$search_result = array()
private

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

Referenced by saveForAnonymous().

◆ $search_type

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

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

Referenced by saveForAnonymous().

◆ $usr_id

int ilUserSearchCache::$usr_id
private

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

◆ DEFAULT_SEARCH

const int ilUserSearchCache::DEFAULT_SEARCH = 0

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

Referenced by __construct().

◆ LAST_QUERY

const int ilUserSearchCache::LAST_QUERY = 7

◆ LUCENE_DEFAULT

const int ilUserSearchCache::LUCENE_DEFAULT = 5

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

Referenced by ilLuceneSearchGUI\initUserSearchCache().

◆ LUCENE_USER_SEARCH

const int ilUserSearchCache::LUCENE_USER_SEARCH = 8

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