1
|
|
|
<?php |
2
|
|
|
namespace Nayjest\Grids; |
3
|
|
|
|
4
|
|
|
class FilterConfig |
5
|
|
|
{ |
6
|
|
|
const OPERATOR_LIKE = 'like'; |
7
|
|
|
const OPERATOR_EQ = 'eq'; |
8
|
|
|
const OPERATOR_NOT_EQ = 'n_eq'; |
9
|
|
|
const OPERATOR_GT = 'gt'; |
10
|
|
|
const OPERATOR_LS = 'lt'; |
11
|
|
|
const OPERATOR_LSE = 'ls_e'; |
12
|
|
|
const OPERATOR_GTE = 'gt_e'; |
13
|
|
|
const OPERATOR_IN = 'in'; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
/** @var FieldConfig */ |
17
|
|
|
protected $column; |
18
|
|
|
|
19
|
|
|
protected $operator = FilterConfig::OPERATOR_EQ; |
20
|
|
|
|
21
|
|
|
protected $template = '*.input'; |
22
|
|
|
|
23
|
|
|
protected $default_value; |
24
|
|
|
|
25
|
|
|
protected $name; |
26
|
|
|
|
27
|
|
|
protected $label; |
28
|
|
|
|
29
|
|
|
/** @var callable */ |
30
|
|
|
protected $filtering_func; |
31
|
|
|
|
32
|
|
|
public function getOperator() |
33
|
|
|
{ |
34
|
|
|
return $this->operator; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function setOperator($operator) |
38
|
|
|
{ |
39
|
|
|
$this->operator = $operator; |
40
|
|
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return self|mixed |
45
|
|
|
*/ |
46
|
|
|
public function operator($operator = null) |
47
|
|
|
{ |
48
|
|
|
if (is_null($operator)) { |
49
|
|
|
return $this->operator; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$this->operator = $operator; |
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getColumn() |
57
|
|
|
{ |
58
|
|
|
return $this->column; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return self|mixed |
63
|
|
|
*/ |
64
|
|
|
public function column() |
65
|
|
|
{ |
66
|
|
|
return $this->getColumn(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getLabel() |
70
|
|
|
{ |
71
|
|
|
return $this->label; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function setLabel($label) |
75
|
|
|
{ |
76
|
|
|
$this->label = $label; |
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return self|mixed |
82
|
|
|
*/ |
83
|
|
|
public function label($label = null) |
84
|
|
|
{ |
85
|
|
|
if (is_null($label)) { |
86
|
|
|
return $this->label; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$this->label = $label; |
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return callable |
95
|
|
|
*/ |
96
|
|
|
public function getFilteringFunc() |
97
|
|
|
{ |
98
|
|
|
return $this->filtering_func; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param callable $func ($value, $data_provider) |
103
|
|
|
* @return $this |
104
|
|
|
*/ |
105
|
|
|
public function setFilteringFunc($func) |
106
|
|
|
{ |
107
|
|
|
$this->filtering_func = $func; |
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param callable $func ($value, $data_provider) |
113
|
|
|
* @return $this |
114
|
|
|
*/ |
115
|
|
|
public function filteringFunc($func = null) |
116
|
|
|
{ |
117
|
|
|
if (is_null($func)) { |
118
|
|
|
return $this->filtering_func; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
$this->filtering_func = $func; |
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function setTemplate($template) |
126
|
|
|
{ |
127
|
|
|
$this->template = $template; |
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
public function getTemplate() |
135
|
|
|
{ |
136
|
|
|
return $this->template; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return self|mixed |
141
|
|
|
*/ |
142
|
|
|
public function template($template = null) |
143
|
|
|
{ |
144
|
|
|
if (is_null($template)) { |
145
|
|
|
return $this->template; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
$this->template = $template; |
149
|
|
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return self|mixed |
155
|
|
|
*/ |
156
|
|
|
public function getDefaultValue() |
157
|
|
|
{ |
158
|
|
|
return $this->default_value; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function setDefaultValue($value) |
162
|
|
|
{ |
163
|
|
|
$this->default_value = $value; |
164
|
|
|
return $this; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function defaultValue($value = null) |
168
|
|
|
{ |
169
|
|
|
if (is_null($value)) { |
170
|
|
|
return $this->default_value; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$this->default_value = $value; |
174
|
|
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function getName() |
178
|
|
|
{ |
179
|
|
|
if (null === $this->name && $this->column) { |
180
|
|
|
$this->name = $this->column->getName(); |
181
|
|
|
} |
182
|
|
|
return $this->name; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function setName($name) |
186
|
|
|
{ |
187
|
|
|
$this->name = $name; |
188
|
|
|
return $this; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @return self|mixed |
193
|
|
|
*/ |
194
|
|
|
public function name($name = null) |
195
|
|
|
{ |
196
|
|
|
if (is_null($name)) { |
197
|
|
|
return $this->getName(); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
$this->name = $name; |
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function attach(FieldConfig $column) |
205
|
|
|
{ |
206
|
|
|
$this->column = $column; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function getId() |
210
|
|
|
{ |
211
|
|
|
return $this->getName() . '-' . $this->getOperator(); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @return string |
216
|
|
|
*/ |
217
|
|
|
public function id() |
218
|
|
|
{ |
219
|
|
|
return $this->getId(); |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|