|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dtc\GridBundle\Grid\Source; |
|
4
|
|
|
|
|
5
|
|
|
use Dtc\GridBundle\Grid\Column\AbstractGridColumn; |
|
6
|
|
|
use Dtc\GridBundle\Grid\Pager\GridSourcePager; |
|
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
8
|
|
|
|
|
9
|
|
|
abstract class AbstractGridSource implements GridSourceInterface |
|
10
|
|
|
{ |
|
11
|
|
|
protected $limit = 25; |
|
12
|
|
|
protected $offset = 0; |
|
13
|
|
|
protected $filter = array(); |
|
14
|
|
|
protected $orderBy = array(); |
|
15
|
|
|
protected $pager = array(); |
|
16
|
|
|
protected $id = 'grid'; |
|
17
|
|
|
protected $columns; |
|
18
|
|
|
protected $parameters; |
|
19
|
|
|
|
|
20
|
|
|
public function bind(Request $request) |
|
21
|
|
|
{ |
|
22
|
|
|
// Change limit, offset |
|
23
|
|
|
if ($limit = $request->get('limit')) { |
|
24
|
|
|
$this->limit = $limit; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
if ($page = $request->get('page')) { |
|
28
|
|
|
$this->offset = $this->limit * ($page - 1); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
if ($offset = $request->get('offset')) { |
|
32
|
|
|
$this->offset = $offset; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
if ($filter = $request->get('filter')) { |
|
36
|
|
|
$this->filter = $filter; |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
if ($sortColumn = $request->get('sort_column')) { |
|
40
|
|
|
$sortOrder = $request->get('sort_order'); |
|
41
|
|
|
$sortOrder = strtoupper($sortOrder); |
|
42
|
|
|
|
|
43
|
|
|
$this->orderBy[$sortColumn] = $sortOrder; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if ($orderBy = $request->get('order')) { |
|
47
|
|
|
$this->orderBy = $orderBy; |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function getDefaultSort() |
|
52
|
|
|
{ |
|
53
|
|
|
return null; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getId() |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->id; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
private $divId = null; |
|
62
|
|
|
|
|
63
|
|
|
public function getDivId() |
|
64
|
|
|
{ |
|
65
|
|
|
if (!$this->divId) { |
|
66
|
|
|
$this->divId = preg_replace('/[^a-zA-Z0-9\-]/', '', $this->id); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return $this->divId; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function setId($value) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->id = $value; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getColumns() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->columns; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function setColumns($columns) |
|
83
|
|
|
{ |
|
84
|
|
|
/** @var AbstractGridColumn $col */ |
|
85
|
|
|
foreach ($columns as $col) { |
|
86
|
|
|
$this->columns[$col->getField()] = $col; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function removeColumn($field) |
|
|
|
|
|
|
91
|
|
|
{ |
|
92
|
|
|
$this->removeColumns(func_get_args()); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function selectColumns(array $fields) |
|
96
|
|
|
{ |
|
97
|
|
|
$selectedCols = array(); |
|
98
|
|
|
foreach ($fields as $field) { |
|
99
|
|
|
if (isset($this->columns[$field])) { |
|
100
|
|
|
$selectedCols[$field] = $this->columns[$field]; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$this->columns = $selectedCols; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function removeColumns(array $fields) |
|
108
|
|
|
{ |
|
109
|
|
|
foreach ($fields as $field) { |
|
110
|
|
|
unset($this->columns[$field]); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function getPager() |
|
115
|
|
|
{ |
|
116
|
|
|
if (!$this->pager) { |
|
|
|
|
|
|
117
|
|
|
$this->pager = new GridSourcePager($this); |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return $this->pager; |
|
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @return $limit |
|
|
|
|
|
|
125
|
|
|
*/ |
|
126
|
|
|
public function getLimit() |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->limit; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @param int $limit |
|
133
|
|
|
*/ |
|
134
|
|
|
public function setLimit($limit) |
|
135
|
|
|
{ |
|
136
|
|
|
$this->limit = $limit; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @return $offset |
|
|
|
|
|
|
141
|
|
|
*/ |
|
142
|
|
|
public function getOffset() |
|
143
|
|
|
{ |
|
144
|
|
|
return $this->offset; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @param int $offset |
|
149
|
|
|
*/ |
|
150
|
|
|
public function setOffset($offset) |
|
151
|
|
|
{ |
|
152
|
|
|
$this->offset = $offset; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @return $filter |
|
|
|
|
|
|
157
|
|
|
*/ |
|
158
|
|
|
public function getFilter() |
|
159
|
|
|
{ |
|
160
|
|
|
return $this->filter; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @param $filter |
|
165
|
|
|
*/ |
|
166
|
|
|
public function setFilter($filter) |
|
167
|
|
|
{ |
|
168
|
|
|
$this->filter = $filter; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @return $orderBy |
|
|
|
|
|
|
173
|
|
|
*/ |
|
174
|
|
|
public function getOrderBy() |
|
175
|
|
|
{ |
|
176
|
|
|
return $this->orderBy; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @param $orderBy |
|
181
|
|
|
*/ |
|
182
|
|
|
public function setOrderBy($orderBy) |
|
183
|
|
|
{ |
|
184
|
|
|
$this->orderBy = $orderBy; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
public function getLastModified() |
|
188
|
|
|
{ |
|
189
|
|
|
return null; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
public function getParameter($key) |
|
193
|
|
|
{ |
|
194
|
|
|
return $this->parameters[$key]; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
public function setParameter($key, $value) |
|
198
|
|
|
{ |
|
199
|
|
|
$this->parameters[$key] = $value; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* @return $parameters |
|
|
|
|
|
|
204
|
|
|
*/ |
|
205
|
|
|
public function getParameters() |
|
206
|
|
|
{ |
|
207
|
|
|
return $this->parameters; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* @param $parameters |
|
212
|
|
|
*/ |
|
213
|
|
|
public function setParameters($parameters) |
|
214
|
|
|
{ |
|
215
|
|
|
$this->parameters = $parameters; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* @return bool Returns true if this GridSource has an ID or false otherise |
|
220
|
|
|
*/ |
|
221
|
|
|
public function hasIdColumn() |
|
222
|
|
|
{ |
|
223
|
|
|
return false; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* @param $id |
|
228
|
|
|
* |
|
229
|
|
|
* @return null|mixed returns the row identified by Id if found |
|
230
|
|
|
*/ |
|
231
|
|
|
public function find($id) |
|
232
|
|
|
{ |
|
233
|
|
|
return null; |
|
234
|
|
|
} |
|
235
|
|
|
} |
|
236
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.