1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Controller\Settings\Divers; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
8
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
9
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
10
|
|
|
use AppBundle\Entity\Tva; |
11
|
|
|
use AppBundle\Form\Type\TvaType; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Tva controller. |
15
|
|
|
* |
16
|
|
|
* @Route("/admin/settings/divers/rate") |
17
|
|
|
*/ |
18
|
|
View Code Duplication |
class TvaController extends Controller |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Lists all Tva entities. |
22
|
|
|
* |
23
|
|
|
* @Route("/", name="admin_rate") |
24
|
|
|
* @Method("GET") |
25
|
|
|
* @Template() |
26
|
|
|
*/ |
27
|
|
|
public function indexAction() |
28
|
|
|
{ |
29
|
|
|
$em = $this->getDoctrine()->getManager(); |
30
|
|
|
$entities = $em->getRepository('AppBundle:Tva')->findAll(); |
31
|
|
|
|
32
|
|
|
return array( |
33
|
|
|
'entities' => $entities, |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Finds and displays a Tva entity. |
39
|
|
|
* |
40
|
|
|
* @Route("/{id}/show", name="admin_rate_show", requirements={"id"="\d+"}) |
41
|
|
|
* @Method("GET") |
42
|
|
|
* @Template() |
43
|
|
|
*/ |
44
|
|
|
public function showAction(Tva $tva) |
45
|
|
|
{ |
46
|
|
|
$deleteForm = $this->createDeleteForm($tva->getId(), 'admin_rate_delete'); |
47
|
|
|
|
48
|
|
|
return array( |
49
|
|
|
'tva' => $tva, |
50
|
|
|
'delete_form' => $deleteForm->createView(), |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Displays a form to create a new Tva entity. |
56
|
|
|
* |
57
|
|
|
* @Route("/new", name="admin_rate_new") |
58
|
|
|
* @Method("GET") |
59
|
|
|
* @Template() |
60
|
|
|
*/ |
61
|
|
|
public function newAction() |
62
|
|
|
{ |
63
|
|
|
$tva = new Tva(); |
64
|
|
|
$form = $this->createForm(new TvaType(), $tva); |
65
|
|
|
|
66
|
|
|
return array( |
67
|
|
|
'tva' => $tva, |
68
|
|
|
'form' => $form->createView(), |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Creates a new Tva entity. |
74
|
|
|
* |
75
|
|
|
* @Route("/create", name="admin_rate_create") |
76
|
|
|
* @Method("POST") |
77
|
|
|
* @Template("AppBundle:Tva:new.html.twig") |
78
|
|
|
*/ |
79
|
|
|
public function createAction(Request $request) |
80
|
|
|
{ |
81
|
|
|
$tva = new Tva(); |
82
|
|
|
$form = $this->createForm(new TvaType(), $tva); |
83
|
|
|
if ($form->handleRequest($request)->isValid()) { |
84
|
|
|
$em = $this->getDoctrine()->getManager(); |
85
|
|
|
$em->persist($tva); |
86
|
|
|
$em->flush(); |
87
|
|
|
|
88
|
|
|
if ($form->get('save')->isClicked()) { |
|
|
|
|
89
|
|
|
$url = $this->redirectToRoute('admin_rate_show', array('id' => $tva->getId())); |
90
|
|
|
} elseif ($form->get('addmore')->isClicked()) { |
|
|
|
|
91
|
|
|
$this->addFlash('info', 'gestock.settings.add_ok'); |
92
|
|
|
$url = $this->redirectToRoute('admin_rate_new'); |
93
|
|
|
} |
94
|
|
|
return $url; |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return array( |
98
|
|
|
'tva' => $tva, |
99
|
|
|
'form' => $form->createView(), |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Displays a form to edit an existing Tva entity. |
105
|
|
|
* |
106
|
|
|
* @Route("/{id}/edit", name="admin_rate_edit", requirements={"id"="\d+"}) |
107
|
|
|
* @Method("GET") |
108
|
|
|
* @Template() |
109
|
|
|
*/ |
110
|
|
|
public function editAction(Tva $tva) |
111
|
|
|
{ |
112
|
|
|
$editForm = $this->createForm(new TvaType(), $tva, array( |
113
|
|
|
'action' => $this->generateUrl('admin_rate_update', array('id' => $tva->getId())), |
114
|
|
|
'method' => 'PUT', |
115
|
|
|
)); |
116
|
|
|
$deleteForm = $this->createDeleteForm($tva->getId(), 'admin_rate_delete'); |
117
|
|
|
|
118
|
|
|
return array( |
119
|
|
|
'tva' => $tva, |
120
|
|
|
'edit_form' => $editForm->createView(), |
121
|
|
|
'delete_form' => $deleteForm->createView(), |
122
|
|
|
); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Edits an existing Tva entity. |
127
|
|
|
* |
128
|
|
|
* @Route("/{id}/update", name="admin_rate_update", requirements={"id"="\d+"}) |
129
|
|
|
* @Method("PUT") |
130
|
|
|
* @Template("AppBundle:Tva:edit.html.twig") |
131
|
|
|
*/ |
132
|
|
|
public function updateAction(Tva $tva, Request $request) |
133
|
|
|
{ |
134
|
|
|
$editForm = $this->createForm(new TvaType(), $tva, array( |
135
|
|
|
'action' => $this->generateUrl('admin_rate_update', array('id' => $tva->getId())), |
136
|
|
|
'method' => 'PUT', |
137
|
|
|
)); |
138
|
|
|
if ($editForm->handleRequest($request)->isValid()) { |
139
|
|
|
$this->getDoctrine()->getManager()->flush(); |
140
|
|
|
|
141
|
|
|
return $this->redirectToRoute('admin_rate_edit', array('id' => $tva->getId())); |
142
|
|
|
} |
143
|
|
|
$deleteForm = $this->createDeleteForm($tva->getId(), 'admin_rate_delete'); |
144
|
|
|
|
145
|
|
|
return array( |
146
|
|
|
'tva' => $tva, |
147
|
|
|
'edit_form' => $editForm->createView(), |
148
|
|
|
'delete_form' => $deleteForm->createView(), |
149
|
|
|
); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Deletes a Tva entity. |
154
|
|
|
* |
155
|
|
|
* @Route("/{id}/delete", name="admin_rate_delete", requirements={"id"="\d+"}) |
156
|
|
|
* @Method("DELETE") |
157
|
|
|
*/ |
158
|
|
|
public function deleteAction(Tva $tva, Request $request) |
159
|
|
|
{ |
160
|
|
|
$form = $this->createDeleteForm($tva->getId(), 'admin_rate_delete'); |
161
|
|
|
if ($form->handleRequest($request)->isValid()) { |
162
|
|
|
$em = $this->getDoctrine()->getManager(); |
163
|
|
|
$em->remove($tva); |
164
|
|
|
$em->flush(); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
return $this->redirectToRoute('admin_rate'); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Create Delete form |
172
|
|
|
* |
173
|
|
|
* @param integer $id |
174
|
|
|
* @param string $route |
175
|
|
|
* @return \Symfony\Component\Form\Form |
176
|
|
|
*/ |
177
|
|
|
protected function createDeleteForm($id, $route) |
178
|
|
|
{ |
179
|
|
|
return $this->createFormBuilder(null, array('attr' => array('id' => 'delete'))) |
|
|
|
|
180
|
|
|
->setAction($this->generateUrl($route, array('id' => $id))) |
181
|
|
|
->setMethod('DELETE') |
182
|
|
|
->getForm() |
183
|
|
|
; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
} |
187
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.