src/Noahtech/Sistemas/InterjamaBundle/Controller/PublicUserController.php line 137

Open in your IDE?
  1. <?php
  2. namespace Noahtech\Sistemas\InterjamaBundle\Controller;
  3. use Noahtech\Sistemas\InterjamaBundle\Handler\McUsuarioHandler;
  4. use Noahtech\Sistemas\InterjamaBundle\Handler\McClienteHandler;
  5. use Noahtech\Sistemas\InterjamaBundle\Handler\McChoferHandler;
  6. use Noahtech\Sistemas\InterjamaBundle\Handler\McPrecargaHandler;
  7. use Noahtech\Sistemas\InterjamaBundle\Handler\McVehiculoHandler;
  8. use Noahtech\Sistemas\InterjamaBundle\Handler\McCategoriaHandler;
  9. use Noahtech\Sistemas\InterjamaBundle\Handler\McContactoHandler;
  10. use Noahtech\Sistemas\InterjamaBundle\Utils\Codes;
  11. use Exception;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Symfony\Component\HttpKernel\Exception\HttpException;
  16. class PublicUserController extends BaseController {
  17.     private function validarChofer ($tipo$numero$id=null) {
  18.         $chofer $this->get(McChoferHandler::class)->getChoferDuplicate($tipo$numero$id);
  19.         if (!is_null($chofer)) {
  20.             throw new HttpException(409"Ya existe un chofer con el tipo y número de documento ingresados.");
  21.         }
  22.     }
  23.     private function validarSiEsChofer($choferId) {
  24.         $chofer $this->get(McChoferHandler::class)->getChoferById($choferId);
  25.         if (is_null($chofer)) {
  26.             throw new HttpException(409"No tiene permisos suficientes para ingresar a esta pagina.");
  27.         }
  28.     }
  29.     private function validarPrecarga($id$choferId) {
  30.         $precarga $this->get(McPrecargaHandler::class)->getPrecargaByChofer($id$choferId);
  31.         if (count($precarga) == 0) {
  32.             throw new AccessDeniedException("No tiene permiso para acceder a esta pagina."); 
  33.         }
  34.     }
  35.     private function validarPrecargasSinFinalizar($choferId) {
  36.         $precarcasSinFinalizar $this->get(McprecargaHandler::class)->getPrecargasByChoferSinFinalizar($choferId);
  37.         if (count($precarcasSinFinalizar) !== 0) {
  38.             throw new AccessDeniedException("Tiene registrada una precarga sin finalizar."); 
  39.         }
  40.     }
  41.     /**
  42.      * @Route("user/public/generar_clave/{token}", name="public_nueva_clave")
  43.      * @return type
  44.      */
  45.     public function generarClaveAction($token) {
  46.         $this->setTitle("Generación de contraseña");
  47.         $band true;
  48.         $user $this->get(McUsuarioHandler::class)->getDataPublicUser($token$band);
  49.         $this->data["data"] = $user;
  50.         $this->response->setData($this->data);
  51.         return $this->render(
  52.                         '@NoahtechSistemasInterjama/public/usuarios/generar_clave.html.twig'$this->data
  53.         );
  54.     }
  55.     
  56.     /**
  57.      * @Route("user/public/recuperar_clave", name="public_recuperar_clave")
  58.      * @return type
  59.      */
  60.     public function recuperarClaveAction() {
  61.         $this->setTitle("Recuperar contraseña");
  62.         $this->data["data"] = null;
  63.         return $this->render(
  64.                         '@NoahtechSistemasInterjama/public/usuarios/recuperar_clave.html.twig'$this->data
  65.         );
  66.     }
  67.     
  68.      /**
  69.      * @Route("user/public/recuperar_clave_update/{token}", name="public_recuperar_clave_update")
  70.      * @return type
  71.      */
  72.     public function recuperarClaveUpdateAction($token) {
  73.         $this->setTitle("Recuperación de contraseña");
  74.         $band false;
  75.         $user $this->get(McUsuarioHandler::class)->getDataPublicUser($token$band);
  76.         $this->data["data"] = $user;
  77.         $this->response->setData($this->data);
  78.         return $this->render(
  79.                         '@NoahtechSistemasInterjama/public/usuarios/generar_clave.html.twig'$this->data
  80.         );
  81.     }
  82.     
  83.     /**
  84.      * Modifica el password de un usuario 
  85.      *
  86.      * @Route("user/public/ajax/usuarios/clave", name="public_ajax_usuario_clave_update", methods={"PUT"}, condition="request.isXmlHttpRequest()")
  87.      */
  88.     public function putClaveUpdateAction(Request $request) {
  89.         $data $request->request->all();
  90.         //En este caso no hay usuario logueado, porque esta acción se realiza sin ingreso al sistema.
  91.         try {
  92.             $currentPersona $this->get(McUsuarioHandler::class)->getById($data["id"]);            
  93.             $currentUser $this->get(McUsuarioHandler::class)->getUsuarioByPersona($currentPersona["persona"]["id"]);            
  94.             $result $this->container->get(McUsuarioHandler::class)->updateClave($data$currentUser);
  95.             $this->response->setData($result);
  96.             $this->response->setCode(Codes::OK);
  97.         } catch (Exception $e) {
  98.             $this->response->setCode($e->getCode());
  99.             $this->response->setMessage($e->getMessage());
  100.         }
  101.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  102.         return new Response($serializedEntity);
  103.     }    
  104.     /**
  105.      * @Route("user/public/ajax/usuario/recuperar_clave_email", name="public_ajax_usuario_recuperar_clave_email", methods={"POST"}, condition="request.isXmlHttpRequest()")     
  106.      */
  107.     public function recuperarClaveEmailAction(Request $request) {
  108.         $cuil $request->request->get('cuil');        
  109.         try {
  110.             $result $this->container->get(McUsuarioHandler::class)->recuperarClaveEmail($request$cuil);
  111.             $this->response->setData($result);
  112.             $this->response->setCode(Codes::OK);
  113.         } catch (Exception $e) {
  114.             $this->response->setCode($e->getStatusCode());
  115.             $this->response->setMessage($e->getMessage());
  116.         }
  117.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  118.         return new Response($serializedEntity);
  119.                
  120.     }
  121.     /**
  122.      * @Route("/", name="public_inicio")
  123.      * @return type
  124.      */
  125.     public function inicioAction() {
  126.         $this->setTitle("Interjama | Home");
  127.         $this->data['title'] = "Interjama | Home";
  128.         $this->data['data'] = null;
  129.        return $this->render('@NoahtechSistemasInterjama/public/home/inicio.html.twig'$this->data);
  130.     }
  131.     /**
  132.      * @Route("public/chofer", name="public_chofer_inicio")
  133.      * @return type
  134.      */
  135.     public function publicChoferAction() {
  136.         $this->setTitle("Interjama | Chofer");
  137.         $clientes $this->get(McClienteHandler::class)->getClientes();
  138.         $this->data["data"] = $clientes;
  139.         return $this->render(
  140.                         '@NoahtechSistemasInterjama/public/chofer/inicio.html.twig'$this->data
  141.         );
  142.     }
  143.     
  144.     /**
  145.      * @Route("public/ajax/chofer/search", name="public_ajax_chofer_search", methods={"POST"}, condition="request.isXmlHttpRequest()")     
  146.      */
  147.     public function searchChoferAction(Request $request) {
  148.         $data $request->request->all();    
  149.         try {
  150.             $result $this->container->get(McChoferHandler::class)->serachChofer($data);
  151.             $this->response->setData($result);
  152.             $this->response->setCode(Codes::OK);
  153.         } catch (Exception $e) {
  154.             $this->response->setCode(Codes::ERROR);
  155.             $this->response->setMessage($e->getMessage());
  156.         }
  157.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  158.         return new Response($serializedEntity);
  159.                
  160.     }
  161.     /**
  162.      * Guarda un chofer
  163.      *
  164.      * @Route("public/ajax/chofer", name="public_chofer_save", methods={"POST"}, condition="request.isXmlHttpRequest()")
  165.      */
  166.     public function postSaveAction(Request $request) {
  167.         $this->validarChofer($request->request->get('tipo'), $request->request->get('numero'));
  168.         try {
  169.             $handler $this->get(McChoferHandler::class);            
  170.             $chofer $handler->getChoferFromRequest($request);
  171.             $result $handler->save($chofer);
  172.             $this->response->setData($result);
  173.             $this->response->setCode(Codes::OK);            
  174.         } catch (Exception $e) {
  175.             $this->response->setCode(Codes::ERROR);
  176.             $this->response->setMessage($e->getMessage());
  177.         }
  178.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  179.         return new Response($serializedEntity);       
  180.     }
  181.     /**
  182.      * Modifica un chofer
  183.      *
  184.      * @Route("public/ajax/chofer/{id}", name="public_chofer_update", methods={"PUT"}, condition="request.isXmlHttpRequest()")
  185.      */
  186.     public function putSaveAction(Request $request$id) {
  187.         $this->validarChofer($request->request->get('tipo'), $request->request->get('numero'), (int)$id);
  188.         try {
  189.             $handler $this->get(McChoferHandler::class);            
  190.             $chofer $handler->getChoferFromRequest($request, (int)$id);
  191.             $result $handler->update($chofer);
  192.             $this->response->setData($result);
  193.             $this->response->setCode(Codes::OK);            
  194.         } catch (Exception $e) {
  195.             $this->response->setCode(Codes::ERROR);
  196.             $this->response->setMessage($e->getMessage());
  197.         }
  198.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  199.         return new Response($serializedEntity);       
  200.     }
  201.     /** SECCION PRECARGAS */
  202.     /**
  203.      * @Route("public/chofer/{choferId}/precargas", name="public_chofer_precargas_listado")
  204.      * @return type
  205.      */
  206.     public function precargaListadoAction($choferId) { 
  207.         $this->validarSiEsChofer((int)$choferId); 
  208.         $this->setTitle("Bandeja de entrada | InterJama");
  209.         $clientes $this->get(McClienteHandler::class)->getClientes();
  210.         $precarcasSinFinalizar $this->get(McprecargaHandler::class)->getPrecargasByChoferSinFinalizar($choferId);
  211.         $this->data['data'] = null;
  212.         $this->data['chofer'] = $choferId;
  213.         $this->data['precargasSinFinalizar'] = COUNT($precarcasSinFinalizar) == 0;
  214.         return $this->render'@NoahtechSistemasInterjama/public/chofer/precargas/listado.html.twig'$this->data );
  215.     }
  216.     /**
  217.      * consulta de precarga
  218.      *
  219.      * @Route("public/ajax/precargas/search", name="public_ajax_precargas_listado", methods={"POST"}, condition="request.isXmlHttpRequest()")
  220.      */
  221.     public function searchAction(Request $request) {
  222.         $searchParam $request->request->all();              
  223.         $currentPage $request->query->get('page');
  224.         $sortField $request->query->get('sort');
  225.         $sortDirection $request->query->get('direction');
  226.         $currentPage null == $currentPage $currentPage;
  227.         $offset = ($currentPage 1) * 100;
  228.         $limit 100;
  229.         try {
  230.             /** @var McPrecargaHandler $handler */
  231.             $handler $this->get(McPrecargaHandler::class);
  232.             $lp $handler->searchPrecargasByChofer($offset$limit$sortField$sortDirection$searchParam);
  233.             $lp->setCurrentPage($currentPage);
  234.             $lp->setPageSize(100);
  235.             $this->response->setData($lp);
  236.             $this->response->setCode(Codes::OK);
  237.         } catch (Exception $e) {
  238.             $this->response->setCode(Codes::ERROR);
  239.             $this->response->setMessage($e->getMessage());
  240.         }
  241.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  242.         return new Response($serializedEntity);
  243.     }
  244.     /**
  245.      * @Route("public/chofer/{choferId}/precarga/nueva", name="public_chofer_precarga_nueva")
  246.      * @return type
  247.      */
  248.     public function precargaNuevoAction($choferId) {
  249.         $this->validarSiEsChofer((int)$choferId);
  250.         $this->setTitle("Nueva Entrada");
  251.         $chofer $this->get(McChoferHandler::class)->getById((int)$choferId);    
  252.         $this->data['data'] = null;
  253.         $this->data['chofer'] = $chofer;
  254.         return $this->render(
  255.                         '@NoahtechSistemasInterjama/public/chofer/precargas/nueva.html.twig'$this->data
  256.         );
  257.     }
  258.     /**
  259.      * Guarda una precarga
  260.      *
  261.      * @Route("public/chofer/{choferId}/ajax/precargas", name="public_chofer_ajax_precargas_save", methods={"POST"}, condition="request.isXmlHttpRequest()")
  262.      */
  263.     public function postPrecargaSaveAction(Request $request$choferId) {        
  264.         $this->validarSiEsChofer((int)$choferId);
  265.         $this->validarPrecargasSinFinalizar((int)$choferId);
  266.         $archivos = (isset($_FILES)) ? $_FILES null;
  267.         try {
  268.             $handler $this->get(McPrecargaHandler::class);
  269.             $usuario null;
  270.             $precarga $handler->getPrecargaFromRequest($request$usuario);       
  271.             $result $handler->save($precarga$archivos$request);
  272.             $this->response->setData($result);
  273.             $this->response->setCode(Codes::OK);
  274.         } catch (Exception $e) {
  275.             $this->response->setCode(Codes::ERROR);
  276.             $this->response->setMessage($e->getMessage());
  277.         }
  278.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  279.         return new Response($serializedEntity);
  280.     }
  281.     /**
  282.      * @Route("public/chofer/{choferId}/precargas/{id}", name="public_chofer_precargas_modificacion")
  283.      * @return type
  284.      */
  285.     public function precargaModificacionAction($choferId$id) {
  286.         $this->validarSiEsChofer((int)$choferId);
  287.         $this->validarPrecarga($id, (int)$choferId);
  288.         $this->setTitle("Modificar Entrada");
  289.         $chofer $this->get(McChoferHandler::class)->getById((int)$choferId);
  290.         $this->data['data'] = $id;
  291.         $this->data['chofer'] = $chofer;
  292.         return $this->render(
  293.                         '@NoahtechSistemasInterjama/public/chofer/precargas/modificacion.html.twig'$this->data
  294.         );
  295.     }
  296.     /**
  297.      * Devuelve una precarga
  298.      *
  299.      * @Route("public/chofer/{choferId}/ajax/precargas/{id}", name="public_chofer_ajax_precarga_get_by_id", methods={"GET"}, condition="request.isXmlHttpRequest()")
  300.      */
  301.     public function getPrecargaByIdAction($choferId$id) {
  302.         $this->validarSiEsChofer((int)$choferId);
  303.         try {
  304.             $handler $this->get(McPrecargaHandler::class);
  305.             $precarga $handler->getById($id);
  306.             $this->response->setData($precarga);
  307.             $this->response->setCode(Codes::OK);
  308.         } catch (Exception $e) {
  309.             $this->response->setCode(Codes::ERROR);
  310.             $this->response->setMessage($e->getMessage());
  311.         }
  312.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  313.         return new Response($serializedEntity);
  314.     }
  315.     /**
  316.      * Modifica una precarga
  317.      *
  318.      * @Route("public/chofer/{choferId}/ajax/precargas/{id}", name="public_chofer_ajax_precarga_update", methods={"POST"}, condition="request.isXmlHttpRequest()")
  319.      */
  320.     public function putUpdateAction(Request $request$id$choferId) {
  321.         $this->validarSiEsChofer((int)$choferId);
  322.         $archivos = (isset($_FILES)) ? $_FILES null;
  323.         try {
  324.             $handler $this->get(McPrecargaHandler::class);
  325.             $usuario null;
  326.             $precarga $handler->getPrecargaFromRequest($request$usuario$id);        
  327.             $result $handler->update($precarga$archivos$request$id);        
  328.             $this->response->setData($result);
  329.             $this->response->setCode(Codes::OK);
  330.         } catch (Exception $e) {
  331.             $this->response->setCode(Codes::ERROR);
  332.             $this->response->setMessage($e->getMessage());
  333.         }
  334.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  335.         return new Response($serializedEntity);
  336.     }
  337.     /**
  338.      * Devuelve los vehiculos de un cliente
  339.      *
  340.      * @Route("public/ajax/cliente/{clienteId}/vehiculos/search/By/Termino", name="public_ajax_cliente_search_vehiculo_by_termino", methods={"GET"}, condition="request.isXmlHttpRequest()")
  341.      */
  342.     public function searchVehiculoByTerminoAction(Request $request$clienteId) {
  343.         $searchParam $request->query->get('q');
  344.         try {
  345.             $handler $this->get(McVehiculoHandler::class);
  346.             $vehiculos $handler->searchVehiculosByTermino($searchParam, (int)$clienteId);
  347.             $this->response->setData($vehiculos);
  348.             $this->response->setCode(Codes::OK);
  349.         } catch (Exception $e) {
  350.             $this->response->setCode(Codes::ERROR);
  351.             $this->response->setMessage($e->getMessage());
  352.         }
  353.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  354.         return new Response($serializedEntity);
  355.     }
  356.     /**
  357.      * Devuelve todas las categorias de vehiculos
  358.      *
  359.      * @Route("public/ajax/categorias/all", name="public_ajax_get_all_categorias", methods={"GET"}, condition="request.isXmlHttpRequest()")
  360.      */
  361.     public function getAllCategoriasAction(Request $request) {
  362.         try {
  363.             $handler $this->get(McCategoriaHandler::class);
  364.             $categorias $handler->getCategorias();
  365.             $this->response->setData($categorias);
  366.             $this->response->setCode(Codes::OK);
  367.         } catch (Exception $e) {
  368.             $this->response->setCode(Codes::ERROR);
  369.             $this->response->setMessage($e->getMessage());
  370.         }
  371.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  372.         return new Response($serializedEntity);
  373.     }
  374.     /**
  375.      * consulta de un vehículo por dominio principal
  376.      *
  377.      * @Route("public/ajax/vehiculo/dominio/{dominio}/exists", name="public_ajax_vehiculo_dominio_exists", methods={"GET"}, condition="request.isXmlHttpRequest()")
  378.      */
  379.     public function dominioExistsAction($dominio) {
  380.         try {
  381.             $handler $this->get(McVehiculoHandler::class);
  382.             $vehiculo $handler->getVehiculoByDominio($dominio);
  383.             $this->response->setData($vehiculo);
  384.             $this->response->setCode(Codes::OK);
  385.         } catch (Exception $e) {
  386.             $this->response->setCode(Codes::ERROR);
  387.             $this->response->setMessage($e->getMessage());
  388.         }
  389.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  390.         return new Response($serializedEntity);
  391.     }
  392.     /**
  393.      * Guarda un vehículo
  394.      *
  395.      * @Route("public/ajax/vehiculos", name="public_ajax_vehiculo_save", methods={"POST"}, condition="request.isXmlHttpRequest()")
  396.      */
  397.     public function vehiculoSaveAction(Request $request) {
  398.         try {
  399.             $handler $this->get(McVehiculoHandler::class);            
  400.             $vehiculo $handler->getVehiculoFromRequest($request);
  401.             $result $handler->save($vehiculo);
  402.             $this->response->setData($result);
  403.             $this->response->setCode(Codes::OK);            
  404.         } catch (Exception $e) {
  405.             $this->response->setCode(Codes::ERROR);
  406.             $this->response->setMessage($e->getMessage());
  407.         }
  408.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  409.         return new Response($serializedEntity);       
  410.     }
  411.     /**
  412.      * Guarda un contacto
  413.      *
  414.      * @Route("public/ajax/contacto", name="public_ajax_contacto_save", methods={"POST"}, condition="request.isXmlHttpRequest()")
  415.      */
  416.     public function contactoSaveAction(Request $request) {
  417.         try {
  418.             $handler $this->get(McContactoHandler::class);
  419.             $contacto $handler->getContactoFromRequest($request);
  420.             $result $handler->save($contacto);
  421.             $this->response->setData($result);
  422.             $this->response->setCode(Codes::OK); 
  423.         } catch (Exception $e) {
  424.             $this->response->setCode(Codes::ERROR);
  425.             $this->response->setMessage($e->getMessage());
  426.         }
  427.         $serializedEntity $this->container->get('serializer')->serialize($this->response'json');
  428.         return new Response($serializedEntity);       
  429.     }
  430. }