1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sco\Admin\View\Filters; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Builder; |
6
|
|
|
use Sco\Admin\Contracts\View\Filters\FilterInterface; |
7
|
|
|
|
8
|
|
|
abstract class Filter implements FilterInterface |
9
|
|
|
{ |
10
|
|
|
protected $type; |
11
|
|
|
|
12
|
|
|
protected $value; |
13
|
|
|
|
14
|
|
|
protected $name; |
15
|
|
|
|
16
|
|
|
protected $title; |
17
|
|
|
|
18
|
|
|
protected $defaultValue; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Apply filter to the query. |
22
|
|
|
* |
23
|
|
|
* @param Builder $query |
24
|
|
|
*/ |
25
|
|
|
public function apply(Builder $query) |
26
|
|
|
{ |
27
|
|
|
// TODO |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function __construct($name, $title) |
31
|
|
|
{ |
32
|
|
|
$this->setName($name)->setTitle($title); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
public function getValue() |
39
|
|
|
{ |
40
|
|
|
if (is_null($this->value)) { |
41
|
|
|
return $this->getDefaultValue(); |
42
|
|
|
} |
43
|
|
|
return $this->value; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function setValue($value) |
50
|
|
|
{ |
51
|
|
|
$this->value = $value; |
52
|
|
|
|
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function getName() |
60
|
|
|
{ |
61
|
|
|
return $this->name; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function setName($name) |
68
|
|
|
{ |
69
|
|
|
$this->name = $name; |
70
|
|
|
|
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
public function getTitle() |
78
|
|
|
{ |
79
|
|
|
return $this->title; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
|
|
public function setTitle($title) |
86
|
|
|
{ |
87
|
|
|
$this->title = $title; |
88
|
|
|
|
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
|
|
public function getDefaultValue() |
96
|
|
|
{ |
97
|
|
|
return $this->defaultValue; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
|
|
public function setDefaultValue($defaultValue) |
104
|
|
|
{ |
105
|
|
|
$this->defaultValue = $defaultValue; |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function isActive() |
111
|
|
|
{ |
112
|
|
|
return !is_null($this->value); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function toArray() |
116
|
|
|
{ |
117
|
|
|
return [ |
118
|
|
|
'name' => $this->getName(), |
119
|
|
|
'title' => $this->getTitle(), |
120
|
|
|
'type' => $this->type, |
121
|
|
|
]; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function jsonSerialize() |
125
|
|
|
{ |
126
|
|
|
return $this->toArray(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function toJson($options = 0) |
130
|
|
|
{ |
131
|
|
|
return json_encode($this->jsonSerialize(), $options); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function __toString() |
135
|
|
|
{ |
136
|
|
|
return $this->toJson(); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|