src/Noahtech/Sistemas/InterjamaBundle/Controller/VepController.php line 48

Open in your IDE?
  1. <?php
  2. namespace Noahtech\Sistemas\InterjamaBundle\Controller;
  3. use Noahtech\Sistemas\InterjamaBundle\Utils\Codes;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Noahtech\Sistemas\InterjamaBundle\Controller\BaseController;
  8. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  9. use Noahtech\Sistemas\InterjamaBundle\Handler\McVepHandler;
  10. class VepController extends BaseController {
  11.     private function validarAdmin () {
  12.         $usuario $this->getUser();
  13.         $admin false;
  14.         foreach ($usuario->getRoles() as $rol) {            
  15.             if ($rol == 'ROLE_ADMIN'){
  16.                 $admin true;
  17.             }
  18.         }
  19.         if (!$admin){
  20.             throw new AccessDeniedException("No tiene permiso para acceder a esta pagina.");
  21.         }
  22.     }
  23.     /**
  24.      * @Route("/admin/veps", name="admin_vep_listado")
  25.      * @return type
  26.      */
  27.     public function vepListadoAction() {
  28.         $this->validarAdmin();
  29.         $usuario $this->getUser();
  30.         $this->setTitle("Listado de VEPS | InterJama");
  31.         $this->addBreadCrumb("Inicio - Admin"false"admin_home");
  32.         $this->addBreadCrumb("Listado de VEPS"true);        
  33.         $this->data['data'] = null;
  34.         return $this->render(
  35.                         '@NoahtechSistemasInterjama/admin/veps/listado.html.twig'$this->data
  36.         );
  37.     }
  38.     /**
  39.      * consulta de veps
  40.      *
  41.      * @Route("/admin/ajax/veps/search", name="admin_ajax_veps_listado", methods={"POST"}, condition="request.isXmlHttpRequest()")
  42.      */
  43.     public function searchAction(Request $request) {
  44.         $this->validarAdmin();
  45.         $searchParam $request->request->all();
  46.         $currentPage $request->query->get('page');
  47.         $sortField $request->query->get('sort');
  48.         $sortDirection $request->query->get('direction');
  49.         $currentPage null == $currentPage $currentPage;
  50.         $offset = ($currentPage 1) * $this->getTamanioPagina();
  51.         $limit $this->getTamanioPagina();
  52.         try {
  53.             /** @var McVepHandler $handler */
  54.             $handler $this->get(McVepHandler::class);
  55.             $lp $handler->search($offset$limit$sortField$sortDirection$searchParam);
  56.             $lp->setCurrentPage($currentPage);
  57.             $lp->setPageSize($this->getTamanioPagina());
  58.             $this->response->setData($lp);
  59.             $this->response->setCode(Codes::OK);
  60.         } catch (Exception $e) {
  61.             $this->response->setCode(Codes::ERROR);
  62.             $this->response->setMessage($e->getMessage());
  63.         }
  64.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  65.         return new Response($serializedEntity);
  66.     }
  67.     /**
  68.      * @Route("/admin/vep/nuevo", name="admin_vep_nuevo")
  69.      * @return type
  70.      */
  71.     public function vepNuevoAction() {
  72.         $this->validarAdmin();
  73.         $this->setTitle("Nuevo VEP");
  74.         $this->addBreadCrumb("Inicio - Admin"false"admin_home");        
  75.         $this->addBreadCrumb("Nuevo VEP"true);        
  76.         $this->data['data'] = null;       
  77.         return $this->render(
  78.                         '@NoahtechSistemasInterjama/admin/veps/nuevo.html.twig'$this->data
  79.         );
  80.     }
  81.     /**
  82.      * Guarda una VEP
  83.      *
  84.      * @Route("/admin/ajax/vep", name="admin_vep_save", methods={"POST"}, condition="request.isXmlHttpRequest()")
  85.      */
  86.     public function postSaveAction(Request $request) {
  87.         $this->validarAdmin();
  88.         $comprobante $request->files->get('comprobante');
  89.         try {
  90.             $handler $this->get(McVepHandler::class);            
  91.             $vep $handler->getVepFromRequest($request$comprobante);
  92.             $result $handler->save($vep);
  93.             $this->response->setData($result);
  94.             $this->response->setCode(Codes::OK);            
  95.         } catch (Exception $e) {
  96.             $this->response->setCode(Codes::ERROR);
  97.             $this->response->setMessage($e->getMessage());
  98.         }
  99.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  100.         return new Response($serializedEntity);       
  101.     }
  102.     /**
  103.      * @Route("/admin/vep/{id}", name="admin_vep_modificacion")
  104.      * @return type
  105.      */
  106.     public function vepModificacionAction($id) {
  107.         $this->validarAdmin();
  108.         $this->setTitle("Modificar VEP");
  109.         $this->addBreadCrumb("Inicio - Admin"false"admin_home");
  110.         $this->addBreadCrumb("Listado de VEPS"false"admin_vep_listado");
  111.         $this->addBreadCrumb("Modificar VEP"true);        
  112.         $this->data['data'] = $id;
  113.         return $this->render(
  114.                         '@NoahtechSistemasInterjama/admin/veps/modificacion.html.twig'$this->data
  115.         );
  116.     }
  117.     /**
  118.      * Devuelve un VEP
  119.      *
  120.      * @Route("/admin/ajax/vep/{id}", name="admin_ajax_vep_get_by_id", methods={"GET"}, condition="request.isXmlHttpRequest()")
  121.      */
  122.     public function getVepByIdAction($id) {
  123.         $this->validarAdmin();
  124.         try {
  125.             $handler $this->get(McVepHandler::class);
  126.             $vep $handler->getById($id);
  127.             $this->response->setData($vep);
  128.             $this->response->setCode(Codes::OK);
  129.         } catch (Exception $e) {
  130.             $this->response->setCode(Codes::ERROR);
  131.             $this->response->setMessage($e->getMessage());
  132.         }
  133.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  134.         return new Response($serializedEntity);
  135.     }
  136.     /**
  137.      * Modifica un VEP
  138.      *
  139.      * @Route("/admin/ajax/vep/{id}", name="admin_ajax_vep_update", methods={"POST"}, condition="request.isXmlHttpRequest()")
  140.      */
  141.     public function putUpdateAction(Request $request$id) {
  142.         $this->validarAdmin();
  143.         $data $request->request->all();
  144.         $comprobante $request->files->get('comprobante');
  145.         try {
  146.             $handler $this->get(McVepHandler::class);
  147.             $vep $handler->getVepFromRequest($request$comprobante$id);        
  148.             $result $handler->update($vep$id);
  149.             $this->response->setData($result);
  150.             $this->response->setCode(Codes::OK);
  151.         } catch (Exception $e) {
  152.             $this->response->setCode(Codes::ERROR);
  153.             $this->response->setMessage($e->getMessage());
  154.         }
  155.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  156.         return new Response($serializedEntity);
  157.     }
  158. }