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