AppController.php
15.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\Adscripcion;
use AppBundle\Entity\DocenteServicio;
/**
* Description of DocenteController
*
* @author ubv-cipee
*
* @Route("/ceapp")
*
*/
class AppController extends Controller {
/**
* Pagina principal de inicio de la session Docente.
*
* @Route("/", name="cea_index")
* @Method("GET")
*/
public function indexAction()
{
//verificar en las solicitudes la adscripcion del docente
$servicioAdscripcion = $this->getDoctrine()->getRepository('AppBundle:DocenteServicio')->
findOneBy(array(
'idRolInstitucion' => $this->getUser()->getIdRolInstitucion()->getId(),
'idServicioCe' => 2
));
$ascenso = $this->getDoctrine()->getRepository('AppBundle:DocenteServicio')->
findOneBy(array(
'idRolInstitucion' => $this->getUser()->getIdRolInstitucion()->getId(),
'idServicioCe' => 5),
array('id' => 'DESC')
);
//si no ha solicitado adscripción regresa a la pagina de adscripcion
if(!$servicioAdscripcion){ return $this->redirect($this->generateUrl('solicitud_adscripcion')); }
$pida = $this->getDoctrine()->getRepository('AppBundle:DocenteServicio')->
findOneBy(array(
'idRolInstitucion' => $this->getUser()->getIdRolInstitucion()->getId(),
'idServicioCe' => 4),
array('id' => 'DESC')
);
$em = $this->getDoctrine()->getManager();
if(!$pida){
$this->addFlash('warning', 'Estimado Docente Mientras se verifica su adscripción, le solicitamos que por favor cree su PIDA.');
return $this->redirectToRoute('solicitud_pida');
}else{
$caducidad = $this->getDoctrine()->getRepository("AppBundle:PidaCaducidad")->findOneByIdDocenteServicio($pida);
if($caducidad){
//saber si el pida actual caducó
$hoy = new \DateTime("now");
$tiempo = ($hoy->diff($caducidad->getFechaFinal()));
$vigente = $tiempo->invert ? false : true;
if($tiempo->format('%a%') <= 60 && $tiempo->format('%a%') >= 30){
$suffix = ( $tiempo->invert ? ' venció hace' : 'estará viegene por' );
$this->addFlash('warning', 'Estimado docente su PIDA ' . $suffix . $tiempo->format('%a%') . ' días más' );
}else if($tiempo->format('%a%') <= 29 && $vigente){
$this->addFlash('danger', 'Estimado docente dentro de ' . $tiempo->format('%a%') . ' días su PIDA caducará y deberá crear uno nuevo');
}
//var_dump($tiempo); die;
$vencido = ($tiempo->invert ? true : false);
if($vencido){
$pida->setIdEstatus($this->getDoctrine()->getRepository("AppBundle:Estatus")->findOneById(5));
$em->persist($pida);
$em->flush();
$this->addFlash('danger', 'Su pida Actual venció, por favor registre un nuevo PIDA.');
return $this->redirect($this->generateUrl('solicitud_pida'));
}
}
}
$adscripcionPida = $this->getDoctrine()->getRepository('AppBundle:AdscripcionPida')->
findBy(array(
'idRolInstitucion' => $this->getUser()->getIdRolInstitucion()->getId()
));
$escalafon = $this->getDoctrine()->getRepository('AppBundle:DocenteEscala')->findOneBy(
array('idRolInstitucion' => $this->getUser()->getIdRolInstitucion()),
array('id' => 'DESC')
);
$tiempoTranscurrido = 0;
$suffix = "";
if ($escalafon->getidEscala()->getId() != 5){
$escalafones = $this->getDoctrine()->getRepository("AppBundle:Escalafones")->findOneById($escalafon->getIdEscala()->getId() + 1); //tiempo para el proximo escalafon
if($escalafones){
//tiempo para el prox escalafon
$tiempoProxEscalafon = $escalafon->getFechaEscala()->modify('+' . $escalafones->getTiempo() . 'years');
$hoy = new \DateTime("now");
$tiempoTranscurrido = $hoy->diff($tiempoProxEscalafon);
$suffix = ( $tiempoTranscurrido->invert ? ' ago' : '' );
}
}
$adscripcion = $this->getDoctrine()->getRepository("AppBundle:Adscripcion")->findOneByIdRolInstitucion($this->getUser()->getIdRolInstitucion()->getId());
//solicitud aprobada está en falso
$adscrito = false;
if($servicioAdscripcion->getIdEstatus()->getId() == 1){ $adscrito = true; }
return $this->render('cea/index.html.twig', array (
'adscrito' => $adscrito,
'adscripcion' => $adscripcion,
'ascenso' => $ascenso,
'tiempoProxEscalafon' => $tiempoTranscurrido,
'suffix' => $suffix
));
}
/**
* Muestra la página Puede ver los estatus de las solicitudes realizadas
* y permite realizar la solicitud
*
* @Route("/servicios/{tipo}/{estatus}", name="cea_servicios")
* @Method({"GET", "POST"})
*/
public function verServiciosAction(Request $request, $tipo="antiguedad", $estatus=2){
if ($tipo == "antiguedad") $tipo_servicio = 1;
if ($request->getMethod() != 'POST') {
$servicios = $this->getDoctrine()->getRepository('AppBundle:DocenteServicio')->findBy(array(
'idEstatus' => $estatus,
));
switch ($estatus){
case 1:
$mensaje = "activas";
break;
case 2:
$mensaje = "en espera";
break;
case 3:
$mensaje = "rechazadas";
break;
}
}else{
$persona = $this->getDoctrine()->getRepository('AppBundle:Persona')
->findOneByCedulaPasaporte($request->get('docente'));
if (!$persona) {
$this->addFlash('danger', 'Docente ' . $request->get('docente') . ' no Registrado en la Base de Datos del Centro de Estudios.');
return $this->render('cea/index.html.twig', array (
'adscrito' => true
));
}
//1. obtener el rol-institucion-persona
$rol = $this->getDoctrine()->getRepository(
'AppBundle:RolInstitucion')->findOneByIdRol(
$this->getDoctrine()->getRepository(
'AppBundle:Rol')->findOneByIdPersona($persona));
//si no existe el rol del docente, enviar correo al encargado de la región para verificar.
if (!$rol) {
$this->addFlash('danger', 'Docente no Registrado en la Base de Datos del Centro de Estudios. Por Favor');
return $this->render('cea/index.html.twig');
}
$servicios = $this->getDoctrine()->getRepository('AppBundle:DocenteServicio')->findByIdRolInstitucion($rol->getId());
$mensaje = "Busqueda : " . $request->get('docente');
}
return $this->render('cea/servicios.html.twig', array(
'servicios' => $servicios,
'estatus_servicio' => $mensaje,
'tipo' => $tipo
));
}
/**
* Encuentra y muestra una entidad de tipo Servicios Docente.
*
* @Route("/ver_servicio/{id}", name="cea_servicio_show")
* @Method("GET")
*/
public function serviciosShowAction(DocenteServicio $servicio)
{
$em = $this->getDoctrine()->getManager();
$docente = $em->getRepository("AppBundle:RolInstitucion")->findOneById($servicio->getIdRolInstitucion()->getId());
$adscripcion = $this->getDoctrine()->getRepository('AppBundle:Adscripcion')->findOneByIdRolInstitucion($servicio->getIdRolInstitucion());
$escala = $this->getDoctrine()->getRepository('AppBundle:DocenteEscala')->findOneBy(array(
'idRolInstitucion' => $servicio->getIdRolInstitucion(),
'idTipoEscala' => 1
));
return $this->render('cea/servicios_mostar.html.twig', array(
'servicio' => $servicio,
'oposicion' => $escala,
'adscripcion' => $adscripcion,
'docente' => $docente
));
}
/**
* Muestra la página donde explica brevemente el reconocimiento de Antiguedad
* y permite realizar la solicitud
*
* @Route("/mis_servicios/", name="servicios_index")
* @Method({"GET", "POST"})
*/
public function serviciosIndexAction(){
$servicios = $this->getDoctrine()->getRepository('AppBundle:DocenteServicio')->findByIdRolInstitucion($this->getUser()->getIdRolInstitucion());
$adscripcion = $this->getDoctrine()->getRepository('AppBundle:Adscripcion')->findOneByIdRolInstitucion($this->getUser()->getIdRolInstitucion());
return $this->render('solicitudes/index.html.twig', array(
'servicios' => $servicios,
'adscripcion' => $adscripcion
));
}
/**
* Encuentra y muestra una entidad de tipo Adscripción.
*
* @Route("/servicios/actualizar/{id}/{estatus}", name="cea_servicios_actualizar")
* @Method({"GET", "POST"})
*/
public function serviciosEditAction(DocenteServicio $servicios, $estatus, Request $request)
{
$em = $this->getDoctrine()->getManager();
$mensaje = "";
if($estatus == "true") {
$servicios->setIdEstatus($this->getDoctrine()->getRepository('AppBundle:Estatus')->findOneById(1));
if($servicios->getIdServicioCe()->getId() == '3'){
$user = $this->getDoctrine()->getRepository('AppBundle:Usuarios')->findOneByIdRolInstitucion($servicios->getIdRolInstitucion());
$user->addRol($this->getDoctrine()->getRepository('AppBundle:Role')->findOneByName("ROLE_ESTUDIANTE"));
$em->persist($user);
}
$parametros = $request->request->all();
//Guardar el resultado de la verificación de Documentos de los permisos sabaticos
if($servicios->getIdServicioCe()->getId() == 8){
verificar_documentos4($servicios->getIdRolInstitucion(), 18, 1, $em, "", $servicios);
}
}else{
$mensaje = $request->request->get('message-text');
$servicios->setIdEstatus($this->getDoctrine()->getRepository('AppBundle:Estatus')->findOneById(3));
if($servicios->getIdServicioCe()->getId() == '3'){
$user = $this->getDoctrine()->getRepository('AppBundle:Usuarios')->findOneByIdRolInstitucion($servicios->getIdRolInstitucion());
$user->removeRol($this->getDoctrine()->getRepository('AppBundle:Role')->findOneByName("ROLE_ESTUDIANTE"));
$em->persist($user);
}
//Guardar el resultado de la verificación de Documentos de los permisos sabaticos
if($servicios->getIdServicioCe()->getId() == 8){
verificar_documentos4($servicios->getIdRolInstitucion(), 18, 3, $em, "", $servicios);
}
}
$em->persist($servicios);
$em->flush();
$user = $this->getDoctrine()->getRepository('AppBundle:Usuarios')->findOneByIdRolInstitucion($servicios->getIdRolInstitucion());
/*$message = \Swift_Message::newInstance()
->setSubject('Resultado Solicitud de Servicio Docente CEA@UBV')
->setFrom('wilmer.ramones@gmail.com')
->setTo($user->getEmail())
->setBody(
$this->renderView(
'correos/actualizar_servicio.html.twig',
array(
'nombres' => $user->getIdRolInstitucion()->getIdRol()->getIdPersona()->getPrimerNombre(),
'apellidos' => $user->getIdRolInstitucion()->getIdRol()->getIdPersona()->getPrimerApellido(),
'servicio' => $servicios,
'mensaje' => $mensaje,
)
),
'text/html'
)
;
$this->get('mailer')->send($message);*/
$this->addFlash('notice', 'Servicio Actualizada Correctamente, hemos enviado un correo al docente notificandole los cambios.');
$escala = $this->getDoctrine()->getRepository('AppBundle:DocenteEscala')->findOneBy(array(
'idRolInstitucion' => $servicios->getIdRolInstitucion(),
'idTipoEscala' => 1
));
$adscripcion = $this->getDoctrine()->getRepository('AppBundle:Adscripcion')->findOneByIdRolInstitucion($servicios->getIdRolInstitucion());
$ea = $this->getDoctrine()->getRepository('AppBundle:EstadoAcademico')->findOneByIdDocenteServicio($servicios);
return $this->render('cea/servicios_mostar.html.twig', array(
'servicio' => $servicios,
'docente' => $servicios->getIdRolInstitucion(),
'oposicion' => $escala,
'adscripcion' => $adscripcion,
'estado_academico' => $ea
));
}
}
function verificar_documentos4($idRolInstitucion, $tipo, $estatus, $em, $ubicacion="", $servicio){
$existe = $em->getRepository("AppBundle:DocumentosVerificados")->findOneBy(array(
'idRolInstitucion' => $idRolInstitucion,
'idTipoDocumentos' => $tipo
));
if(!$existe) {
$verificacion = new DocumentosVerificados();
$verificacion->setIdEstatus($em->getRepository("AppBundle:Estatus")->findOneById($estatus));
$verificacion->setIdRolInstitucion($idRolInstitucion);
$verificacion->setIdServicio($servicio);
$verificacion->setIdTipoDocumentos($em->getRepository("AppBundle:TipoDocumentos")->findOneById($tipo));
$verificacion->setUbicacion($ubicacion);
$em->persist($verificacion);
$em->flush();
}else{
$existe->setIdEstatus($em->getRepository("AppBundle:Estatus")->findOneById($estatus));
$em->persist($existe);
$em->flush();
}
}