src/Controller/IndexController.php line 30

Open in your IDE?
  1. <?php
  2. // src/Controller/IndexController.php
  3. namespace App\Controller;
  4. use App\Entity\Notification;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  9. use Symfony\Component\Security\Core\Security;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. class IndexController extends AbstractController
  14. {
  15.     
  16.    private $session;
  17.     
  18.    public function __construct(SessionInterface $session)
  19.    {
  20.       $this->session $session;
  21.    }
  22.     /**
  23.      * @Route("/", name="homepage", methods={"GET", "POST"})
  24.      */
  25.     public function homepage(Request $request): Response
  26.     {
  27.               
  28.         return $this->redirectToRoute('app_login', [], Response::HTTP_SEE_OTHER);
  29.         
  30.     }
  31.     public function mainNav(): Response
  32.     {
  33.         
  34.         $lastUsername $this->session->get(Security::LAST_USERNAME);        
  35.         $menu         $this->session->get($lastUsername."_menu");    
  36.         return $this->render('nav.html.twig', [
  37.             'menu' => $menu
  38.         ]);
  39.     }
  40.     public function notifications(Request $requestEntityManagerInterface $entityManager): Response
  41.     {
  42.         
  43.         $lastUsername $this->session->get(Security::LAST_USERNAME);        
  44.         $userData $request->getSession()->get($lastUsername);
  45.         
  46.         $organizationId 0;
  47.         $organizationSession $request->getSession()->get('organization_session');
  48.         if($organizationSession)
  49.         {
  50.             $organizationId  $organizationSession['organization_id'];             
  51.         }
  52.         // -----------------------------------------------------------
  53.         
  54.         $notifications $entityManager->getRepository(Notification::class)->getNotifications($organizationId$userData);        
  55.         return $this->render('notifications.html.twig', [
  56.             'notifications' => $notifications
  57.         ]);
  58.     }
  59.     /**
  60.      * @Route("/filter", name="filter_index", methods={"GET", "POST"})
  61.      */
  62.     public function filtro(Request $request): Response {
  63.         
  64.         $lastUsername $this->session->get(Security::LAST_USERNAME);
  65.         $filter $request->get('filter');
  66.         
  67.         if($filter)
  68.         {
  69.             $month $this->session->set("month"$filter['month']);
  70.             $year $this->session->set("year"$filter['year']);
  71.         }
  72.         if($request->get('clear'))
  73.         {
  74.             $this->session->remove("month");
  75.             $this->session->remove("year");
  76.         }
  77.         
  78.         $referer $request->headers->get('referer');       
  79.         
  80.         return new RedirectResponse($referer);
  81.     }
  82. }