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