|
1 | | -<?php |
2 | | - |
3 | | -namespace Rappasoft\LaravelLivewireTables\Traits\Core\QueryStrings; |
4 | | - |
5 | | -use Livewire\Attributes\Locked; |
6 | | - |
7 | | -trait HasQueryStringForSort |
8 | | -{ |
9 | | - #[Locked] |
10 | | - public ?bool $queryStringStatusForSort; |
11 | | - |
12 | | - protected ?string $queryStringAliasForSort; |
13 | | - |
14 | | - protected function queryStringHasQueryStringForSort(): array |
15 | | - { |
16 | | - return ($this->queryStringForSortEnabled() && $this->sortingIsEnabled()) ? ['sorts' => ['except' => null, 'history' => false, 'keep' => false, 'as' => $this->getQueryStringAliasForSort()]] : []; |
17 | | - |
18 | | - } |
19 | | - |
20 | | - public function setupQueryStringStatusForSort(): void |
21 | | - { |
22 | | - if (! $this->hasQueryStringStatusForSort()) { |
23 | | - $this->setQueryStringForSortEnabled(); |
24 | | - } |
25 | | - } |
26 | | - |
27 | | - public function hasQueryStringStatusForSort(): bool |
28 | | - { |
29 | | - return isset($this->queryStringStatusForSort); |
30 | | - } |
31 | | - |
32 | | - public function getQueryStringStatusForSort(): bool |
33 | | - { |
34 | | - return $this->queryStringStatusForSort ?? true; |
35 | | - } |
36 | | - |
37 | | - public function queryStringForSortEnabled(): bool |
38 | | - { |
39 | | - $this->setupQueryStringStatusForSort(); |
40 | | - |
41 | | - return $this->getQueryStringStatusForSort() && $this->sortingIsEnabled(); |
42 | | - } |
43 | | - |
44 | | - public function setQueryStringStatusForSort(bool $status): self |
45 | | - { |
46 | | - $this->queryStringStatusForSort = $status; |
47 | | - |
48 | | - return $this; |
49 | | - } |
50 | | - |
51 | | - public function setQueryStringForSortEnabled(): self |
52 | | - { |
53 | | - return $this->setQueryStringStatusForSort(true); |
54 | | - } |
55 | | - |
56 | | - public function setQueryStringForSortDisabled(): self |
57 | | - { |
58 | | - return $this->setQueryStringStatusForSort(false); |
59 | | - } |
60 | | - |
61 | | - public function hasQueryStringAliasForSort(): bool |
62 | | - { |
63 | | - return isset($this->queryStringAliasForSort); |
64 | | - } |
65 | | - |
66 | | - public function getQueryStringAliasForSort(): string |
67 | | - { |
68 | | - return $this->queryStringAliasForSort ?? $this->getQueryStringAlias().'-sorts'; |
69 | | - } |
70 | | - |
71 | | - public function setQueryStringAliasForSort(string $alias): self |
72 | | - { |
73 | | - $this->queryStringAliasForSort = $alias; |
74 | | - |
75 | | - return $this; |
76 | | - } |
77 | | -} |
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Rappasoft\LaravelLivewireTables\Traits\Core\QueryStrings; |
| 4 | + |
| 5 | +trait HasQueryStringForSort |
| 6 | +{ |
| 7 | + |
| 8 | + protected function queryStringHasQueryStringForSort(): array |
| 9 | + { |
| 10 | + return ($this->queryStringForSortEnabled() && $this->sortingIsEnabled()) ? ['sorts' => ['except' => null, 'history' => false, 'keep' => false, 'as' => $this->getQueryStringAliasForSort()]] : []; |
| 11 | + |
| 12 | + } |
| 13 | + public function setupQueryStringStatusForSort(): void |
| 14 | + { |
| 15 | + if (! $this->hasQueryStringStatusForSort()) { |
| 16 | + $this->setQueryStringForSortEnabled(); |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | + protected function hasQueryStringStatusForSort(): bool |
| 21 | + { |
| 22 | + return $this->hasQueryStringConfigStatus('sorts'); |
| 23 | + } |
| 24 | + |
| 25 | + protected function getQueryStringStatusForSort(): bool |
| 26 | + { |
| 27 | + return $this->getQueryStringConfigStatus("sorts"); |
| 28 | + } |
| 29 | + |
| 30 | + protected function queryStringForSortEnabled(): bool |
| 31 | + { |
| 32 | + $this->setupQueryStringStatusForSort(); |
| 33 | + |
| 34 | + return $this->getQueryStringStatusForSort() && $this->sortingIsEnabled(); |
| 35 | + } |
| 36 | + |
| 37 | + public function setQueryStringStatusForSort(bool $status): self |
| 38 | + { |
| 39 | + return $this->setQueryStringConfigStatus("sorts", $status); |
| 40 | + } |
| 41 | + |
| 42 | + public function setQueryStringForSortEnabled(): self |
| 43 | + { |
| 44 | + return $this->setQueryStringStatusForSort(true); |
| 45 | + } |
| 46 | + |
| 47 | + public function setQueryStringForSortDisabled(): self |
| 48 | + { |
| 49 | + return $this->setQueryStringStatusForSort(false); |
| 50 | + } |
| 51 | + |
| 52 | + protected function hasQueryStringAliasForSort(): bool |
| 53 | + { |
| 54 | + return $this->hasQueryStringConfigAlias('sorts'); |
| 55 | + } |
| 56 | + |
| 57 | + protected function getQueryStringAliasForSort(): string |
| 58 | + { |
| 59 | + return $this->getQueryStringConfigAlias("sorts"); |
| 60 | + } |
| 61 | + |
| 62 | + public function setQueryStringAliasForSort(string $alias): self |
| 63 | + { |
| 64 | + return $this->setQueryStringConfigAlias("sorts", $alias); |
| 65 | + } |
| 66 | +} |
0 commit comments