|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kunstmaan\FormBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManager; |
|
6
|
|
|
use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionMap; |
|
7
|
|
|
use Kunstmaan\AdminListBundle\AdminList\AdminList; |
|
8
|
|
|
use Kunstmaan\AdminListBundle\AdminList\ExportList; |
|
9
|
|
|
use Kunstmaan\FormBundle\AdminList\FormPageAdminListConfigurator; |
|
10
|
|
|
use Kunstmaan\FormBundle\AdminList\FormSubmissionAdminListConfigurator; |
|
11
|
|
|
use Kunstmaan\FormBundle\AdminList\FormSubmissionExportListConfigurator; |
|
12
|
|
|
use Kunstmaan\NodeBundle\Entity\NodeTranslation; |
|
13
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
14
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
15
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
20
|
|
|
use Kunstmaan\AdminBundle\FlashMessages\FlashTypes; |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The controller which will handle everything related with form pages and form submissions |
|
25
|
|
|
*/ |
|
26
|
|
|
class FormSubmissionsController extends Controller |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* The index action will use an admin list to list all the form pages |
|
30
|
|
|
* |
|
31
|
|
|
* @Route("/", name="KunstmaanFormBundle_formsubmissions") |
|
32
|
|
|
* @Template("KunstmaanAdminListBundle:Default:list.html.twig") |
|
33
|
|
|
* |
|
34
|
|
|
* @return array |
|
|
|
|
|
|
35
|
|
|
*/ |
|
36
|
|
View Code Duplication |
public function indexAction(Request $request) |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
/* @var EntityManager $em */ |
|
39
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
40
|
|
|
$aclHelper = $this->container->get('kunstmaan_admin.acl.helper'); |
|
41
|
|
|
|
|
42
|
|
|
/* @var AdminList $adminList */ |
|
43
|
|
|
$adminList = $this->get('kunstmaan_adminlist.factory')->createList( |
|
44
|
|
|
new FormPageAdminListConfigurator($em, $aclHelper, PermissionMap::PERMISSION_VIEW), |
|
45
|
|
|
$em |
|
46
|
|
|
); |
|
47
|
|
|
$adminList->bindRequest($request); |
|
48
|
|
|
|
|
49
|
|
|
return array('adminlist' => $adminList); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* The list action will use an admin list to list all the form submissions related to the given $nodeTranslationId |
|
54
|
|
|
* |
|
55
|
|
|
* @param int $nodeTranslationId |
|
56
|
|
|
* |
|
57
|
|
|
* @Route("/list/{nodeTranslationId}", requirements={"nodeTranslationId" = "\d+"}, |
|
58
|
|
|
* name="KunstmaanFormBundle_formsubmissions_list") |
|
59
|
|
|
* @Method({"GET", "POST"}) |
|
60
|
|
|
* @Template() |
|
61
|
|
|
* |
|
62
|
|
|
* @return array |
|
|
|
|
|
|
63
|
|
|
*/ |
|
64
|
|
|
public function listAction(Request $request, $nodeTranslationId) |
|
65
|
|
|
{ |
|
66
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
67
|
|
|
$nodeTranslation = $em->getRepository('KunstmaanNodeBundle:NodeTranslation')->find($nodeTranslationId); |
|
68
|
|
|
|
|
69
|
|
|
/** @var AdminList $adminList */ |
|
70
|
|
|
$adminList = $this->get('kunstmaan_adminlist.factory')->createList( |
|
71
|
|
|
new FormSubmissionAdminListConfigurator($em, $nodeTranslation, $this->getParameter('kunstmaan_form.deletable_formsubmissions')), |
|
|
|
|
|
|
72
|
|
|
$em |
|
73
|
|
|
); |
|
74
|
|
|
$adminList->bindRequest($request); |
|
75
|
|
|
|
|
76
|
|
|
return array('nodetranslation' => $nodeTranslation, 'adminlist' => $adminList); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* The edit action will be used to edit a given submission. |
|
81
|
|
|
* |
|
82
|
|
|
* @param int $nodeTranslationId The node translation id |
|
83
|
|
|
* @param int $submissionId The submission id |
|
84
|
|
|
* |
|
85
|
|
|
* @Route("/list/{nodeTranslationId}/{submissionId}", requirements={"nodeTranslationId" = "\d+", "submissionId" = |
|
86
|
|
|
* "\d+"}, name="KunstmaanFormBundle_formsubmissions_list_edit") |
|
87
|
|
|
* @Method({"GET", "POST"}) |
|
88
|
|
|
* @Template() |
|
89
|
|
|
* |
|
90
|
|
|
* @return array |
|
|
|
|
|
|
91
|
|
|
*/ |
|
92
|
|
|
public function editAction($nodeTranslationId, $submissionId) |
|
93
|
|
|
{ |
|
94
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
95
|
|
|
$nodeTranslation = $em->getRepository('KunstmaanNodeBundle:NodeTranslation')->find($nodeTranslationId); |
|
96
|
|
|
$formSubmission = $em->getRepository('KunstmaanFormBundle:FormSubmission')->find($submissionId); |
|
97
|
|
|
$request = $this->container->get('request_stack')->getCurrentRequest(); |
|
98
|
|
|
$deletableFormsubmission = $this->getParameter('kunstmaan_form.deletable_formsubmissions'); |
|
99
|
|
|
|
|
100
|
|
|
/** @var AdminList $adminList */ |
|
101
|
|
|
$adminList = $this->get('kunstmaan_adminlist.factory')->createList( |
|
102
|
|
|
new FormSubmissionAdminListConfigurator($em, $nodeTranslation,$deletableFormsubmission), |
|
|
|
|
|
|
103
|
|
|
$em |
|
104
|
|
|
); |
|
105
|
|
|
$adminList->bindRequest($request); |
|
106
|
|
|
|
|
107
|
|
|
return [ |
|
108
|
|
|
'nodetranslation' => $nodeTranslation, |
|
109
|
|
|
'formsubmission' => $formSubmission, |
|
110
|
|
|
'adminlist' => $adminList, |
|
111
|
|
|
]; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Export as CSV of all the form submissions for the given $nodeTranslationId |
|
116
|
|
|
* |
|
117
|
|
|
* @param int $nodeTranslationId |
|
118
|
|
|
* |
|
119
|
|
|
* @Route("/export/{nodeTranslationId}.{_format}", requirements={"nodeTranslationId" = "\d+","_format" = |
|
120
|
|
|
* "csv|xlsx|ods"}, name="KunstmaanFormBundle_formsubmissions_export") |
|
121
|
|
|
* @Method({"GET"}) |
|
122
|
|
|
* |
|
123
|
|
|
* @return Response |
|
124
|
|
|
*/ |
|
125
|
|
|
public function exportAction($nodeTranslationId, $_format) |
|
126
|
|
|
{ |
|
127
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
128
|
|
|
/** @var NodeTranslation $nodeTranslation */ |
|
129
|
|
|
$nodeTranslation = $em->getRepository('KunstmaanNodeBundle:NodeTranslation')->find($nodeTranslationId); |
|
130
|
|
|
$translator = $this->get('translator'); |
|
131
|
|
|
|
|
132
|
|
|
/** @var ExportList $exportList */ |
|
133
|
|
|
$configurator = new FormSubmissionExportListConfigurator($em, $nodeTranslation, $translator); |
|
|
|
|
|
|
134
|
|
|
$exportList = $this->get('kunstmaan_adminlist.factory')->createExportList($configurator); |
|
135
|
|
|
|
|
136
|
|
|
return $this->get('kunstmaan_adminlist.service.export')->getDownloadableResponse($exportList, $_format); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @Route( |
|
141
|
|
|
* "/{id}/delete", |
|
142
|
|
|
* requirements={"id" = "\d+"}, |
|
143
|
|
|
* name="KunstmaanFormBundle_formsubmissions_delete" |
|
144
|
|
|
* ) |
|
145
|
|
|
* @Template() |
|
146
|
|
|
* @Method("POST") |
|
147
|
|
|
* |
|
148
|
|
|
* @param Request $request |
|
149
|
|
|
* @param int $id |
|
150
|
|
|
* |
|
151
|
|
|
* @return RedirectResponse |
|
152
|
|
|
* |
|
153
|
|
|
* @throws AccessDeniedException |
|
154
|
|
|
*/ |
|
155
|
|
|
public function deleteAction(Request $request, $id) |
|
156
|
|
|
{ |
|
157
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
158
|
|
|
$submission = $em->getRepository('KunstmaanFormBundle:FormSubmission')->find($id); |
|
159
|
|
|
|
|
160
|
|
|
$node = $em->getRepository('KunstmaanNodeBundle:Node')->find($submission->getNode()); |
|
161
|
|
|
$nt = $node->getNodeTranslation($request->getLocale()); |
|
162
|
|
|
|
|
163
|
|
|
$this->denyAccessUnlessGranted(PermissionMap::PERMISSION_DELETE, $node); |
|
164
|
|
|
|
|
165
|
|
|
$url = $this->get('router')->generate( |
|
166
|
|
|
'KunstmaanFormBundle_formsubmissions_list', |
|
167
|
|
|
['nodeTranslationId' => $nt->getId()] |
|
168
|
|
|
); |
|
169
|
|
|
|
|
170
|
|
|
$fields = $em->getRepository('KunstmaanFormBundle:FormSubmissionField')->findBy(['formSubmission' => $submission]); |
|
171
|
|
|
|
|
172
|
|
|
try { |
|
173
|
|
|
foreach ($fields as $field) { |
|
174
|
|
|
$em->remove($field); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
$em->remove($submission); |
|
|
|
|
|
|
178
|
|
|
$em->flush(); |
|
179
|
|
|
|
|
180
|
|
|
$this->addFlash( |
|
181
|
|
|
FlashTypes::SUCCESS, |
|
182
|
|
|
$this->get('translator')->trans('formsubmissions.delete.flash.success') |
|
183
|
|
|
); |
|
184
|
|
|
} catch (\Exception $e) { |
|
185
|
|
|
$this->get('logger')->error($e->getMessage()); |
|
186
|
|
|
$this->addFlash( |
|
187
|
|
|
FlashTypes::ERROR, |
|
188
|
|
|
$this->get('translator')->trans('formsubmissions.delete.flash.error') |
|
189
|
|
|
); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
$response = new RedirectResponse($url); |
|
193
|
|
|
|
|
194
|
|
|
return $response; |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
|
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.