19 declare(strict_types=1);
68 $this->db = $DIC->database();
75 $this->usr_id = $a_usr_id;
76 $this->search_type = self::DEFAULT_SEARCH;
83 return self::$instance;
85 return self::$instance =
new ilUserSearchCache($a_usr_id);
103 $this->search_type = $a_type;
116 return $this->search_result ?: array();
128 $this->search_result = $a_results;
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'];
151 $this->failed[$a_ref_id] = $a_ref_id;
159 return in_array($a_ref_id, $this->failed);
164 $this->
checked[$a_ref_id] = $a_obj_id;
169 return array_key_exists($a_ref_id, $this->
checked) and $this->
checked[$a_ref_id];
179 return $this->
checked ?: array();
191 $this->page_number = $a_number;
200 return $this->page_number ?: 1;
205 $this->query = $a_query;
210 return $this->query ??
'';
218 return urlencode(str_replace(
'"',
'.', $this->
getQuery()));
226 $this->root = $a_root;
236 $this->item_filter = $a_filter;
246 $this->mime_filter = $a_filter;
256 $this->creation_filter = $a_filter;
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');
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)),
285 'usr_id' => array(
'integer', $this->usr_id),
286 'search_type' => array(
'integer', $this->search_type)
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(
''))
305 $this->search_result = array();
307 $this->failed = array();
313 $this->search_result = array();
315 $this->failed = array();
320 public function delete():
bool 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');
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') .
')';
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())),
363 'usr_id' => array(
'integer',$this->usr_id),
364 'search_type' => array(
'integer',self::LAST_QUERY),
365 'query' => array(
'text',serialize($this->
getQuery()))
373 $session_usr_search = [];
383 $session_usr_search[self::LAST_QUERY][
'query'] = $this->
getQuery();
389 $this->failed = array();
391 $this->search_result = array();
392 $this->page_number = 0;
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');
405 $this->search_result = (array) unserialize((
string) $row->search_result);
406 if (strlen((
string) $row->checked)) {
407 $this->
checked = (array) unserialize((
string) $row->checked);
409 if (strlen((
string) $row->failed)) {
410 $this->failed = (array) unserialize((
string) $row->failed);
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));
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'] ??
''));
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'] ?? []));
static get(string $a_var)
appendToFailed(int $a_ref_id)
Append failed id.
setQuery(string $a_query)
getCheckedItems()
Get all checked items public.
switchSearchType(int $a_type)
switch to search type reads entries from database
static _getInstance(int $a_usr_id)
deleteCachedEntriesAnonymous()
readAnonymous()
Read from session for anonymous user.
getResultPageNumber()
get result page number
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
checked()
description: > Example for rendering a Checked Glyph.
getUrlEncodedQuery()
Urlencode query for further use in e.g glossariers (highlighting off search terms).
setResultPageNumber(int $a_number)
Set result page number.
setItemFilter(array $a_filter)
addResult(array $a_result_item)
Append result.
isAnonymous()
Check if current user is anonymous user.
setRoot(int $a_root)
set root node of search
isFailed(int $a_ref_id)
check if reference has failed access
setResults(array $a_results)
Set results.
const int LUCENE_USER_SEARCH
Class for storing search result.
appendToChecked(int $a_ref_id, int $a_obj_id)
setMimeFilter(array $a_filter)
static ilUserSearchCache $instance
setCreationFilter(array $a_filter)
__construct(int $a_usr_id)
Constructor.
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.