|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yaro\Jarboe\Table\Filters; |
|
4
|
|
|
|
|
5
|
|
|
class CheckboxFilter extends AbstractFilter |
|
6
|
|
|
{ |
|
7
|
|
|
const NO_INPUT_APPLIED = '__jarboe-no-search-input-applied'; |
|
8
|
|
|
|
|
9
|
|
|
private $checkedTitle; |
|
10
|
|
|
private $uncheckedTitle; |
|
11
|
|
|
private $desearchTitle; |
|
12
|
|
|
|
|
13
|
11 |
|
public function __construct() |
|
14
|
|
|
{ |
|
15
|
11 |
|
$this->checkedTitle = 'Checked'; |
|
16
|
11 |
|
$this->uncheckedTitle = 'Unchecked'; |
|
17
|
11 |
|
$this->desearchTitle = 'None'; |
|
18
|
11 |
|
} |
|
19
|
|
|
|
|
20
|
1 |
|
public function getValue($tableIdentifier) |
|
21
|
|
|
{ |
|
22
|
1 |
|
$key = sprintf('jarboe.%s.search.%s', $tableIdentifier, $this->field()->name()); |
|
23
|
|
|
|
|
24
|
1 |
|
return session($key, self::NO_INPUT_APPLIED); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @return string |
|
29
|
|
|
*/ |
|
30
|
1 |
|
public function getCheckedTitle(): string |
|
31
|
|
|
{ |
|
32
|
1 |
|
return $this->checkedTitle; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return string |
|
37
|
|
|
*/ |
|
38
|
1 |
|
public function getDesearchTitle(): string |
|
39
|
|
|
{ |
|
40
|
1 |
|
return $this->desearchTitle; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return string |
|
45
|
|
|
*/ |
|
46
|
1 |
|
public function getUncheckedTitle(): string |
|
47
|
|
|
{ |
|
48
|
1 |
|
return $this->uncheckedTitle; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
3 |
|
public function titles(string $checked = null, string $unchecked = null, string $desearch = null) |
|
52
|
|
|
{ |
|
53
|
3 |
|
if (!is_null($checked)) { |
|
54
|
1 |
|
$this->checkedTitle = $checked; |
|
55
|
|
|
} |
|
56
|
3 |
|
if (!is_null($unchecked)) { |
|
57
|
1 |
|
$this->uncheckedTitle = $unchecked; |
|
58
|
|
|
} |
|
59
|
3 |
|
if (!is_null($desearch)) { |
|
60
|
1 |
|
$this->desearchTitle = $desearch; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
3 |
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
1 |
|
public function render() |
|
67
|
|
|
{ |
|
68
|
1 |
|
return view('jarboe::crud.filters.checkbox', [ |
|
69
|
1 |
|
'filter' => $this, |
|
70
|
1 |
|
'value' => $this->value(), |
|
71
|
1 |
|
'desearch' => self::NO_INPUT_APPLIED, |
|
72
|
|
|
]); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
2 |
|
public function apply($query) |
|
76
|
|
|
{ |
|
77
|
2 |
|
$value = $this->value(); |
|
78
|
2 |
|
if ($value === self::NO_INPUT_APPLIED) { |
|
79
|
1 |
|
return; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
2 |
|
$query->where( |
|
83
|
2 |
|
$this->field()->name(), |
|
84
|
2 |
|
$this->sign, |
|
85
|
2 |
|
!$value && $this->field()->isNullable() ? null : $value |
|
86
|
|
|
); |
|
87
|
2 |
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|