|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
GESTCONV - Aplicación web para la gestión de la convivencia en centros educativos |
|
4
|
|
|
|
|
5
|
|
|
Copyright (C) 2015: 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\Alumno; |
|
24
|
|
|
use AppBundle\Entity\AvisoSancion; |
|
25
|
|
|
use AppBundle\Entity\ObservacionSancion; |
|
26
|
|
|
use AppBundle\Entity\Sancion; |
|
27
|
|
|
use AppBundle\Form\Type\NuevaObservacionType; |
|
28
|
|
|
use AppBundle\Form\Type\NuevaSancionType; |
|
29
|
|
|
use AppBundle\Form\Type\RangoFechasInformeType; |
|
30
|
|
|
use AppBundle\Form\Type\SancionType; |
|
31
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
32
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; |
|
33
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
34
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
35
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @Route("/sancion") |
|
39
|
|
|
*/ |
|
40
|
|
|
|
|
41
|
|
|
class SancionController extends BaseController |
|
42
|
|
|
{ |
|
43
|
|
|
/** |
|
44
|
|
|
* @Route("/nueva/{alumno}", name="parte_sancionar",methods={"GET", "POST"}) |
|
45
|
|
|
* @Security("has_role('ROLE_REVISOR')") |
|
46
|
|
|
*/ |
|
47
|
|
|
public function sancionarAction(Alumno $alumno, Request $peticion) |
|
48
|
|
|
{ |
|
49
|
|
|
$sancion = new Sancion(); |
|
50
|
|
|
$usuario = $this->getUser(); |
|
51
|
|
|
|
|
52
|
|
|
$sancion->setFechaSancion(new \DateTime()) |
|
53
|
|
|
->setUsuario($usuario) |
|
|
|
|
|
|
54
|
|
|
->setRegistradoEnSeneca(false); |
|
55
|
|
|
|
|
56
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
57
|
|
|
|
|
58
|
|
|
$partes = $em->getRepository('AppBundle:Parte')->findAllSancionablesPorAlumno($alumno); |
|
59
|
|
|
|
|
60
|
|
|
$formulario = $this->createForm(new NuevaSancionType(), $sancion, array( |
|
61
|
|
|
'alumno' => $alumno |
|
62
|
|
|
)); |
|
63
|
|
|
|
|
64
|
|
|
$formulario->handleRequest($peticion); |
|
65
|
|
|
|
|
66
|
|
|
if ($formulario->isSubmitted() && $formulario->isValid()) { |
|
67
|
|
|
|
|
68
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
69
|
|
|
|
|
70
|
|
|
foreach($sancion->getPartes() as $parte) { |
|
71
|
|
|
$parte->setSancion($sancion); |
|
72
|
|
|
} |
|
73
|
|
|
$em->persist($sancion); |
|
74
|
|
|
$em->flush(); |
|
75
|
|
|
|
|
76
|
|
|
$this->notificarSancion($alumno->getGrupo()->getTutores(), $sancion); |
|
77
|
|
|
$this->notificarSancion($em->getRepository('AppBundle:Usuario')->getUsuariosDeSancion($sancion), $sancion); |
|
78
|
|
|
|
|
79
|
|
|
$this->addFlash('success', 'Se ha registrado la sanción'); |
|
80
|
|
|
|
|
81
|
|
|
// redireccionar a la portada |
|
82
|
|
|
return new RedirectResponse( |
|
83
|
|
|
$this->generateUrl('parte_pendiente') |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return $this->render('AppBundle:Parte:sancionar.html.twig', |
|
88
|
|
|
array( |
|
89
|
|
|
'alumno' => $alumno, |
|
90
|
|
|
'partes' => $partes, |
|
91
|
|
|
'sanciones' => $em->getRepository('AppBundle:Sancion')->findAllPorAlumno($alumno), |
|
92
|
|
|
'formulario' => $formulario->createView(), |
|
93
|
|
|
'usuario' => $usuario |
|
94
|
|
|
)); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @Route("/notificar", name="sancion_listado_notificar",methods={"GET", "POST"}) |
|
99
|
|
|
* @Security("has_role('ROLE_REVISOR') or has_role('ROLE_TUTOR') ") |
|
100
|
|
|
*/ |
|
101
|
|
|
public function listadoNotificarAction(Request $request) |
|
102
|
|
|
{ |
|
103
|
|
|
$usuario = $this->getUser(); |
|
104
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
105
|
|
|
|
|
106
|
|
|
if (($request->getMethod() === 'POST') && (($request->request->get('noNotificada')) || ($request->request->get('notificada')))) { |
|
107
|
|
|
|
|
108
|
|
|
$id = $request->request->get(($request->request->get('notificada')) ? 'notificada' : 'noNotificada'); |
|
109
|
|
|
|
|
110
|
|
|
$sanciones = $em->getRepository('AppBundle:Sancion') |
|
111
|
|
|
->findAllNoNotificadosPorAlumno($id); |
|
112
|
|
|
|
|
113
|
|
|
foreach ($sanciones as $sancion) { |
|
114
|
|
|
$avisoSancion = new AvisoSancion(); |
|
115
|
|
|
$avisoSancion |
|
116
|
|
|
->setSancion($sancion) |
|
117
|
|
|
->setUsuario($usuario) |
|
|
|
|
|
|
118
|
|
|
->setAnotacion($request->request->get('anotacion')) |
|
119
|
|
|
->setFecha(new \DateTime()) |
|
120
|
|
|
->setTipo($em->getRepository('AppBundle:CategoriaAviso')->find($request->request->get('tipo'))); |
|
121
|
|
|
|
|
122
|
|
|
if ($request->request->get('notificada')) { |
|
123
|
|
|
$sancion->setFechaComunicado(new \DateTime()); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
$em->persist($avisoSancion); |
|
127
|
|
|
} |
|
128
|
|
|
$em->flush(); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
$alumnos = ($this->isGranted('ROLE_REVISOR')) |
|
132
|
|
|
? $em->getRepository('AppBundle:Alumno')->findAllConSancionesAunNoNotificadas() |
|
133
|
|
|
: $em->getRepository('AppBundle:Alumno')->findAllConSancionesAunNoNotificadasPorTutoria($usuario); |
|
134
|
|
|
|
|
135
|
|
|
if (count($alumnos) == 0) { |
|
136
|
|
|
// redireccionar a la portada |
|
137
|
|
|
return new RedirectResponse( |
|
138
|
|
|
$this->generateUrl('portada') |
|
139
|
|
|
); |
|
140
|
|
|
} |
|
141
|
|
|
return $this->render('AppBundle:Sancion:notificar.html.twig', |
|
142
|
|
|
array( |
|
143
|
|
|
'usuario' => $usuario, |
|
144
|
|
|
'alumnos' => $alumnos, |
|
145
|
|
|
'tipos' => $em->getRepository('AppBundle:CategoriaAviso')->findAll() |
|
146
|
|
|
)); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @Route("/listar", name="sancion_listar",methods={"GET"}) |
|
152
|
|
|
* @Security("has_role('ROLE_REVISOR')") |
|
153
|
|
|
*/ |
|
154
|
|
|
public function listarAction() |
|
155
|
|
|
{ |
|
156
|
|
|
$usuario = $this->getUser(); |
|
157
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
158
|
|
|
|
|
159
|
|
|
$sanciones = $em->getRepository('AppBundle:Sancion') |
|
160
|
|
|
->createQueryBuilder('s') |
|
161
|
|
|
->orderBy('s.fechaSancion', 'DESC') |
|
162
|
|
|
->getQuery() |
|
163
|
|
|
->getResult(); |
|
164
|
|
|
|
|
165
|
|
|
return $this->render('AppBundle:Sancion:listar.html.twig', |
|
166
|
|
|
array( |
|
167
|
|
|
'sanciones' => $sanciones, |
|
168
|
|
|
'usuario' => $usuario |
|
169
|
|
|
)); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @Route("/detalle/{sancion}", name="sancion_detalle",methods={"GET", "POST"}) |
|
174
|
|
|
* @Security("has_role('ROLE_REVISOR')") |
|
175
|
|
|
*/ |
|
176
|
|
|
public function detalleAction(Sancion $sancion, Request $request) |
|
177
|
|
|
{ |
|
178
|
|
|
$usuario = $this->getUser(); |
|
179
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
180
|
|
|
|
|
181
|
|
|
$formularioSancion = $this->createForm(new SancionType(), $sancion, array( |
|
182
|
|
|
'admin' => true, |
|
183
|
|
|
'bloqueado' => false |
|
184
|
|
|
)); |
|
185
|
|
|
|
|
186
|
|
|
$formularioSancion->get('sinSancion')->setData($sancion->getMotivosNoAplicacion() !== null); |
|
187
|
|
|
|
|
188
|
|
|
$observacion = new ObservacionSancion(); |
|
189
|
|
|
$observacion |
|
190
|
|
|
->setSancion($sancion) |
|
191
|
|
|
->setFecha(new \DateTime()) |
|
192
|
|
|
->setUsuario($usuario); |
|
|
|
|
|
|
193
|
|
|
|
|
194
|
|
|
$formularioObservacion = $this->createForm(new NuevaObservacionType(), $observacion, array( |
|
195
|
|
|
'admin' => $this->isGranted('ROLE_ADMIN') |
|
196
|
|
|
)); |
|
197
|
|
|
|
|
198
|
|
|
$formularioObservacion->handleRequest($request); |
|
199
|
|
|
|
|
200
|
|
|
if ($formularioObservacion->isSubmitted() && $formularioObservacion->isValid()) { |
|
201
|
|
|
$em->persist($observacion); |
|
202
|
|
|
$em->flush(); |
|
203
|
|
|
$this->addFlash('success', 'Observación registrada correctamente'); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
$formularioSancion->handleRequest($request); |
|
207
|
|
|
|
|
208
|
|
|
if ($formularioSancion->isSubmitted() && $formularioSancion->isValid()) { |
|
209
|
|
|
|
|
210
|
|
|
$em->flush(); |
|
211
|
|
|
|
|
212
|
|
|
$this->addFlash('success', 'Se han registrado correctamente los cambios en la sanción'); |
|
213
|
|
|
|
|
214
|
|
|
return new RedirectResponse( |
|
215
|
|
|
$this->generateUrl('sancion_listar') |
|
216
|
|
|
); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
return $this->render('AppBundle:Sancion:detalle.html.twig', |
|
220
|
|
|
array( |
|
221
|
|
|
'sancion' => $sancion, |
|
222
|
|
|
'formulario_sancion' => $formularioSancion->createView(), |
|
223
|
|
|
'formulario_observacion' => $formularioObservacion->createView(), |
|
224
|
|
|
'usuario' => $usuario |
|
225
|
|
|
)); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* @Route("/informe", name="sancion_informe",methods={"GET", "POST"}) |
|
231
|
|
|
* @Security("has_role('ROLE_REVISOR')") |
|
232
|
|
|
*/ |
|
233
|
|
|
public function informeAction(Request $request) |
|
234
|
|
|
{ |
|
235
|
|
|
$usuario = $this->getUser(); |
|
236
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
237
|
|
|
|
|
238
|
|
|
$fechasPorDefecto = array('desde' => null, 'hasta' => null); |
|
239
|
|
|
|
|
240
|
|
|
$formFechas = $this->createForm(new RangoFechasInformeType(), $fechasPorDefecto) |
|
241
|
|
|
->handleRequest($request); |
|
242
|
|
|
|
|
243
|
|
|
$fechas = ($formFechas->isValid()) ? $formFechas->getData() : array('desde' => null, 'hasta' => null); |
|
244
|
|
|
|
|
245
|
|
|
$alumnado = $em->getRepository('AppBundle:Alumno')->getSancionadosPorFecha($fechas); |
|
246
|
|
|
|
|
247
|
|
|
if ($formFechas->isValid() && $formFechas->get('generar')->isClicked()) { |
|
|
|
|
|
|
248
|
|
|
$plantilla = $this->container->getParameter('listado'); |
|
249
|
|
|
$logos = $this->container->getParameter('logos'); |
|
250
|
|
|
|
|
251
|
|
|
$pdf = $this->generarPdf('Informe de sanciones', $logos, $plantilla, -15); |
|
252
|
|
|
|
|
253
|
|
|
$html = $this->renderView('AppBundle:Sancion:imprimir_informe.html.twig', |
|
254
|
|
|
array( |
|
255
|
|
|
'items' => $alumnado, |
|
256
|
|
|
'fechas' => $fechas |
|
257
|
|
|
)); |
|
258
|
|
|
|
|
259
|
|
|
$pdf->writeHTML($html); |
|
260
|
|
|
|
|
261
|
|
|
$response = new Response($pdf->Output( 'Informe_de_sanciones_' . date('Y-m-d H-i-s') . '.pdf')); |
|
262
|
|
|
$response->headers->set('Content-Type', 'application/pdf'); |
|
263
|
|
|
|
|
264
|
|
|
return $response; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
return $this->render('AppBundle:Sancion:listar_informe.html.twig', |
|
268
|
|
|
array( |
|
269
|
|
|
'formulario_fechas' => $formFechas->createView(), |
|
270
|
|
|
'items' => $alumnado, |
|
271
|
|
|
'usuario' => $usuario |
|
272
|
|
|
)); |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
/** |
|
276
|
|
|
* @Route("/imprimir/{sancion}", name="sancion_detalle_pdf",methods={"GET"}) |
|
277
|
|
|
* @Security("has_role('ROLE_REVISOR')") |
|
278
|
|
|
*/ |
|
279
|
|
|
public function detallePdfAction(Sancion $sancion) |
|
280
|
|
|
{ |
|
281
|
|
|
$usuario = $this->getUser(); |
|
282
|
|
|
$plantilla = $this->container->getParameter('sancion'); |
|
283
|
|
|
$logos = $this->container->getParameter('logos'); |
|
284
|
|
|
|
|
285
|
|
|
$pdf = $this->generarPdf('Sancion #' . $sancion->getId(), $logos, $plantilla, -15, 'S' . $sancion->getId()); |
|
286
|
|
|
|
|
287
|
|
|
$html = $this->renderView('AppBundle:Sancion:imprimir.html.twig', |
|
288
|
|
|
array( |
|
289
|
|
|
'sancion' => $sancion, |
|
290
|
|
|
'usuario' => $usuario, |
|
291
|
|
|
'localidad' => $this->container->getParameter('localidad'), |
|
292
|
|
|
'director' => $this->container->getParameter('director') |
|
293
|
|
|
)); |
|
294
|
|
|
|
|
295
|
|
|
$pdf->writeHTML($html); |
|
296
|
|
|
|
|
297
|
|
|
$response = new Response($pdf->Output('sancion_' . $sancion->getId() . '.pdf')); |
|
298
|
|
|
$response->headers->set('Content-Type', 'application/pdf'); |
|
299
|
|
|
|
|
300
|
|
|
return $response; |
|
301
|
|
|
} |
|
302
|
|
|
} |
|
303
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.