AjaxController.php
4.75 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
<?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 Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\TutoresAscenso;
/**
* Description of AjaxController
*
* @author ubv-cipee
*
*
*/
class AjaxController extends Controller {
/**
* @Route("/ajax/contador_solicitudes", name="ajax_contador_solicitudes")
* @Method({"GET"})
*/
public function contadorAction(Request $request){
if($request->isXmlHttpRequest()){
$encoders = array(new JsonEncoder());
$normalizers = array(new ObjectNormalizer());
$serializer = new Serializer($normalizers, $encoders);
$em = $this->getDoctrine()->getManager();
if ($this->get('security.authorization_checker')->isGranted('ROLE_COORDINADOR_NACIONAL')){
$posts = $em->getRepository('AppBundle:DocenteServicio')->findBy(array(
'idEstatus' => 2
));
//si no es coordinador nacional, entonces no cuente las solcitudes de antiguedad
//que son de tipo 1
}else{
$repository = $this->getDoctrine()
->getRepository('AppBundle:DocenteServicio');
$query = $repository->createQueryBuilder('p')
->where('p.idEstatus = :estatus')
->andWhere('p.idServicioCe > :identificador')
->setParameters(array('estatus'=> 2, 'identificador' => 2))
->getQuery();
$posts = $query->getResult();
}
$cuenta = count($posts);
$response = new JsonResponse();
$response->setStatusCode(200);
$response->setData(array(
'response' => 'success',
'posts' => $serializer->serialize($cuenta, 'json')
));
return $response;
}
}
/**
* @Route("/ajax/buscar_tutor", name="ajax_buscar_tutor")
* @Method({"GET"})
*/
public function buscarTutorAction(Request $request){
//if($request->isXmlHttpRequest()){
$encoders = array(new JsonEncoder());
$normalizers = array(new ObjectNormalizer());
$serializer = new Serializer($normalizers, $encoders);
$cedula = filter_input(INPUT_GET, 'cedula', FILTER_SANITIZE_SPECIAL_CHARS);
$documento = filter_input(INPUT_GET, 'documento', FILTER_SANITIZE_SPECIAL_CHARS);
$repository = $this->getDoctrine()->getRepository('AppBundle:TutoresAscenso')->findOneBy(array(
'idDocumentoIdentidad' => $documento,
'cedulaPasaporte' => $cedula
));
$response = new JsonResponse();
$response->setStatusCode(200);
$response->setData(array(
'response' => 'success',
'posts' => $serializer->serialize($repository, 'json')
));
return $response;
//}
}
/**
* @Route("/ajax/registrar_tutor", name="ajax_registrar_tutor")
* @Method({"POST"})
*/
public function registrarTutorAction(Request $request){
//if($request->isXmlHttpRequest()){
$encoders = array(new JsonEncoder());
$normalizers = array(new ObjectNormalizer());
$serializer = new Serializer($normalizers, $encoders);
$nuevoTutor = new TutoresAscenso();
$form = $this->createForm('AppBundle\Form\TutoresAscensoType', $nuevoTutor);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($nuevoTutor);
$em->flush();
return new JsonResponse(array('message' => 'Success!'), 200);
}
echo $form;
$response = new JsonResponse(
array(
'message' => $form,
), 400);
return $response;
//}
}
}