1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Pfilsx\DataGrid\Grid\Columns; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Pfilsx\DataGrid\Grid\DataGrid; |
8
|
|
|
use Pfilsx\DataGrid\Grid\Filters\AbstractFilter; |
9
|
|
|
|
10
|
|
|
abstract class AbstractColumn |
11
|
|
|
{ |
12
|
|
|
protected $attributes; |
13
|
|
|
|
14
|
|
|
protected $value = null; |
15
|
|
|
|
16
|
|
|
protected $label = ''; |
17
|
|
|
/** |
18
|
|
|
* @var AbstractFilter|null |
19
|
|
|
*/ |
20
|
|
|
protected $filter; |
21
|
|
|
|
22
|
|
|
protected $filterValue; |
23
|
|
|
|
24
|
|
|
protected $sort = false; |
25
|
|
|
|
26
|
|
|
protected $isVisible = true; |
27
|
|
|
|
28
|
|
|
protected $template; |
29
|
|
|
/** |
30
|
|
|
* @var array |
31
|
|
|
* |
32
|
|
|
*/ |
33
|
|
|
protected $container; |
34
|
|
|
|
35
|
|
|
public function __construct(array $container, array $config = []) |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
$this->container = $container; |
39
|
|
|
$this->setConfiguration($config); |
40
|
|
|
$this->checkConfiguration(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function setConfiguration($config) |
44
|
|
|
{ |
45
|
|
|
foreach ($config as $key => $value) { |
46
|
|
|
$setter = 'set' . ucfirst($key); |
47
|
|
|
if (method_exists($this, $setter)) { |
48
|
|
|
$this->$setter($value); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function checkConfiguration() |
54
|
|
|
{ |
55
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getAttributes() |
59
|
|
|
{ |
60
|
|
|
return $this->attributes; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function hasAttributes() |
64
|
|
|
{ |
65
|
|
|
return !empty($this->attributes); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param mixed $attributes |
70
|
|
|
*/ |
71
|
|
|
protected function setAttributes($attributes): void |
72
|
|
|
{ |
73
|
|
|
$this->attributes = $attributes; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return mixed |
78
|
|
|
*/ |
79
|
|
|
public function getValue() |
80
|
|
|
{ |
81
|
|
|
return $this->value; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param mixed $value |
86
|
|
|
*/ |
87
|
|
|
protected function setValue($value): void |
88
|
|
|
{ |
89
|
|
|
$this->value = $value; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function getLabel(): string |
96
|
|
|
{ |
97
|
|
|
return $this->label; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string $label |
102
|
|
|
*/ |
103
|
|
|
protected function setLabel(string $label): void |
104
|
|
|
{ |
105
|
|
|
$this->label = $label; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function hasFilter() |
109
|
|
|
{ |
110
|
|
|
return is_subclass_of($this->filter, AbstractFilter::class); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function getFilter() |
114
|
|
|
{ |
115
|
|
|
return $this->filter; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function setFilter(array $filter) |
119
|
|
|
{ |
120
|
|
|
$filterClass = $filter['class']; |
121
|
|
|
unset($filter['class']); |
122
|
|
|
$filter['template'] = $this->template; |
123
|
|
|
/** @var AbstractFilter $filterObj */ |
124
|
|
|
$this->filter = new $filterClass($this->container, $filter); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
public function hasSort() |
129
|
|
|
{ |
130
|
|
|
return $this->sort !== false && !empty($this->attribute); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function setSort($direction) |
134
|
|
|
{ |
135
|
|
|
$this->sort = $direction; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function getSort() |
139
|
|
|
{ |
140
|
|
|
return $this->sort; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function getAttribute() |
144
|
|
|
{ |
145
|
|
|
return null; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function getFilterValue() |
149
|
|
|
{ |
150
|
|
|
return $this->filterValue; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function setFilterValue($value) |
154
|
|
|
{ |
155
|
|
|
$this->filterValue = $value; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
abstract public function getHeadContent(); |
159
|
|
|
|
160
|
|
|
abstract public function getFilterContent(); |
161
|
|
|
|
162
|
|
|
abstract public function getCellContent($entity); |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @return mixed |
166
|
|
|
*/ |
167
|
|
|
public function getTemplate() |
168
|
|
|
{ |
169
|
|
|
return $this->template; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param mixed $template |
174
|
|
|
*/ |
175
|
|
|
public function setTemplate($template): void |
176
|
|
|
{ |
177
|
|
|
$this->template = $template; |
178
|
|
|
if ($this->hasFilter()) { |
179
|
|
|
$this->filter->setTemplate($template); |
|
|
|
|
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return bool |
185
|
|
|
*/ |
186
|
|
|
public function isVisible(): bool |
187
|
|
|
{ |
188
|
|
|
return $this->isVisible; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @param bool $visibility |
193
|
|
|
*/ |
194
|
|
|
protected function setVisible(bool $visibility): void |
195
|
|
|
{ |
196
|
|
|
$this->isVisible = $visibility; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
} |
200
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.