|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\View; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
6
|
|
|
use Doctrine\Common\Collections\Collection; |
|
7
|
|
|
use LAG\AdminBundle\Action\Configuration\ActionConfiguration; |
|
8
|
|
|
use LAG\AdminBundle\Admin\Configuration\AdminConfiguration; |
|
9
|
|
|
use LAG\AdminBundle\Field\FieldInterface; |
|
10
|
|
|
use Pagerfanta\Pagerfanta; |
|
11
|
|
|
|
|
12
|
|
|
class View implements ViewInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
private $actionName; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var ActionConfiguration |
|
21
|
|
|
*/ |
|
22
|
|
|
private $configuration; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
private $adminName; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var array|Collection |
|
31
|
|
|
*/ |
|
32
|
|
|
private $entities = []; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var FieldInterface[] |
|
36
|
|
|
*/ |
|
37
|
|
|
private $fields; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var AdminConfiguration |
|
41
|
|
|
*/ |
|
42
|
|
|
private $adminConfiguration; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var bool |
|
46
|
|
|
*/ |
|
47
|
|
|
private $haveToPaginate = false; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var int |
|
51
|
|
|
*/ |
|
52
|
|
|
private $totalCount = 0; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var Pagerfanta |
|
56
|
|
|
*/ |
|
57
|
|
|
private $pager; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* View constructor. |
|
61
|
|
|
* |
|
62
|
|
|
* @param $actionName |
|
63
|
|
|
* @param $adminName |
|
64
|
|
|
* @param ActionConfiguration $configuration |
|
65
|
|
|
* @param AdminConfiguration $adminConfiguration |
|
66
|
|
|
* @param array $fields |
|
67
|
|
|
*/ |
|
68
|
|
|
public function __construct( |
|
69
|
|
|
$actionName, |
|
70
|
|
|
$adminName, |
|
71
|
|
|
ActionConfiguration $configuration, |
|
72
|
|
|
AdminConfiguration $adminConfiguration, |
|
73
|
|
|
array $fields = [] |
|
74
|
|
|
) { |
|
75
|
|
|
$this->actionName = $actionName; |
|
76
|
|
|
$this->configuration = $configuration; |
|
77
|
|
|
$this->adminName = $adminName; |
|
78
|
|
|
$this->fields = $fields; |
|
79
|
|
|
$this->adminConfiguration = $adminConfiguration; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return ActionConfiguration |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getConfiguration() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->configuration; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return string |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getActionName() |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->actionName; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return array |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getEntities() |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->entities; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param $entities |
|
108
|
|
|
*/ |
|
109
|
|
|
public function setEntities($entities) |
|
110
|
|
|
{ |
|
111
|
|
|
if ($entities instanceof Pagerfanta) { |
|
112
|
|
|
$this->pager = $entities; |
|
113
|
|
|
$this->entities = new ArrayCollection($entities->getCurrentPageResults()); |
|
|
|
|
|
|
114
|
|
|
$this->haveToPaginate = true; |
|
115
|
|
|
$this->totalCount = $entities->count(); |
|
116
|
|
|
} else { |
|
117
|
|
|
$this->entities = $entities; |
|
118
|
|
|
$this->totalCount = count($entities); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @return string |
|
124
|
|
|
*/ |
|
125
|
|
|
public function getName() |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->adminName; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @return FieldInterface[] |
|
132
|
|
|
*/ |
|
133
|
|
|
public function getFields() |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->fields; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @return AdminConfiguration |
|
140
|
|
|
*/ |
|
141
|
|
|
public function getAdminConfiguration() |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->adminConfiguration; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @return bool |
|
148
|
|
|
*/ |
|
149
|
|
|
public function haveToPaginate() |
|
150
|
|
|
{ |
|
151
|
|
|
return $this->haveToPaginate; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @return int |
|
156
|
|
|
*/ |
|
157
|
|
|
public function getTotalCount() |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->totalCount; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @return Pagerfanta|null |
|
164
|
|
|
*/ |
|
165
|
|
|
public function getPager() |
|
166
|
|
|
{ |
|
167
|
|
|
return $this->pager; |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.