AjaxController.php
1.76 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
<?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;
/**
* 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();
$posts = $em->getRepository('AppBundle:DocenteServicio')->findBy(array(
'idEstatus' => 2
));
$cuenta = count($posts);
$response = new JsonResponse();
$response->setStatusCode(200);
$response->setData(array(
'response' => 'success',
'posts' => $serializer->serialize($cuenta, 'json')
));
return $response;
}
}
}