|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ZoneStorageController controller des zones de stockage. |
|
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\Divers; |
|
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\ZoneStorage; |
|
23
|
|
|
use AppBundle\Form\Type\ZoneStorageType; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* ZoneStorage controller. |
|
27
|
|
|
* |
|
28
|
|
|
* @category Controller |
|
29
|
|
|
* |
|
30
|
|
|
* @Route("/admin/settings/divers/zonestorage") |
|
31
|
|
|
*/ |
|
32
|
|
View Code Duplication |
class ZoneStorageController extends AbstractController |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* Lists all ZoneStorage entities. |
|
36
|
|
|
* |
|
37
|
|
|
* @Route("/", name="admin_zonestorage") |
|
38
|
|
|
* @Method("GET") |
|
39
|
|
|
* @Template() |
|
40
|
|
|
*/ |
|
41
|
|
|
public function indexAction() |
|
42
|
|
|
{ |
|
43
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
44
|
|
|
$entities = $em->getRepository('AppBundle:ZoneStorage')->findAll(); |
|
45
|
|
|
|
|
46
|
|
|
return array( |
|
47
|
|
|
'entities' => $entities, |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Finds and displays a ZoneStorage entity. |
|
53
|
|
|
* |
|
54
|
|
|
* @Route("/{slug}/show", name="admin_zonestorage_show") |
|
55
|
|
|
* @Method("GET") |
|
56
|
|
|
* @Template() |
|
57
|
|
|
*/ |
|
58
|
|
|
public function showAction(ZoneStorage $zonestorage) |
|
59
|
|
|
{ |
|
60
|
|
|
$deleteForm = $this->createDeleteForm($zonestorage->getId(), 'admin_zonestorage_delete'); |
|
61
|
|
|
|
|
62
|
|
|
return array( |
|
63
|
|
|
'zonestorage' => $zonestorage, |
|
64
|
|
|
'delete_form' => $deleteForm->createView(), |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Displays a form to create a new ZoneStorage entity. |
|
70
|
|
|
* |
|
71
|
|
|
* @Route("/new", name="admin_zonestorage_new") |
|
72
|
|
|
* @Method("GET") |
|
73
|
|
|
* @Template() |
|
74
|
|
|
*/ |
|
75
|
|
|
public function newAction() |
|
76
|
|
|
{ |
|
77
|
|
|
$zonestorage = new ZoneStorage(); |
|
78
|
|
|
$form = $this->createForm(new ZoneStorageType(), $zonestorage); |
|
79
|
|
|
|
|
80
|
|
|
return array( |
|
81
|
|
|
'zonestorage' => $zonestorage, |
|
82
|
|
|
'form' => $form->createView(), |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Creates a new ZoneStorage entity. |
|
88
|
|
|
* |
|
89
|
|
|
* @Route("/create", name="admin_zonestorage_create") |
|
90
|
|
|
* @Method("POST") |
|
91
|
|
|
* @Template("AppBundle:Settings/Divers/ZoneStorage:new.html.twig") |
|
92
|
|
|
*/ |
|
93
|
|
|
public function createAction(Request $request) |
|
94
|
|
|
{ |
|
95
|
|
|
$zonestorage = new ZoneStorage(); |
|
96
|
|
|
$form = $this->createForm(new ZoneStorageType(), $zonestorage); |
|
97
|
|
|
if ($form->handleRequest($request)->isValid()) { |
|
98
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
99
|
|
|
$em->persist($zonestorage); |
|
100
|
|
|
$em->flush(); |
|
101
|
|
|
|
|
102
|
|
|
if ($form->get('save')->isSubmitted()) { |
|
103
|
|
|
$url = $this->redirectToRoute('admin_zonestorage_show', array('slug' => $zonestorage->getSlug())); |
|
104
|
|
|
} elseif ($form->get('addmore')->isSubmitted()) { |
|
105
|
|
|
$this->addFlash('info', 'gestock.settings.add_ok'); |
|
106
|
|
|
$url = $this->redirect($this->generateUrl('admin_zonestorage_new')); |
|
107
|
|
|
} |
|
108
|
|
|
return $url; |
|
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
return array( |
|
112
|
|
|
'zonestorage' => $zonestorage, |
|
113
|
|
|
'form' => $form->createView(), |
|
114
|
|
|
); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Displays a form to edit an existing ZoneStorage entity. |
|
119
|
|
|
* |
|
120
|
|
|
* @Route("/{slug}/edit", name="admin_zonestorage_edit") |
|
121
|
|
|
* @Method("GET") |
|
122
|
|
|
* @Template() |
|
123
|
|
|
*/ |
|
124
|
|
|
public function editAction(ZoneStorage $zonestorage = null) |
|
125
|
|
|
{ |
|
126
|
|
|
$editForm = $this->createForm(new ZoneStorageType(), $zonestorage, array( |
|
127
|
|
|
'action' => $this->generateUrl('admin_zonestorage_update', array('slug' => $zonestorage->getSlug())), |
|
|
|
|
|
|
128
|
|
|
'method' => 'PUT', |
|
129
|
|
|
)); |
|
130
|
|
|
$deleteForm = $this->createDeleteForm($zonestorage->getId(), 'admin_zonestorage_delete'); |
|
131
|
|
|
|
|
132
|
|
|
return array( |
|
133
|
|
|
'zonestorage' => $zonestorage, |
|
134
|
|
|
'edit_form' => $editForm->createView(), |
|
135
|
|
|
'delete_form' => $deleteForm->createView(), |
|
136
|
|
|
); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Edits an existing ZoneStorage entity. |
|
141
|
|
|
* |
|
142
|
|
|
* @Route("/{slug}/update", name="admin_zonestorage_update") |
|
143
|
|
|
* @Method("PUT") |
|
144
|
|
|
* @Template("AppBundle:Settings/Divers/ZoneStorage:edit.html.twig") |
|
145
|
|
|
*/ |
|
146
|
|
|
public function updateAction(Request $request, ZoneStorage $zonestorage = null) |
|
147
|
|
|
{ |
|
148
|
|
|
$editForm = $this->createForm(new ZoneStorageType(), $zonestorage, array( |
|
149
|
|
|
'action' => $this->generateUrl('admin_zonestorage_update', array('slug' => $zonestorage->getSlug())), |
|
|
|
|
|
|
150
|
|
|
'method' => 'PUT', |
|
151
|
|
|
)); |
|
152
|
|
|
if ($editForm->handleRequest($request)->isValid()) { |
|
153
|
|
|
$this->getDoctrine()->getManager()->flush(); |
|
154
|
|
|
$this->addFlash('info', 'gestock.settings.edit_ok'); |
|
155
|
|
|
|
|
156
|
|
|
return $this->redirectToRoute('admin_zonestorage_edit', array('slug' => $zonestorage->getSlug())); |
|
157
|
|
|
} |
|
158
|
|
|
$deleteForm = $this->createDeleteForm($zonestorage->getId(), 'admin_zonestorage_delete'); |
|
159
|
|
|
|
|
160
|
|
|
return array( |
|
161
|
|
|
'zonestorage' => $zonestorage, |
|
162
|
|
|
'edit_form' => $editForm->createView(), |
|
163
|
|
|
'delete_form' => $deleteForm->createView(), |
|
164
|
|
|
); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Deletes a ZoneStorage entity. |
|
169
|
|
|
* |
|
170
|
|
|
* @Route("/{id}/delete", name="admin_zonestorage_delete", requirements={"id"="\d+"}) |
|
171
|
|
|
* @Method("DELETE") |
|
172
|
|
|
*/ |
|
173
|
|
|
public function deleteAction(Request $request, ZoneStorage $zonestorage = null) |
|
174
|
|
|
{ |
|
175
|
|
|
$form = $this->createDeleteForm($zonestorage->getId(), 'admin_zonestorage_delete'); |
|
|
|
|
|
|
176
|
|
|
if ($form->handleRequest($request)->isValid()) { |
|
177
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
178
|
|
|
$em->remove($zonestorage); |
|
179
|
|
|
$em->flush(); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
return $this->redirectToRoute('admin_zonestorage'); |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
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.