19declare(strict_types=1);
69 $this->db =
$DIC->database();
76 $this->usr_id = $a_usr_id;
104 $this->search_type = $a_type;
117 return $this->search_result ?: [];
129 $this->search_result = $a_results;
141 $this->search_result[$a_result_item[
'ref_id']][
'ref_id'] = $a_result_item[
'ref_id'];
142 $this->search_result[$a_result_item[
'ref_id']][
'obj_id'] = $a_result_item[
'obj_id'];
143 $this->search_result[$a_result_item[
'ref_id']][
'type'] = $a_result_item[
'type'];
152 $this->failed[$a_ref_id] = $a_ref_id;
160 return in_array($a_ref_id, $this->failed);
165 $this->
checked[$a_ref_id] = $a_obj_id;
170 return array_key_exists($a_ref_id, $this->
checked) and $this->
checked[$a_ref_id];
192 $this->page_number = $a_number;
201 return $this->page_number ?: 1;
206 $this->query = $a_query;
211 return $this->query ??
'';
219 return urlencode(str_replace(
'"',
'.', $this->
getQuery()));
227 $this->root = $a_root;
237 $this->item_filter = $a_filter;
247 $this->mime_filter = $a_filter;
257 $this->creation_filter = $a_filter;
267 $this->copyright_filter = $copyright_identifiers;
284 $query =
"SELECT COUNT(*) num FROM usr_search " .
285 "WHERE usr_id = " . $this->db->quote($this->usr_id,
'integer') .
" " .
286 "AND search_type = " . $this->db->quote($this->search_type,
'integer');
294 'search_result' => [
'clob', serialize([0])],
295 'checked' => [
'clob', serialize([0])],
296 'failed' => [
'clob', serialize([0])],
297 'page' => [
'integer', 0]
300 'usr_id' => [
'integer', $this->usr_id],
301 'search_type' => [
'integer', $this->search_type]
308 'search_result' => [
'clob', serialize([0])],
309 'checked' => [
'clob', serialize([0])],
310 'failed' => [
'clob', serialize([0])],
311 'page' => [
'integer', 0],
312 'usr_id' => [
'integer', $this->usr_id],
313 'search_type' => [
'integer', $this->search_type],
314 'query' => [
'clob', serialize(
'')]
320 $this->search_result = [];
328 $this->search_result = [];
335 public function delete():
bool
337 $query =
"DELETE FROM usr_search " .
338 "WHERE usr_id = " . $this->db->quote($this->usr_id,
'integer') .
" " .
339 "AND search_type = " . $this->db->quote($this->search_type,
'integer');
353 $query =
"DELETE FROM usr_search " .
354 "WHERE usr_id = " . $this->db->quote($this->usr_id,
'integer') .
" " .
355 "AND ( search_type = " . $this->db->quote($this->search_type,
'integer') .
' ' .
356 "OR search_type = " . $this->db->quote(self::LAST_QUERY,
'integer') .
')';
359 $this->db->insert(
'usr_search', [
360 'usr_id' => [
'integer', $this->usr_id],
361 'search_result' => [
'clob', serialize($this->search_result)],
362 'checked' => [
'clob', serialize($this->
checked)],
363 'failed' => [
'clob', serialize($this->failed)],
364 'page' => [
'integer', $this->page_number],
365 'search_type' => [
'integer', $this->search_type],
366 'query' => [
'clob', serialize($this->
getQuery())],
367 'root' => [
'integer', $this->
getRoot()],
368 'item_filter' => [
'text', serialize($this->
getItemFilter())],
369 'mime_filter' => [
'text', serialize($this->
getMimeFilter())],
379 'usr_id' => [
'integer', $this->usr_id],
380 'search_type' => [
'integer', self::LAST_QUERY],
381 'query' => [
'text', serialize($this->
getQuery())]
389 $session_usr_search = [];
408 $this->search_result = [];
409 $this->page_number = 0;
416 $query =
"SELECT * FROM usr_search " .
417 "WHERE usr_id = " . $this->db->quote($this->usr_id,
'integer') .
" " .
418 "AND search_type = " . $this->db->quote($this->search_type,
'integer');
422 $this->search_result = (array) unserialize((
string) $row->search_result);
423 if (strlen((
string) $row->checked)) {
424 $this->
checked = (array) unserialize((
string) $row->checked);
426 if (strlen((
string) $row->failed)) {
427 $this->failed = (array) unserialize((
string) $row->failed);
429 $this->page_number = (
int) $row->page;
430 $this->setQuery(unserialize((
string) $row->query));
431 $this->
setRoot((
int) $row->root);
432 $this->
setItemFilter((array) unserialize((
string) $row->item_filter));
434 if ($row->copyright_filter !==
null) {
447 $this->search_result = (array) ($usr_search_cache[$this->search_type][
'search_result'] ?? []);
448 $this->
checked = (array) ($usr_search_cache[$this->search_type][
'checked'] ?? []);
449 $this->failed = (array) ($usr_search_cache[$this->search_type][
'failed'] ?? []);
450 $this->page_number = (
int) ($usr_search_cache[$this->search_type][
'page_number'] ?? 1);
451 $this->
setQuery((
string) ($usr_search_cache[$this->search_type][
'query'] ??
''));
453 $this->
setItemFilter((array) ($usr_search_cache[$this->search_type][
'item_filter'] ?? []));
454 $this->
setMimeFilter((array) ($usr_search_cache[$this->search_type][
'mime_filter'] ?? []));
455 $this->
setCreationFilter((array) ($usr_search_cache[$this->search_type][
'creation_filter'] ?? []));
456 $this->
setCopyrightFilter(...(array) ($usr_search_cache[$this->search_type][
'copyright_filter'] ?? []));
static get(string $a_var)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
Class for storing search result.
appendToChecked(int $a_ref_id, int $a_obj_id)
setCreationFilter(array $a_filter)
deleteCachedEntriesAnonymous()
readAnonymous()
Read from session for anonymous user.
setItemFilter(array $a_filter)
getCheckedItems()
Get all checked items @access public.
getResultPageNumber()
get result page number
setResults(array $a_results)
Set results.
isFailed(int $a_ref_id)
check if reference has failed access
addResult(array $a_result_item)
Append result.
setMimeFilter(array $a_filter)
getUrlEncodedQuery()
Urlencode query for further use in e.g glossariers (highlighting off search terms).
setRoot(int $a_root)
set root node of search
switchSearchType(int $a_type)
switch to search type reads entries from database
static _getInstance(int $a_usr_id)
static ilUserSearchCache $instance
const int LUCENE_USER_SEARCH
setQuery(string $a_query)
appendToFailed(int $a_ref_id)
Append failed id.
__construct(int $a_usr_id)
Constructor.
setResultPageNumber(int $a_number)
Set result page number.
isAnonymous()
Check if current user is anonymous user.
setCopyrightFilter(string ... $copyright_identifiers)