1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Controller\Settings; |
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\Settings; |
11
|
|
|
use AppBundle\Form\Type\SettingsType; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Application controller. |
15
|
|
|
* |
16
|
|
|
* @category Controller |
17
|
|
|
* @Route("/admin/settings/application") |
18
|
|
|
*/ |
19
|
|
View Code Duplication |
class ApplicationController extends Controller |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Lists all Settings entities. |
23
|
|
|
* |
24
|
|
|
* @Route("/", name="admin_application") |
25
|
|
|
* @Method("GET") |
26
|
|
|
* @Template() |
27
|
|
|
*/ |
28
|
|
|
public function indexAction() |
29
|
|
|
{ |
30
|
|
|
$em = $this->getDoctrine()->getManager(); |
31
|
|
|
$entities = $em->getRepository('AppBundle:Settings')->findAll(); |
32
|
|
|
|
33
|
|
|
return array( |
34
|
|
|
'entities' => $entities, |
35
|
|
|
'ctEntity' => count($entities), |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Finds and displays a Settings entity. |
41
|
|
|
* |
42
|
|
|
* @Route("/{id}/show", name="admin_application_show", requirements={"id"="\d+"}) |
43
|
|
|
* @Method("GET") |
44
|
|
|
* @Template() |
45
|
|
|
*/ |
46
|
|
|
public function showAction(Settings $settings) |
47
|
|
|
{ |
48
|
|
|
$deleteForm = $this->createDeleteForm($settings->getId(), 'admin_application_delete'); |
49
|
|
|
|
50
|
|
|
return array( |
51
|
|
|
'settings' => $settings, |
52
|
|
|
'delete_form' => $deleteForm->createView(), |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Displays a form to create a new Settings entity. |
58
|
|
|
* |
59
|
|
|
* @Route("/new", name="admin_application_new") |
60
|
|
|
* @Method("GET") |
61
|
|
|
* @Template() |
62
|
|
|
*/ |
63
|
|
|
public function newAction() |
64
|
|
|
{ |
65
|
|
|
$settings = new Settings(); |
66
|
|
|
$form = $this->createForm(new SettingsType(), $settings); |
67
|
|
|
|
68
|
|
|
return array( |
69
|
|
|
'settings' => $settings, |
70
|
|
|
'form' => $form->createView(), |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Creates a new Settings entity. |
76
|
|
|
* |
77
|
|
|
* @Route("/create", name="admin_application_create") |
78
|
|
|
* @Method("POST") |
79
|
|
|
* @Template("AppBundle:Application:new.html.twig") |
80
|
|
|
*/ |
81
|
|
|
public function createAction(Request $request) |
82
|
|
|
{ |
83
|
|
|
$settings = new Settings(); |
84
|
|
|
$form = $this->createForm(new SettingsType(), $settings); |
85
|
|
|
if ($form->handleRequest($request)->isValid()) { |
86
|
|
|
$em = $this->getDoctrine()->getManager(); |
87
|
|
|
$em->persist($settings); |
88
|
|
|
$em->flush(); |
89
|
|
|
|
90
|
|
|
return $this->redirect($this->generateUrl('admin_application_show', array('id' => $settings->getId()))); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return array( |
94
|
|
|
'settings' => $settings, |
95
|
|
|
'form' => $form->createView(), |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Displays a form to edit an existing Settings entity. |
101
|
|
|
* |
102
|
|
|
* @Route("/{id}/edit", name="admin_application_edit", requirements={"id"="\d+"}) |
103
|
|
|
* @Method("GET") |
104
|
|
|
* @Template() |
105
|
|
|
*/ |
106
|
|
|
public function editAction(Settings $settings) |
107
|
|
|
{ |
108
|
|
|
$editForm = $this->createForm(new SettingsType(), $settings, array( |
109
|
|
|
'action' => $this->generateUrl('admin_application_update', array('id' => $settings->getId())), |
110
|
|
|
'method' => 'PUT', |
111
|
|
|
)); |
112
|
|
|
$deleteForm = $this->createDeleteForm($settings->getId(), 'admin_application_delete'); |
113
|
|
|
|
114
|
|
|
return array( |
115
|
|
|
'settings' => $settings, |
116
|
|
|
'edit_form' => $editForm->createView(), |
117
|
|
|
'delete_form' => $deleteForm->createView(), |
118
|
|
|
); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Edits an existing Settings entity. |
123
|
|
|
* |
124
|
|
|
* @Route("/{id}/update", name="admin_application_update", requirements={"id"="\d+"}) |
125
|
|
|
* @Method("PUT") |
126
|
|
|
* @Template("AppBundle:Application:edit.html.twig") |
127
|
|
|
*/ |
128
|
|
|
public function updateAction(Settings $settings, Request $request) |
129
|
|
|
{ |
130
|
|
|
$editForm = $this->createForm(new SettingsType(), $settings, array( |
131
|
|
|
'action' => $this->generateUrl('admin_application_update', array('id' => $settings->getId())), |
132
|
|
|
'method' => 'PUT', |
133
|
|
|
)); |
134
|
|
|
if ($editForm->handleRequest($request)->isValid()) { |
135
|
|
|
$this->getDoctrine()->getManager()->flush(); |
136
|
|
|
|
137
|
|
|
return $this->redirect($this->generateUrl('admin_application_edit', array('id' => $settings->getId()))); |
138
|
|
|
} |
139
|
|
|
$deleteForm = $this->createDeleteForm($settings->getId(), 'admin_application_delete'); |
140
|
|
|
|
141
|
|
|
return array( |
142
|
|
|
'settings' => $settings, |
143
|
|
|
'edit_form' => $editForm->createView(), |
144
|
|
|
'delete_form' => $deleteForm->createView(), |
145
|
|
|
); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Deletes a Settings entity. |
150
|
|
|
* |
151
|
|
|
* @Route("/{id}/delete", name="admin_application_delete", requirements={"id"="\d+"}) |
152
|
|
|
* @Method("DELETE") |
153
|
|
|
*/ |
154
|
|
|
public function deleteAction(Settings $settings, Request $request) |
155
|
|
|
{ |
156
|
|
|
$form = $this->createDeleteForm($settings->getId(), 'admin_application_delete'); |
157
|
|
|
if ($form->handleRequest($request)->isValid()) { |
158
|
|
|
$em = $this->getDoctrine()->getManager(); |
159
|
|
|
$em->remove($settings); |
160
|
|
|
$em->flush(); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
return $this->redirect($this->generateUrl('admin_application')); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Create Delete form |
168
|
|
|
* |
169
|
|
|
* @param integer $id |
170
|
|
|
* @param string $route |
171
|
|
|
* @return \Symfony\Component\Form\Form |
172
|
|
|
*/ |
173
|
|
|
protected function createDeleteForm($id, $route) |
174
|
|
|
{ |
175
|
|
|
return $this->createFormBuilder(null, array('attr' => array('id' => 'delete'))) |
|
|
|
|
176
|
|
|
->setAction($this->generateUrl($route, array('id' => $id))) |
177
|
|
|
->setMethod('DELETE') |
178
|
|
|
->getForm() |
179
|
|
|
; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
} |
183
|
|
|
|
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.