|
1 | | -<?php |
2 | | - |
3 | | -namespace Rappasoft\LaravelLivewireTables\Traits\Core\QueryStrings; |
4 | | - |
5 | | -use Livewire\Attributes\Locked; |
6 | | - |
7 | | -trait HasQueryStringForFilter |
8 | | -{ |
9 | | - #[Locked] |
10 | | - public ?bool $queryStringStatusForFilter; |
11 | | - |
12 | | - protected ?string $queryStringAliasForFilter; |
13 | | - |
14 | | - protected function queryStringHasQueryStringForFilter(): array |
15 | | - { |
16 | | - return ($this->queryStringForFilterIsEnabled()) ? |
17 | | - [ |
18 | | - 'appliedFilters' => ['except' => null, 'history' => false, 'keep' => false, 'as' => $this->getQueryStringAliasForFilter()], |
19 | | - 'filterComponents' => ['except' => null, 'history' => false, 'keep' => false, 'as' => $this->getQueryStringAliasForFilter()], |
20 | | - ] : []; |
21 | | - } |
22 | | - |
23 | | - protected function setupQueryStringStatusForFilter(): void |
24 | | - { |
25 | | - if (! $this->hasQueryStringStatusForFilter()) { |
26 | | - $this->setQueryStringForFilterEnabled(); |
27 | | - } |
28 | | - } |
29 | | - |
30 | | - public function hasQueryStringStatusForFilter(): bool |
31 | | - { |
32 | | - return isset($this->queryStringStatusForFilter); |
33 | | - } |
34 | | - |
35 | | - public function getQueryStringStatusForFilter(): bool |
36 | | - { |
37 | | - return $this->queryStringStatusForFilter ?? true; |
38 | | - } |
39 | | - |
40 | | - public function queryStringForFilterIsEnabled(): bool |
41 | | - { |
42 | | - $this->setupQueryStringStatusForFilter(); |
43 | | - |
44 | | - return $this->getQueryStringStatusForFilter() && $this->filtersAreEnabled(); |
45 | | - } |
46 | | - |
47 | | - public function setQueryStringStatusForFilter(bool $status): self |
48 | | - { |
49 | | - $this->queryStringStatusForFilter = $status; |
50 | | - |
51 | | - return $this; |
52 | | - } |
53 | | - |
54 | | - public function setQueryStringForFilterEnabled(): self |
55 | | - { |
56 | | - $this->setQueryStringStatusForFilter(true); |
57 | | - |
58 | | - return $this; |
59 | | - } |
60 | | - |
61 | | - public function setQueryStringForFilterDisabled(): self |
62 | | - { |
63 | | - $this->setQueryStringStatusForFilter(false); |
64 | | - |
65 | | - return $this; |
66 | | - } |
67 | | - |
68 | | - public function hasQueryStringAliasForFilter(): bool |
69 | | - { |
70 | | - return isset($this->queryStringAliasForFilter); |
71 | | - } |
72 | | - |
73 | | - public function getQueryStringAliasForFilter(): string |
74 | | - { |
75 | | - return $this->queryStringAliasForFilter ?? $this->getQueryStringAlias().'-filters'; |
76 | | - } |
77 | | - |
78 | | - public function setQueryStringAliasForFilter(string $alias): self |
79 | | - { |
80 | | - $this->queryStringAliasForFilter = $alias; |
81 | | - |
82 | | - return $this; |
83 | | - } |
84 | | -} |
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Rappasoft\LaravelLivewireTables\Traits\Core\QueryStrings; |
| 4 | + |
| 5 | +use Livewire\Attributes\Locked; |
| 6 | + |
| 7 | +trait HasQueryStringForFilter |
| 8 | +{ |
| 9 | + #[Locked] |
| 10 | + public ?bool $queryStringStatusForFilter; |
| 11 | + |
| 12 | + protected ?string $queryStringAliasForFilter; |
| 13 | + |
| 14 | + protected function queryStringHasQueryStringForFilter(): array |
| 15 | + { |
| 16 | + return ($this->queryStringForFilterIsEnabled()) ? |
| 17 | + [ |
| 18 | + 'appliedFilters' => ['except' => null, 'history' => false, 'keep' => false, 'as' => $this->getQueryStringAliasForFilter()], |
| 19 | + 'filterComponents' => ['except' => null, 'history' => false, 'keep' => false, 'as' => $this->getQueryStringAliasForFilter()], |
| 20 | + ] : []; |
| 21 | + } |
| 22 | + |
| 23 | + protected function setupQueryStringStatusForFilter(): void |
| 24 | + { |
| 25 | + if (! $this->hasQueryStringStatusForFilter()) { |
| 26 | + $this->setQueryStringForFilterEnabled(); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + public function hasQueryStringStatusForFilter(): bool |
| 31 | + { |
| 32 | + return isset($this->queryStringStatusForFilter); |
| 33 | + } |
| 34 | + |
| 35 | + public function getQueryStringStatusForFilter(): bool |
| 36 | + { |
| 37 | + return $this->queryStringStatusForFilter ?? true; |
| 38 | + } |
| 39 | + |
| 40 | + public function queryStringForFilterIsEnabled(): bool |
| 41 | + { |
| 42 | + $this->setupQueryStringStatusForFilter(); |
| 43 | + |
| 44 | + return $this->getQueryStringStatusForFilter() && $this->filtersAreEnabled(); |
| 45 | + } |
| 46 | + |
| 47 | + public function setQueryStringStatusForFilter(bool $status): self |
| 48 | + { |
| 49 | + $this->queryStringStatusForFilter = $status; |
| 50 | + |
| 51 | + return $this; |
| 52 | + } |
| 53 | + |
| 54 | + public function setQueryStringForFilterEnabled(): self |
| 55 | + { |
| 56 | + $this->setQueryStringStatusForFilter(true); |
| 57 | + |
| 58 | + return $this; |
| 59 | + } |
| 60 | + |
| 61 | + public function setQueryStringForFilterDisabled(): self |
| 62 | + { |
| 63 | + $this->setQueryStringStatusForFilter(false); |
| 64 | + |
| 65 | + return $this; |
| 66 | + } |
| 67 | + |
| 68 | + public function hasQueryStringAliasForFilter(): bool |
| 69 | + { |
| 70 | + return isset($this->queryStringAliasForFilter); |
| 71 | + } |
| 72 | + |
| 73 | + public function getQueryStringAliasForFilter(): string |
| 74 | + { |
| 75 | + return $this->queryStringAliasForFilter ?? $this->getQueryStringAlias().'-filters'; |
| 76 | + } |
| 77 | + |
| 78 | + public function setQueryStringAliasForFilter(string $alias): self |
| 79 | + { |
| 80 | + $this->queryStringAliasForFilter = $alias; |
| 81 | + |
| 82 | + return $this; |
| 83 | + } |
| 84 | +} |
0 commit comments