1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\FormBundle\AdminList; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManager; |
6
|
|
|
use Doctrine\ORM\QueryBuilder; |
7
|
|
|
use Kunstmaan\AdminBundle\Entity\EntityInterface; |
8
|
|
|
use Kunstmaan\AdminListBundle\AdminList\Configurator\AbstractDoctrineORMAdminListConfigurator; |
9
|
|
|
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\DateFilterType; |
10
|
|
|
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\StringFilterType; |
11
|
|
|
use Kunstmaan\NodeBundle\Entity\NodeTranslation; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Adminlist configuration to list all the form submissions for a given NodeTranslation |
15
|
|
|
*/ |
16
|
|
|
class FormSubmissionAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var NodeTranslation |
20
|
|
|
*/ |
21
|
|
|
protected $nodeTranslation; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var bool |
25
|
|
|
*/ |
26
|
|
|
protected $deletableFormsubmissions; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param EntityManager $em The entity manager |
30
|
|
|
* @param NodeTranslation $nodeTranslation The node translation |
31
|
|
|
* @param bool $deletableFormsubmissions Can formsubmissions be deleted or not |
32
|
|
|
*/ |
33
|
5 |
|
public function __construct(EntityManager $em, $nodeTranslation, $deletableFormsubmissions = false) |
34
|
|
|
{ |
35
|
5 |
|
parent::__construct($em); |
36
|
5 |
|
$this->nodeTranslation = $nodeTranslation; |
37
|
5 |
|
$this->deletableFormsubmissions = $deletableFormsubmissions; |
38
|
5 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Configure the fields you can filter on |
42
|
|
|
*/ |
43
|
1 |
|
public function buildFilters() |
44
|
|
|
{ |
45
|
1 |
|
$builder = $this->getFilterBuilder(); |
46
|
1 |
|
$builder->add('created', new DateFilterType('created'), 'Date') |
47
|
1 |
|
->add('lang', new StringFilterType('lang'), 'Language') |
48
|
1 |
|
->add('ipAddress', new StringFilterType('ipAddress'), 'IP Address'); |
49
|
1 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Configure the visible columns |
53
|
|
|
*/ |
54
|
1 |
|
public function buildFields() |
55
|
|
|
{ |
56
|
1 |
|
$this->addField('created', 'kuma_form.submission.list.header.created', true) |
|
|
|
|
57
|
1 |
|
->addField('lang', 'kuma_form.submission.list.header.language', true) |
|
|
|
|
58
|
1 |
|
->addField('ipAddress', 'kuma_form.submission.list.header.ip_address', true); |
|
|
|
|
59
|
1 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Add a view action. |
63
|
|
|
*/ |
64
|
1 |
|
public function buildItemActions() |
65
|
|
|
{ |
66
|
1 |
|
$nodeTranslation = $this->nodeTranslation; |
67
|
|
|
$create_route = function (EntityInterface $item) use ($nodeTranslation) { |
68
|
1 |
|
$arr = array('path' => 'KunstmaanFormBundle_formsubmissions_list_edit', 'params' => array('nodeTranslationId' => $nodeTranslation->getId(), 'submissionId' => $item->getId())); |
69
|
|
|
|
70
|
1 |
|
return $arr; |
71
|
1 |
|
}; |
72
|
1 |
|
$ia = new \Kunstmaan\AdminListBundle\AdminList\ItemAction\SimpleItemAction($create_route, 'eye', 'View'); |
73
|
1 |
|
$this->addItemAction($ia); |
74
|
1 |
|
} |
75
|
|
|
|
76
|
1 |
|
public function canEdit($item) |
77
|
|
|
{ |
78
|
1 |
|
return false; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Return the url to edit the given $item |
83
|
|
|
* |
84
|
|
|
* @param mixed $item |
85
|
|
|
* |
86
|
|
|
* @return array |
|
|
|
|
87
|
|
|
*/ |
88
|
1 |
|
public function getEditUrlFor($item) |
89
|
|
|
{ |
90
|
|
|
return array( |
91
|
1 |
|
'path' => 'KunstmaanFormBundle_formsubmissions_list_edit', |
92
|
1 |
|
'params' => array('nodeTranslationId' => $this->nodeTranslation->getId(), 'submissionId' => $item->getId()), |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Return the url to list all the items |
98
|
|
|
* |
99
|
|
|
* @return array |
|
|
|
|
100
|
|
|
*/ |
101
|
1 |
|
public function getIndexUrl() |
102
|
|
|
{ |
103
|
|
|
return array( |
104
|
1 |
|
'path' => 'KunstmaanFormBundle_formsubmissions_list', |
105
|
1 |
|
'params' => array('nodeTranslationId' => $this->nodeTranslation->getId()), |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Configure if it's possible to add new items |
111
|
|
|
* |
112
|
|
|
* @return bool |
113
|
|
|
*/ |
114
|
1 |
|
public function canAdd() |
115
|
|
|
{ |
116
|
1 |
|
return false; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Configure the types of items you can add |
121
|
|
|
* |
122
|
|
|
* @param array $params |
123
|
|
|
* |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
1 |
|
public function getAddUrlFor(array $params = array()) |
127
|
|
|
{ |
128
|
1 |
|
return ''; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Configure if it's possible to delete the given $item |
133
|
|
|
* |
134
|
|
|
* @param mixed $item |
135
|
|
|
* |
136
|
|
|
* @return bool |
137
|
|
|
*/ |
138
|
1 |
|
public function canDelete($item) |
139
|
|
|
{ |
140
|
1 |
|
return $this->deletableFormsubmissions; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Configure if it's possible to export the listed items |
145
|
|
|
* |
146
|
|
|
* @return bool |
147
|
|
|
*/ |
148
|
1 |
|
public function canExport() |
149
|
|
|
{ |
150
|
1 |
|
return true; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Get the delete url for the given $item |
155
|
|
|
* |
156
|
|
|
* @param mixed $item |
157
|
|
|
* |
158
|
|
|
* @return array |
159
|
|
|
*/ |
160
|
1 |
|
public function getDeleteUrlFor($item) |
161
|
|
|
{ |
162
|
1 |
|
if (!$this->deletableFormsubmissions) { |
163
|
1 |
|
return []; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
return [ |
167
|
|
|
'path' => 'KunstmaanFormBundle_formsubmissions_delete', |
168
|
|
|
'params' => ['id' => $item->getId()], |
169
|
|
|
]; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Get the url to export the listed items |
174
|
|
|
* |
175
|
|
|
* @return array|string |
176
|
|
|
*/ |
177
|
1 |
|
public function getExportUrl() |
178
|
|
|
{ |
179
|
1 |
|
return array('path' => 'KunstmaanFormBundle_formsubmissions_export', 'params' => array('nodeTranslationId' => $this->nodeTranslation->getId())); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @return string |
184
|
|
|
*/ |
185
|
1 |
|
public function getBundleName() |
186
|
|
|
{ |
187
|
1 |
|
return 'KunstmaanFormBundle'; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @return string |
192
|
|
|
*/ |
193
|
1 |
|
public function getEntityName() |
194
|
|
|
{ |
195
|
1 |
|
return 'FormSubmission'; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Make some modifications to the default created query builder |
200
|
|
|
* |
201
|
|
|
* @param QueryBuilder $queryBuilder The query builder |
202
|
|
|
* @param array $params The parameters |
203
|
|
|
*/ |
204
|
1 |
|
public function adaptQueryBuilder(QueryBuilder $queryBuilder, array $params = array()) |
205
|
|
|
{ |
206
|
1 |
|
parent::adaptQueryBuilder($queryBuilder); |
207
|
|
|
$queryBuilder |
208
|
1 |
|
->innerJoin('b.node', 'n', 'WITH', 'b.node = n.id') |
209
|
1 |
|
->andWhere('n.id = :node') |
210
|
1 |
|
->andWhere('b.lang = :lang') |
211
|
1 |
|
->setParameter('node', $this->nodeTranslation->getNode()->getId()) |
212
|
1 |
|
->setParameter('lang', $this->nodeTranslation->getLang()) |
213
|
1 |
|
->addOrderBy('b.created', 'DESC'); |
214
|
1 |
|
} |
215
|
|
|
} |
216
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: