3 declare(strict_types=1);
81 $this->db = $DIC->database();
88 $this->usr_id = $a_usr_id;
89 $this->search_type = self::DEFAULT_SEARCH;
96 return self::$instance;
98 return self::$instance =
new ilUserSearchCache($a_usr_id);
116 $this->search_type = $a_type;
129 return $this->search_result ?: array();
141 $this->search_result = $a_results;
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'];
164 $this->failed[$a_ref_id] = $a_ref_id;
172 return in_array($a_ref_id, $this->failed);
185 $this->checked[$a_ref_id] = $a_obj_id;
197 return array_key_exists($a_ref_id, $this->checked) and $this->checked[$a_ref_id];
207 return $this->checked ?: array();
219 $this->page_number = $a_number;
228 return $this->page_number ?: 1;
238 $this->query = $a_query;
246 if (is_array($this->query)) {
249 return $this->query ??
'';
260 return urlencode(str_replace(
'"',
'.',
$query[
'lom_content']));
262 return urlencode(str_replace(
'"',
'.', $this->
getQuery()));
270 $this->root = $a_root;
284 $this->item_filter = $a_filter;
294 $this->mime_filter = $a_filter;
304 $this->creation_filter = $a_filter;
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');
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)),
337 'usr_id' => array(
'integer', $this->usr_id),
338 'search_type' => array(
'integer', $this->search_type)
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)
356 $this->search_result = array();
357 $this->checked = array();
358 $this->failed = array();
368 $this->search_result = array();
369 $this->checked = array();
370 $this->failed = array();
377 public function delete():
bool 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');
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') .
')';
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())),
420 'usr_id' => array(
'integer',$this->usr_id),
421 'search_type' => array(
'integer',self::LAST_QUERY),
422 'query' => array(
'text',serialize($this->
getQuery()))
430 $session_usr_search = [];
440 $session_usr_search[self::LAST_QUERY][
'query'] = $this->
getQuery();
453 $this->failed = array();
454 $this->checked = array();
455 $this->search_result = array();
456 $this->page_number = 0;
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');
469 $this->search_result = (array) unserialize((
string) $row->search_result);
470 if (strlen((
string) $row->checked)) {
471 $this->checked = (array) unserialize((
string) $row->checked);
473 if (strlen((
string) $row->failed)) {
474 $this->failed = (array) unserialize((
string) $row->failed);
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));
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'] ??
''));
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'] ?? []));
static get(string $a_var)
setQuery($a_query)
set query
appendToFailed(int $a_ref_id)
Append failed id.
getCheckedItems()
Get all checked items public.
deleteCachedEntries()
delete cached entries
switchSearchType(int $a_type)
switch to search type reads entries from database
static _getInstance(int $a_usr_id)
deleteCachedEntriesAnonymous()
Delete cached entries for anonymous user.
readAnonymous()
Read from session for anonymous user.
getResultPageNumber()
get result page number
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.
Class for storing search result.
appendToChecked(int $a_ref_id, int $a_obj_id)
Append checked id.
setMimeFilter(array $a_filter)
static ilUserSearchCache $instance
setCreationFilter(array $a_filter)
__construct(int $a_usr_id)
Constructor.
isChecked(int $a_ref_id)
Check if reference was already checked.
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.