src/Controller/Notificacion/NotificacionUsuarioController.php line 130

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Notificacion;
  3. use App\Entity\Notificacion\AdjuntoNotificacion;
  4. use App\Entity\Notificacion\NotificacionUsuario;
  5. use App\Entity\Notificacion\Notificacion;
  6. use App\Repository\Notificacion\NotificacionUsuarioRepository;
  7. use App\Security\Voter\NotificacionUsuarioVoter;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Workflow\Registry;
  14. use App\Form\NotificacionUsuario\NotificacionUsuarioFiltroType;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  16. #[Route('/notificacion/notificacion/usuario')]
  17. class NotificacionUsuarioController extends AbstractController
  18. {
  19.     public const FORM_CONSULTA_NOTIFICACION_USUARIO 'consulta_notificacion_usuario_form';
  20.     public const FORM_CONSULTA_NOTIFICACION_USUARIO_STAR 'consulta_notificacion_usuario_form_start';
  21.     public const FORM_CONSULTA_PERSONA_NOTIFICADA 'consulta_persona_notificada_form';
  22.     #[Route('/'name'portal_aspirante_notificaciones'methods: ['GET'])]
  23.     public function index(NotificacionUsuarioRepository $notificacionUsuarioRepository): Response
  24.     {
  25.         $notificacionesUsuario $notificacionUsuarioRepository->findByUser(
  26.             $this->getUser()
  27.         );
  28.         return $this->render('portal_aspirante/notificacion/index.html.twig', [
  29.             'notificacion_usuarios' => $notificacionesUsuario,
  30.         ]);
  31.     }
  32.     #[Route('/{idView}/listado/{reset}'name'notificaciones_usuario_listado'methods: ['GET''POST'])]
  33.     public function listadoNotificacionesUsuario(
  34.         NotificacionUsuarioRepository $notificacionUsuarioRepository
  35.         Notificacion $notificacion,
  36.         Request $request
  37.         EntityManagerInterface $entityManager,
  38.         int $reset null
  39.     ): Response
  40.     {
  41.         // Reinicio el formulario si reset = 1
  42.         if ($reset == 1) {
  43.             $request->getSession()->remove(self::FORM_CONSULTA_NOTIFICACION_USUARIO);
  44.         }
  45.         // Inicializo el formulario con lo seteado previamente en la sesión
  46.         $data = ($request->getSession()->has(self::FORM_CONSULTA_NOTIFICACION_USUARIO)) 
  47.             ? $request->getSession()->get(self::FORM_CONSULTA_NOTIFICACION_USUARIO
  48.             : null;
  49.         $form $this->createForm(NotificacionUsuarioFiltroType::class, $data);
  50.         $form->handleRequest($request);
  51.         if ($form->isSubmitted() && $form->isValid()) {
  52.             $request->getSession()->set(self::FORM_CONSULTA_NOTIFICACION_USUARIO$form->getData());
  53.             $request->getSession()->remove(self::FORM_CONSULTA_NOTIFICACION_USUARIO_STAR);
  54.         }
  55.         $arrayMensaje explode("\n"
  56.             preg_replace("/[\r\n|\r]+/""\n"
  57.                 strip_tags(html_entity_decode($notificacion->getMensaje()))
  58.             )
  59.         );
  60.         
  61.         return $this->renderForm('notificacion_usuario/index.html.twig', [
  62.             'form' => $form,
  63.             'notificacionesUsuario' => $notificacionUsuarioRepository->findPorNotificacion($notificacion),
  64.             'notificacion' => $notificacion,
  65.             // 'sinHtml' => strip_tags(html_entity_decode($notificacion->getMensaje())),
  66.             'arrayMensaje' => $arrayMensaje
  67.         ]);
  68.     }
  69.     #[Route('/notificacion_usuario_datos/{notificacion}'name'notificaciones_usuarios_datos'methods: ['GET''POST'])]
  70.     public function notificacionesUsuarioDatos(
  71.         Request $request
  72.         Notificacion $notificacion,
  73.         NotificacionUsuarioRepository $notificacionUsuarioRepository
  74.     ): Response
  75.     {
  76.         $idNotificacion $notificacion->getId(); 
  77.         // Proceso si hay filtro de datos
  78.         if ($request->getSession()->has(self::FORM_CONSULTA_NOTIFICACION_USUARIO)) {
  79.             $params['formulario'] = array_filter($request->getSession()->get(self::FORM_CONSULTA_NOTIFICACION_USUARIO));
  80.         }
  81.         $start $request->request->get('start');
  82.         $request->getSession()->set(self::FORM_CONSULTA_NOTIFICACION_USUARIO_STAR$start);
  83. /*        $params['user'] = $this->getUser()->getUserIdentifier();*/
  84.         $params['draw'] = intval($request->request->get('draw'));
  85.         $params['start'] = $start;
  86.         $params['length'] = $request->request->get('length');
  87.         $params['search'] = $request->request->get('search');
  88.         $params['orders'] = $request->request->get('order');
  89.         $params['columns'] = $request->request->get('columns');
  90.         $params['idNotificacion'] = $idNotificacion;
  91.         $notificacionesUsuario $notificacionUsuarioRepository->loadNotificacionesUsuarioData($params);
  92.         $params['start'] = 0;
  93.         $params['length'] = count($notificacionUsuarioRepository->findPorNotificacion($notificacion));
  94.         $notificacionesUsuarioSinPaginar $notificacionUsuarioRepository->loadNotificacionesUsuarioData($params);
  95.         $respuesta['draw'] = $params['draw'];
  96.         $respuesta['recordsTotal'] = $params['length'];
  97.         $respuesta['recordsFiltered'] = count($notificacionesUsuarioSinPaginar);
  98.         $respuesta['data'] = $notificacionesUsuario;
  99.         return $this->json($respuesta);
  100.     }
  101.     #[Route('/{idView}'name'portal_aspirante_notificaciones_show'methods: ['GET'])]
  102.     public function show(
  103.         Request $request,
  104.         NotificacionUsuario $notificacionUsuario,
  105.         Registry $workflows,
  106.         EntityManagerInterface $entityManager
  107.     ): Response
  108.     {
  109.         do {
  110.             $this->denyAccessUnlessGranted(NotificacionUsuarioVoter::ACCESS$notificacionUsuario);
  111.             $workflow $workflows->get($notificacionUsuario'notificacion_usuario');
  112.             if ($workflow->can($notificacionUsuario'leido'))
  113.             {
  114.                 $workflow->apply($notificacionUsuario'leido',[
  115.                     'sso_user' => $this->getUser(),
  116.                 ]);
  117.                 $entityManager->flush();
  118.             } 
  119.         } while (false);
  120.         return $this->render('portal_aspirante/notificacion/show.html.twig', [
  121.             'notificacion_usuario' => $notificacionUsuario,
  122.         ]);
  123.     }
  124.     #[Route('/{idView}/descargar'name'portal_aspirante_notificacion_adjunto_notificacion_descargar')]
  125.     public function descargar(Request $requestAdjuntoNotificacion $adjuntoNotificacion): Response
  126.     {
  127.         $extensionArray explode('.',$adjuntoNotificacion->getUrlAdjunto());
  128.         $extensionArray array_splice($extensionArray1count($extensionArray));
  129.         $extensionFinal "";
  130.         foreach($extensionArray as $extension)
  131.         {
  132.             $extensionFinal $extensionFinal.'.'.$extension;
  133.         }
  134.         $rutaCarpeta =  $_ENV["APP_FILES_NOTIFICACIONES"];
  135.         $fecha $adjuntoNotificacion->getNotificacion()->getFechaHoraAlta()->format('Y-m-d');
  136.         $rutaArchivo $rutaCarpeta.'/'.$fecha.'/'.$adjuntoNotificacion->getNotificacion()->getId().'/';
  137.         return $this->file(
  138.             $rutaArchivo.$adjuntoNotificacion->getUrlAdjunto(),
  139.             $adjuntoNotificacion->getDescripcion().$extensionFinal);
  140.     }
  141. }