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
|
|
|
public function operator($operator = null) |
44
|
|
|
{ |
45
|
|
|
if (is_null($operator)) { |
46
|
|
|
return $this->operator; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$this->operator = $operator; |
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getColumn() |
54
|
|
|
{ |
55
|
|
|
return $this->column; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function column() |
59
|
|
|
{ |
60
|
|
|
return $this->getColumn(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function getLabel() |
64
|
|
|
{ |
65
|
|
|
return $this->label; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function setLabel($label) |
69
|
|
|
{ |
70
|
|
|
$this->label = $label; |
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function label($label = null) |
75
|
|
|
{ |
76
|
|
|
if (is_null($label)) { |
77
|
|
|
return $this->label; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$this->label = $label; |
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return callable |
86
|
|
|
*/ |
87
|
|
|
public function getFilteringFunc() |
88
|
|
|
{ |
89
|
|
|
return $this->filtering_func; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param callable $func ($value, $data_provider) |
94
|
|
|
* @return $this |
95
|
|
|
*/ |
96
|
|
|
public function setFilteringFunc($func) |
97
|
|
|
{ |
98
|
|
|
$this->filtering_func = $func; |
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param callable $func ($value, $data_provider) |
104
|
|
|
* @return $this |
105
|
|
|
*/ |
106
|
|
|
public function filteringFunc($func = null) |
107
|
|
|
{ |
108
|
|
|
if (is_null($func)) { |
109
|
|
|
return $this->filtering_func; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$this->filtering_func = $func; |
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function setTemplate($template) |
117
|
|
|
{ |
118
|
|
|
$this->template = $template; |
119
|
|
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
|
public function getTemplate() |
126
|
|
|
{ |
127
|
|
|
return $this->template; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function template($template = null) |
131
|
|
|
{ |
132
|
|
|
if (is_null($template)) { |
133
|
|
|
return $this->template; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
$this->template = $template; |
137
|
|
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
|
141
|
|
|
public function getDefaultValue() |
142
|
|
|
{ |
143
|
|
|
return $this->default_value; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function setDefaultValue($value) |
147
|
|
|
{ |
148
|
|
|
$this->default_value = $value; |
149
|
|
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function defaultValue($value = null) |
153
|
|
|
{ |
154
|
|
|
if (is_null($value)) { |
155
|
|
|
return $this->default_value; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
$this->default_value = $value; |
159
|
|
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function getName() |
163
|
|
|
{ |
164
|
|
|
if (null === $this->name && $this->column) { |
165
|
|
|
$this->name = $this->column->getName(); |
166
|
|
|
} |
167
|
|
|
return $this->name; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
public function setName($name) |
171
|
|
|
{ |
172
|
|
|
$this->name = $name; |
173
|
|
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function name($name = null) |
177
|
|
|
{ |
178
|
|
|
if (is_null($name)) { |
179
|
|
|
return $this->getName(); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
$this->name = $name; |
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function attach(FieldConfig $column) |
187
|
|
|
{ |
188
|
|
|
$this->column = $column; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
public function getId() |
192
|
|
|
{ |
193
|
|
|
return $this->getName() . '-' . $this->getOperator(); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function id() |
197
|
|
|
{ |
198
|
|
|
return $this->getId(); |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|