-
-
Notifications
You must be signed in to change notification settings - Fork 828
/
SearchState.php
79 lines (68 loc) · 1.84 KB
/
SearchState.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Search;
use Closure;
use Flarum\Search\Filter\FilterInterface;
use Flarum\User\User;
class SearchState
{
/**
* @var FilterInterface[]
*/
protected array $activeFilters = [];
final public function __construct(
protected User $actor,
/**
* Whether this is a fulltext search or just filtering.
*/
protected bool $fulltextSearch,
/**
* An array of sort-order pairs, where the column
* is the key, and the order is the value. The order may be 'asc',
* 'desc', or an array of IDs to order by.
* Alternatively, a callable may be used.
*
* @var array<string, string|int[]>|Closure $defaultSort
*/
protected array|Closure $defaultSort = []
) {
}
public function getActor(): User
{
return $this->actor;
}
public function getDefaultSort(): array|Closure
{
return $this->defaultSort;
}
/**
* Set the default sort order for the search. This will only be applied if
* a sort order has not been specified in the search criteria.
*/
public function setDefaultSort(array|Closure $defaultSort): void
{
$this->defaultSort = $defaultSort;
}
public function isFulltextSearch(): bool
{
return $this->fulltextSearch;
}
/**
* Get a list of the filters that are active.
*
* @return FilterInterface[]
*/
public function getActiveFilters(): array
{
return $this->activeFilters;
}
public function addActiveFilter(FilterInterface $filter): void
{
$this->activeFilters[] = $filter;
}
}