|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Fi\CoreBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
7
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* MenuApplicazione controller. |
|
11
|
|
|
*/ |
|
12
|
|
|
class MenuApplicazioneController extends FiCoreController |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Creates a new table entity. |
|
17
|
|
|
*/ |
|
18
|
1 |
|
public function createAction(Request $request) |
|
19
|
|
|
{ |
|
20
|
1 |
|
$this->setup($request); |
|
21
|
1 |
|
$namespace = $this->getNamespace(); |
|
|
|
|
|
|
22
|
1 |
|
$bundle = $this->getBundle(); |
|
|
|
|
|
|
23
|
1 |
|
$controller = $this->getController(); |
|
24
|
|
|
|
|
25
|
1 |
|
if (!self::$canCreate) { |
|
26
|
|
|
throw new AccessDeniedException("Non si hanno i permessi per creare questo contenuto"); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
1 |
|
$nomebundle = $namespace . $bundle . 'Bundle'; |
|
|
|
|
|
|
30
|
1 |
|
$classbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Entity\\' . $controller; |
|
31
|
1 |
|
$formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller; |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
1 |
|
$entity = new $classbundle(); |
|
|
|
|
|
|
34
|
1 |
|
$formType = $formbundle . 'Type'; |
|
35
|
|
|
|
|
36
|
1 |
|
$form = $this->createForm( |
|
37
|
1 |
|
$formType, |
|
38
|
1 |
|
$entity, |
|
39
|
|
|
array('attr' => array( |
|
40
|
1 |
|
'id' => 'formdati' . $controller, |
|
41
|
1 |
|
), |
|
42
|
1 |
|
'action' => $this->generateUrl($controller . '_create'), |
|
43
|
|
|
) |
|
44
|
1 |
|
); |
|
45
|
|
|
|
|
46
|
1 |
|
$form->submit($request->request->get($form->getName())); |
|
47
|
|
|
|
|
48
|
1 |
|
if ($form->isValid()) { |
|
49
|
1 |
|
$em = $this->getDoctrine()->getManager(); |
|
50
|
1 |
|
$em->persist($entity); |
|
51
|
1 |
|
$em->flush(); |
|
52
|
1 |
|
$em->getConfiguration()->getResultCacheImpl()->delete($controller); |
|
53
|
|
|
|
|
54
|
1 |
|
$continua = (int) $request->get('continua'); |
|
55
|
1 |
|
if ($continua === 0) { |
|
56
|
1 |
|
return new Response('OK'); |
|
57
|
|
|
} else { |
|
58
|
|
|
return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $entity->getId()))); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $this->render( |
|
63
|
|
|
$nomebundle . ':' . $controller . ':new.html.twig', |
|
64
|
|
|
array( |
|
65
|
|
|
'nomecontroller' => $controller, |
|
66
|
|
|
'entity' => $entity, |
|
67
|
|
|
'form' => $form->createView(), |
|
68
|
|
|
) |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Edits an existing table entity. |
|
74
|
|
|
*/ |
|
75
|
1 |
|
public function updateAction(Request $request, $id) |
|
76
|
|
|
{ |
|
77
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
|
78
|
1 |
|
$this->setup($request); |
|
79
|
1 |
|
$namespace = $this->getNamespace(); |
|
|
|
|
|
|
80
|
1 |
|
$bundle = $this->getBundle(); |
|
|
|
|
|
|
81
|
1 |
|
$controller = $this->getController(); |
|
82
|
|
|
|
|
83
|
1 |
|
if (!self::$canUpdate) { |
|
84
|
|
|
throw new AccessDeniedException("Non si hanno i permessi per aggiornare questo contenuto"); |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
1 |
|
$nomebundle = $namespace . $bundle . 'Bundle'; |
|
88
|
1 |
|
$formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller; |
|
89
|
1 |
|
$formType = $formbundle . 'Type'; |
|
|
|
|
|
|
90
|
|
|
|
|
91
|
1 |
|
$repoStorico = $this->container->get('Storicomodifiche_repository'); |
|
92
|
|
|
|
|
93
|
1 |
|
$em = $this->getDoctrine()->getManager(); |
|
94
|
|
|
|
|
95
|
1 |
|
$entity = $em->getRepository($nomebundle . ':' . $controller)->find($id); |
|
96
|
|
|
|
|
97
|
1 |
|
if (!$entity) { |
|
98
|
|
|
throw $this->createNotFoundException('Unable to find ' . $controller . ' entity.'); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
1 |
|
$deleteForm = $this->createDeleteForm($id); |
|
102
|
|
|
|
|
103
|
1 |
|
$editForm = $this->createForm( |
|
104
|
1 |
|
$formType, |
|
105
|
1 |
|
$entity, |
|
106
|
|
|
array('attr' => array( |
|
107
|
1 |
|
'id' => 'formdati' . $controller, |
|
108
|
1 |
|
), |
|
109
|
1 |
|
'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())), |
|
110
|
|
|
) |
|
111
|
1 |
|
); |
|
112
|
|
|
|
|
113
|
1 |
|
$editForm->submit($request->request->get($editForm->getName())); |
|
114
|
|
|
|
|
115
|
1 |
|
if ($editForm->isValid()) { |
|
116
|
1 |
|
$originalData = $em->getUnitOfWork()->getOriginalEntityData($entity); |
|
117
|
|
|
|
|
118
|
1 |
|
$em->persist($entity); |
|
119
|
1 |
|
$em->flush(); |
|
120
|
1 |
|
$em->getConfiguration()->getResultCacheImpl()->delete($controller); |
|
121
|
|
|
|
|
122
|
1 |
|
$newData = $em->getUnitOfWork()->getOriginalEntityData($entity); |
|
123
|
1 |
|
$changes = $repoStorico->isRecordChanged($nomebundle, $controller, $originalData, $newData); |
|
124
|
|
|
|
|
125
|
1 |
|
if ($changes) { |
|
126
|
|
|
$repoStorico->saveHistory($controller, $changes, $id, $this->getUser()); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
1 |
|
$continua = (int) $request->get('continua'); |
|
130
|
1 |
|
if ($continua === 0) { |
|
131
|
1 |
|
return new Response('OK'); |
|
132
|
|
|
} else { |
|
133
|
|
|
return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $id))); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
return $this->render( |
|
138
|
|
|
$nomebundle . ':' . $controller . ':edit.html.twig', |
|
139
|
|
|
array( |
|
140
|
|
|
'entity' => $entity, |
|
141
|
|
|
'edit_form' => $editForm->createView(), |
|
142
|
|
|
'delete_form' => $deleteForm->createView(), |
|
143
|
|
|
'nomecontroller' => $controller, |
|
144
|
|
|
) |
|
145
|
|
|
); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Deletes a table entity. |
|
150
|
|
|
*/ |
|
151
|
1 |
|
public function deleteAction(Request $request) |
|
152
|
|
|
{ |
|
153
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
|
154
|
1 |
|
$this->setup($request); |
|
155
|
1 |
|
if (!self::$canDelete) { |
|
156
|
|
|
throw new AccessDeniedException("Non si hanno i permessi per aggiornare questo contenuto"); |
|
|
|
|
|
|
157
|
|
|
} |
|
158
|
1 |
|
$namespace = $this->getNamespace(); |
|
|
|
|
|
|
159
|
1 |
|
$bundle = $this->getBundle(); |
|
|
|
|
|
|
160
|
1 |
|
$controller = $this->getController(); |
|
161
|
|
|
|
|
162
|
1 |
|
$nomebundle = $namespace . $bundle . 'Bundle'; |
|
163
|
|
|
|
|
164
|
|
|
try { |
|
165
|
1 |
|
$em = $this->getDoctrine()->getManager(); |
|
|
|
|
|
|
166
|
1 |
|
$qb = $em->createQueryBuilder(); |
|
|
|
|
|
|
167
|
1 |
|
$ids = explode(',', $request->get('id')); |
|
168
|
1 |
|
$qb->delete($nomebundle . ':' . $controller, 'u') |
|
169
|
1 |
|
->andWhere('u.id IN (:ids)') |
|
170
|
1 |
|
->setParameter('ids', $ids); |
|
171
|
|
|
|
|
172
|
1 |
|
$query = $qb->getQuery(); |
|
173
|
1 |
|
$query->execute(); |
|
174
|
1 |
|
$em->getConfiguration()->getResultCacheImpl()->delete($controller); |
|
175
|
1 |
|
} catch (\Exception $e) { |
|
176
|
|
|
$response = new Response(); |
|
177
|
|
|
$response->setStatusCode('200'); |
|
178
|
|
|
|
|
179
|
|
|
return new Response('404'); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
1 |
|
return new Response('OK'); |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.