1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\View; |
4
|
|
|
|
5
|
|
|
use ArrayIterator; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use Doctrine\Common\Collections\Collection; |
8
|
|
|
use LAG\AdminBundle\Configuration\ActionConfiguration; |
9
|
|
|
use LAG\AdminBundle\Configuration\AdminConfiguration; |
10
|
|
|
use LAG\AdminBundle\Field\FieldInterface; |
11
|
|
|
use LAG\AdminBundle\Menu\MenuItem; |
12
|
|
|
use Pagerfanta\Pagerfanta; |
13
|
|
|
use Symfony\Component\Form\FormInterface; |
14
|
|
|
|
15
|
|
|
class View implements ViewInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private $actionName; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var ActionConfiguration |
24
|
|
|
*/ |
25
|
|
|
private $configuration; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $adminName; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var array|Collection |
34
|
|
|
*/ |
35
|
|
|
private $entities = []; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var FieldInterface[] |
39
|
|
|
*/ |
40
|
|
|
private $fields; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var AdminConfiguration |
44
|
|
|
*/ |
45
|
|
|
private $adminConfiguration; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var bool |
49
|
|
|
*/ |
50
|
|
|
private $haveToPaginate = false; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var int |
54
|
|
|
*/ |
55
|
|
|
private $totalCount = 0; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var Pagerfanta |
59
|
|
|
*/ |
60
|
|
|
private $pager; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var FieldInterface[] |
64
|
|
|
*/ |
65
|
|
|
private $headers; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var MenuItem[] |
69
|
|
|
*/ |
70
|
|
|
private $menus; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var FormInterface[] |
74
|
|
|
*/ |
75
|
|
|
private $forms; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var string |
79
|
|
|
*/ |
80
|
|
|
private $base; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* View constructor. |
84
|
|
|
* |
85
|
|
|
* @param string $actionName |
86
|
|
|
* @param string $adminName |
87
|
|
|
* @param string $base |
88
|
|
|
* @param ActionConfiguration $configuration |
89
|
|
|
* @param AdminConfiguration $adminConfiguration |
90
|
|
|
* @param FieldInterface[] $fields |
91
|
|
|
* @param FormInterface[] $forms |
92
|
|
|
* @param array $menus |
93
|
|
|
* @param FieldInterface[] $headers |
94
|
|
|
*/ |
95
|
|
|
public function __construct( |
96
|
|
|
string $actionName, |
97
|
|
|
string $adminName, |
98
|
|
|
ActionConfiguration $configuration, |
99
|
|
|
AdminConfiguration $adminConfiguration, |
100
|
|
|
string $base = '', |
101
|
|
|
array $fields = [], |
102
|
|
|
array $forms = [], |
103
|
|
|
array $menus = [], |
104
|
|
|
array $headers = [] |
105
|
|
|
) { |
106
|
|
|
$this->actionName = $actionName; |
107
|
|
|
$this->configuration = $configuration; |
108
|
|
|
$this->adminName = $adminName; |
109
|
|
|
$this->fields = $fields; |
110
|
|
|
$this->adminConfiguration = $adminConfiguration; |
111
|
|
|
$this->headers = $headers; |
112
|
|
|
$this->menus = $menus; |
113
|
|
|
$this->forms = $forms; |
114
|
|
|
$this->base = $base; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function __call($name, $arguments) |
118
|
|
|
{ |
119
|
|
|
return $this->configuration->getParameter($name); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return ActionConfiguration |
124
|
|
|
*/ |
125
|
|
|
public function getConfiguration() |
126
|
|
|
{ |
127
|
|
|
return $this->configuration; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
public function getActionName() |
134
|
|
|
{ |
135
|
|
|
return $this->actionName; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return Collection|Pagerfanta|array |
140
|
|
|
*/ |
141
|
|
|
public function getEntities() |
142
|
|
|
{ |
143
|
|
|
return $this->entities; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param mixed $entities |
148
|
|
|
*/ |
149
|
|
|
public function setEntities($entities) |
150
|
|
|
{ |
151
|
|
|
if ($entities instanceof Pagerfanta) { |
152
|
|
|
$this->pager = $entities; |
153
|
|
|
$results = $entities->getCurrentPageResults(); |
154
|
|
|
|
155
|
|
|
if ($results instanceof ArrayIterator) { |
156
|
|
|
$results = $results->getArrayCopy(); |
157
|
|
|
} |
158
|
|
|
$this->entities = new ArrayCollection($results); |
|
|
|
|
159
|
|
|
$this->haveToPaginate = true; |
160
|
|
|
$this->totalCount = $entities->count(); |
161
|
|
|
} else { |
162
|
|
|
$this->entities = $entities; |
163
|
|
|
$this->totalCount = count($entities); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return string |
169
|
|
|
*/ |
170
|
|
|
public function getName() |
171
|
|
|
{ |
172
|
|
|
return $this->adminName; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @return FieldInterface[] |
177
|
|
|
*/ |
178
|
|
|
public function getFields() |
179
|
|
|
{ |
180
|
|
|
return $this->fields; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return AdminConfiguration |
185
|
|
|
*/ |
186
|
|
|
public function getAdminConfiguration() |
187
|
|
|
{ |
188
|
|
|
return $this->adminConfiguration; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @return bool |
193
|
|
|
*/ |
194
|
|
|
public function haveToPaginate() |
195
|
|
|
{ |
196
|
|
|
return $this->haveToPaginate; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return int |
201
|
|
|
*/ |
202
|
|
|
public function getTotalCount() |
203
|
|
|
{ |
204
|
|
|
return $this->totalCount; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @return Pagerfanta|null |
209
|
|
|
*/ |
210
|
|
|
public function getPager() |
211
|
|
|
{ |
212
|
|
|
return $this->pager; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return FieldInterface[] |
217
|
|
|
*/ |
218
|
|
|
public function getHeaders() |
219
|
|
|
{ |
220
|
|
|
return $this->headers; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @return MenuItem[] |
225
|
|
|
*/ |
226
|
|
|
public function getMenus(): array |
227
|
|
|
{ |
228
|
|
|
return $this->menus; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @return string |
233
|
|
|
*/ |
234
|
|
|
public function getTemplate(): string |
235
|
|
|
{ |
236
|
|
|
return $this->configuration->getParameter('template'); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @return FormInterface[] |
241
|
|
|
*/ |
242
|
|
|
public function getForms(): array |
243
|
|
|
{ |
244
|
|
|
return $this->forms; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @return string |
249
|
|
|
*/ |
250
|
|
|
public function getBase(): string |
251
|
|
|
{ |
252
|
|
|
return $this->base; |
253
|
|
|
} |
254
|
|
|
} |
255
|
|
|
|