|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
ÁTICA - Aplicación web para la gestión documental de centros educativos |
|
4
|
|
|
|
|
5
|
|
|
Copyright (C) 2015-2016: Luis Ramón López López |
|
6
|
|
|
|
|
7
|
|
|
This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
it under the terms of the GNU Affero General Public License as published by |
|
9
|
|
|
the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
(at your option) any later version. |
|
11
|
|
|
|
|
12
|
|
|
This program is distributed in the hope that it will be useful, |
|
13
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
GNU Affero General Public License for more details. |
|
16
|
|
|
|
|
17
|
|
|
You should have received a copy of the GNU Affero General Public License |
|
18
|
|
|
along with this program. If not, see [http://www.gnu.org/licenses/]. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace AppBundle\Controller; |
|
22
|
|
|
|
|
23
|
|
|
use AppBundle\Entity\Department; |
|
24
|
|
|
use AppBundle\Entity\Group; |
|
25
|
|
|
use AppBundle\Entity\NonSchoolDay; |
|
26
|
|
|
use AppBundle\Entity\Training; |
|
27
|
|
|
use AppBundle\Entity\Workcenter; |
|
28
|
|
|
use Doctrine\ORM\EntityManager; |
|
29
|
|
|
use Doctrine\ORM\Query; |
|
30
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
31
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; |
|
32
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
33
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
34
|
|
|
|
|
35
|
|
|
class AdminController extends Controller |
|
36
|
|
|
{ |
|
37
|
|
|
public static $DEPARTMENT_ENTITY_DATA = [ |
|
38
|
|
|
'entity' => 'department', |
|
39
|
|
|
'entityClassName' => 'AppBundle\Entity\Department', |
|
40
|
|
|
'entityFormType' => 'AppBundle\Form\Type\DepartmentType', |
|
41
|
|
|
'query' => 'SELECT d FROM AppBundle:Department d LEFT JOIN d.head h', |
|
42
|
|
|
'defaultSortFieldName' => 'd.name', |
|
43
|
|
|
'columns' => [ |
|
44
|
|
|
['size' => '5', 'sort_field' => 'd.name', 'name' => 'department.name'], |
|
45
|
|
|
['size' => '4', 'sort_field' => 'h.displayName', 'name' => 'department.head'], |
|
46
|
|
|
], |
|
47
|
|
|
'data_columns' => ['name', 'head'] |
|
48
|
|
|
]; |
|
49
|
|
|
|
|
50
|
|
|
public static $GROUP_ENTITY_DATA = [ |
|
51
|
|
|
'entity' => 'group', |
|
52
|
|
|
'entityClassName' => 'AppBundle\Entity\Group', |
|
53
|
|
|
'entityFormType' => 'AppBundle\Form\Type\GroupType', |
|
54
|
|
|
'query' => 'SELECT g FROM AppBundle:Group g JOIN g.training t', |
|
55
|
|
|
'defaultSortFieldName' => 'g.name', |
|
56
|
|
|
'columns' => [ |
|
57
|
|
|
['size' => '4', 'sort_field' => 'g.name', 'name' => 'form.name'], |
|
58
|
|
|
['size' => '5', 'sort_field' => 'g.training', 'name' => 'form.training'] |
|
59
|
|
|
], |
|
60
|
|
|
'data_columns' => ['name', 'training'] |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
|
|
public static $TRAINING_ENTITY_DATA = [ |
|
64
|
|
|
'entity' => 'training', |
|
65
|
|
|
'entityClassName' => 'AppBundle\Entity\Training', |
|
66
|
|
|
'entityFormType' => 'AppBundle\Form\Type\TrainingType', |
|
67
|
|
|
'query' => 'SELECT t FROM AppBundle:Training t JOIN t.department d', |
|
68
|
|
|
'defaultSortFieldName' => 't.name', |
|
69
|
|
|
'columns' => [ |
|
70
|
|
|
['size' => '4', 'sort_field' => 't.name', 'name' => 'form.name'], |
|
71
|
|
|
['size' => '3', 'sort_field' => 'd.name', 'name' => 'form.department'], |
|
72
|
|
|
['size' => '2', 'sort_field' => 't.programHours', 'name' => 'form.program_hours'] |
|
73
|
|
|
], |
|
74
|
|
|
'data_columns' => ['name', 'department', 'programHours'] |
|
75
|
|
|
]; |
|
76
|
|
|
|
|
77
|
|
|
public static $NON_SCHOOL_DAY_ENTITY_DATA = [ |
|
78
|
|
|
'entity' => 'non_school_day', |
|
79
|
|
|
'entityClassName' => 'AppBundle\Entity\NonSchoolDay', |
|
80
|
|
|
'entityFormType' => 'AppBundle\Form\Type\NonSchoolDayType', |
|
81
|
|
|
'query' => 'SELECT n FROM AppBundle:NonSchoolDay n', |
|
82
|
|
|
'defaultSortFieldName' => 'n.date', |
|
83
|
|
|
'columns' => [ |
|
84
|
|
|
['size' => '2', 'sort_field' => 'n.date', 'name' => 'form.date'], |
|
85
|
|
|
['size' => '7', 'sort_field' => 'n.name', 'name' => 'form.name'] |
|
86
|
|
|
], |
|
87
|
|
|
'data_columns' => ['date', 'name'] |
|
88
|
|
|
]; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @Route("/admin", name="admin_menu", methods={"GET"}) |
|
92
|
|
|
* @Security("is_granted('ROLE_ADMIN')") |
|
93
|
|
|
*/ |
|
94
|
|
|
public function indexAction() |
|
95
|
|
|
{ |
|
96
|
|
|
$menuItem = $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_menu'); |
|
97
|
|
|
|
|
98
|
|
|
return $this->render('admin/menu.html.twig', |
|
99
|
|
|
[ |
|
100
|
|
|
'menu_item' => $menuItem |
|
101
|
|
|
]); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function genericIndexAction($entityData, Request $request, $items = null, Query $query = null) |
|
105
|
|
|
{ |
|
106
|
|
|
/** @var EntityManager $em */ |
|
107
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
108
|
|
|
|
|
109
|
|
|
if (null === $query) { |
|
110
|
|
|
$query = $em->createQuery($entityData['query']); |
|
111
|
|
|
|
|
112
|
|
|
if (null !== $items) { |
|
113
|
|
|
$query->setParameters($items); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
$paginator = $this->get('knp_paginator'); |
|
118
|
|
|
$pagination = $paginator->paginate( |
|
119
|
|
|
$query, |
|
120
|
|
|
$request->query->getInt('page', 1), |
|
121
|
|
|
$this->getParameter('page.size'), |
|
122
|
|
|
[ |
|
123
|
|
|
'defaultSortFieldName' => $entityData['defaultSortFieldName'], |
|
124
|
|
|
'defaultSortDirection' => 'asc' |
|
125
|
|
|
] |
|
126
|
|
|
); |
|
127
|
|
|
|
|
128
|
|
|
$menuItem = $this->get('app.menu_builders_chain')->getMenuItemByRouteName(isset($entityData['parent']) |
|
129
|
|
|
? $entityData['parent'] |
|
130
|
|
|
: $request->get('_route')); |
|
131
|
|
|
|
|
132
|
|
|
$options = [ |
|
133
|
|
|
'menu_item' => $menuItem, |
|
134
|
|
|
'title' => isset($entityData['title']) ? $entityData['title'] : null, |
|
135
|
|
|
'pagination' => $pagination, |
|
136
|
|
|
'entity' => $entityData['entity'], |
|
137
|
|
|
'columns' => $entityData['columns'], |
|
138
|
|
|
'data_columns' => $entityData['data_columns'] |
|
139
|
|
|
]; |
|
140
|
|
|
|
|
141
|
|
|
if (isset($entityData['breadcrumb'])) { |
|
142
|
|
|
$options['breadcrumb'] = $entityData['breadcrumb']; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
if (isset($entityData['back_path'])) { |
|
146
|
|
|
$options['back_path'] = $entityData['back_path']; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
if (isset($entityData['path_options'])) { |
|
150
|
|
|
$options['path_options'] = $entityData['path_options']; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
return $this->render(isset($entityData['manage_template']) ? $entityData['manage_template'] |
|
154
|
|
|
: 'admin/manage_generic.html.twig', $options); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
public function genericFormAction($entityData, $element, Request $request) |
|
158
|
|
|
{ |
|
159
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
160
|
|
|
|
|
161
|
|
|
$new = (null === $element); |
|
162
|
|
|
if ($new) { |
|
163
|
|
|
$element = new $entityData['entityClassName']; |
|
164
|
|
|
$em->persist($element); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
$form = $this->createForm($entityData['entityFormType'], $element); |
|
168
|
|
|
|
|
169
|
|
|
$form->handleRequest($request); |
|
170
|
|
|
|
|
171
|
|
|
$menuItem = $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_' . $entityData['entity']); |
|
172
|
|
|
|
|
173
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
174
|
|
|
|
|
175
|
|
|
// Probar a guardar los cambios |
|
176
|
|
|
try { |
|
177
|
|
|
$em->flush(); |
|
178
|
|
|
$this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'user')); |
|
179
|
|
|
return $this->redirectToRoute($menuItem->getRouteName(), $menuItem->getRouteParams()); |
|
180
|
|
|
} catch (\Exception $e) { |
|
181
|
|
|
$this->addFlash('error', $this->get('translator')->trans('alert.not_saved', [], 'user')); |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
$title = ((string) $element) ?: $this->get('translator')->trans('form.new', [], $entityData['entity']); |
|
186
|
|
|
|
|
187
|
|
|
return $this->render(isset($entityData['form_template']) ? $entityData['form_template'] : 'admin/form_generic.html.twig', [ |
|
188
|
|
|
'form' => $form->createView(), |
|
189
|
|
|
'new' => $new, |
|
190
|
|
|
'menu_item' => $menuItem, |
|
191
|
|
|
'breadcrumb' => [ |
|
192
|
|
|
['fixed' => $title] |
|
193
|
|
|
], |
|
194
|
|
|
'element' => $element, |
|
195
|
|
|
'title' => $title, |
|
196
|
|
|
'entity' => $entityData['entity'] |
|
197
|
|
|
]); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
public function genericDeleteAction($entityData, $element, Request $request) |
|
201
|
|
|
{ |
|
202
|
|
|
if ('POST' === $request->getMethod() && $request->request->has('delete')) { |
|
203
|
|
|
|
|
204
|
|
|
// Eliminar el departamento de la base de datos |
|
205
|
|
|
$this->getDoctrine()->getManager()->remove($element); |
|
206
|
|
|
try { |
|
207
|
|
|
$this->getDoctrine()->getManager()->flush(); |
|
208
|
|
|
$this->addFlash('success', $this->get('translator')->trans('alert.deleted', [], $entityData['entity'])); |
|
209
|
|
|
} catch (\Exception $e) { |
|
210
|
|
|
$this->addFlash('error', $this->get('translator')->trans('alert.not_deleted', [], $entityData['entity'])); |
|
211
|
|
|
} |
|
212
|
|
|
return $this->redirectToRoute('admin_' . $entityData['entity']); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
$title = (string) $element; |
|
216
|
|
|
|
|
217
|
|
|
$breadcrumb = [ |
|
218
|
|
|
['fixed' => $title, 'path' => 'admin_' . $entityData['entity'] . '_form', 'options' => ['id' => $element->getId()]], |
|
219
|
|
|
['caption' => 'menu.delete'] |
|
220
|
|
|
]; |
|
221
|
|
|
|
|
222
|
|
|
return $this->render(':admin:delete_generic.html.twig', [ |
|
223
|
|
|
'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_departments'), |
|
224
|
|
|
'breadcrumb' => $breadcrumb, |
|
225
|
|
|
'title' => $title, |
|
226
|
|
|
'element' => $element, |
|
227
|
|
|
'entity' => $entityData['entity'] |
|
228
|
|
|
]); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* @Route("/admin/departamentos", name="admin_department", methods={"GET"}) |
|
233
|
|
|
* @Security("is_granted('ROLE_ADMIN')") |
|
234
|
|
|
*/ |
|
235
|
|
|
public function departmentsIndexAction(Request $request) |
|
236
|
|
|
{ |
|
237
|
|
|
return $this->genericIndexAction(self::$DEPARTMENT_ENTITY_DATA, $request); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* @Route("/admin/departamentos/nuevo", name="admin_department_new", methods={"GET", "POST"}) |
|
242
|
|
|
* @Route("/admin/departamentos/{id}", name="admin_department_form", methods={"GET", "POST"}, requirements={"id": "\d+"}) |
|
243
|
|
|
* @Security("is_granted('ROLE_ADMIN')") |
|
244
|
|
|
*/ |
|
245
|
|
|
public function departmentsFormAction(Department $element = null, Request $request) |
|
246
|
|
|
{ |
|
247
|
|
|
return $this->genericFormAction(self::$DEPARTMENT_ENTITY_DATA, $element, $request); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* @Route("/admin/departamentos/eliminar/{id}", name="admin_department_delete", methods={"GET", "POST"}, requirements={"id": "\d+"} ) |
|
252
|
|
|
* @Security("is_granted('ROLE_ADMIN')") |
|
253
|
|
|
*/ |
|
254
|
|
|
public function deleteElementAction(Department $element, Request $request) |
|
255
|
|
|
{ |
|
256
|
|
|
return $this->genericDeleteAction(self::$DEPARTMENT_ENTITY_DATA, $element, $request); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* @Route("/admin/grupos", name="admin_group", methods={"GET"}) |
|
261
|
|
|
* @Security("is_granted('ROLE_DEPARTMENT_HEAD')") |
|
262
|
|
|
*/ |
|
263
|
|
|
public function groupIndexAction(Request $request) |
|
264
|
|
|
{ |
|
265
|
|
|
return $this->genericIndexAction(self::$GROUP_ENTITY_DATA, $request); |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* @Route("/admin/grupos/nuevo", name="admin_group_new", methods={"GET", "POST"}) |
|
270
|
|
|
* @Route("/admin/grupos/{id}", name="admin_group_form", methods={"GET", "POST"}, requirements={"id": "\d+"}) |
|
271
|
|
|
* @Security("is_granted('ROLE_ADMIN')") |
|
272
|
|
|
*/ |
|
273
|
|
|
public function groupFormAction(Group $element = null, Request $request) |
|
274
|
|
|
{ |
|
275
|
|
|
return $this->genericFormAction(self::$GROUP_ENTITY_DATA, $element, $request); |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* @Route("/admin/grupos/eliminar/{id}", name="admin_group_delete", methods={"GET", "POST"}, requirements={"id": "\d+"} ) |
|
280
|
|
|
* @Security("is_granted('ROLE_ADMIN')") |
|
281
|
|
|
*/ |
|
282
|
|
|
public function groupDeleteAction(Group $element, Request $request) |
|
283
|
|
|
{ |
|
284
|
|
|
return $this->genericDeleteAction(self::$GROUP_ENTITY_DATA, $element, $request); |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
/** |
|
288
|
|
|
* @Route("/admin/ensenanzas", name="admin_training", methods={"GET"}) |
|
289
|
|
|
* @Security("is_granted('ROLE_ADMIN')") |
|
290
|
|
|
*/ |
|
291
|
|
|
public function trainingIndexAction(Request $request) |
|
292
|
|
|
{ |
|
293
|
|
|
return $this->genericIndexAction(self::$TRAINING_ENTITY_DATA, $request); |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* @Route("/admin/ensenanzas/nueva", name="admin_training_new", methods={"GET", "POST"}) |
|
298
|
|
|
* @Route("/admin/ensenanzas/{id}", name="admin_training_form", methods={"GET", "POST"}, requirements={"id": "\d+"}) |
|
299
|
|
|
* @Security("is_granted('ROLE_ADMIN')") |
|
300
|
|
|
*/ |
|
301
|
|
|
public function trainingFormAction(Training $element = null, Request $request) |
|
302
|
|
|
{ |
|
303
|
|
|
return $this->genericFormAction(self::$TRAINING_ENTITY_DATA, $element, $request); |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
/** |
|
307
|
|
|
* @Route("/admin/ensenanzas/eliminar/{id}", name="admin_training_delete", methods={"GET", "POST"}, requirements={"id": "\d+"} ) |
|
308
|
|
|
* @Security("is_granted('ROLE_ADMIN')") |
|
309
|
|
|
*/ |
|
310
|
|
|
public function trainingDeleteAction(Training $element, Request $request) |
|
311
|
|
|
{ |
|
312
|
|
|
return $this->genericDeleteAction(self::$TRAINING_ENTITY_DATA, $element, $request); |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
/** |
|
316
|
|
|
* @Route("/admin/diasnolectivos", name="admin_non_school_day", methods={"GET"}) |
|
317
|
|
|
* @Security("is_granted('ROLE_ADMIN')") |
|
318
|
|
|
*/ |
|
319
|
|
|
public function nonSchoolDayIndexAction(Request $request) |
|
320
|
|
|
{ |
|
321
|
|
|
return $this->genericIndexAction(self::$NON_SCHOOL_DAY_ENTITY_DATA, $request); |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
/** |
|
325
|
|
|
* @Route("/admin/diasnolectivos/nuevo", name="admin_non_school_day_new", methods={"GET", "POST"}) |
|
326
|
|
|
* @Route("/admin/diasnolectivos/{id}", name="admin_non_school_day_form", methods={"GET", "POST"}) |
|
327
|
|
|
* @Security("is_granted('ROLE_ADMIN')") |
|
328
|
|
|
*/ |
|
329
|
|
|
public function nonSchoolDayFormAction(NonSchoolDay $element = null, Request $request) |
|
330
|
|
|
{ |
|
331
|
|
|
return $this->genericFormAction(self::$NON_SCHOOL_DAY_ENTITY_DATA, $element, $request); |
|
332
|
|
|
} |
|
333
|
|
|
|
|
334
|
|
|
/** |
|
335
|
|
|
* @Route("/admin/diasnolectivos/eliminar/{id}", name="admin_non_school_day_delete", methods={"GET", "POST"}) |
|
336
|
|
|
* @Security("is_granted('ROLE_ADMIN')") |
|
337
|
|
|
*/ |
|
338
|
|
|
public function workcenterDeleteAction(Workcenter $element, Request $request) |
|
339
|
|
|
{ |
|
340
|
|
|
return $this->genericDeleteAction(self::$NON_SCHOOL_DAY_ENTITY_DATA, $element, $request); |
|
341
|
|
|
} |
|
342
|
|
|
} |
|
343
|
|
|
|