<?php
// src/Controller/IndexController.php
namespace App\Controller;
use App\Entity\Notification;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Doctrine\ORM\EntityManagerInterface;
class IndexController extends AbstractController
{
private $session;
public function __construct(SessionInterface $session)
{
$this->session = $session;
}
/**
* @Route("/", name="homepage", methods={"GET", "POST"})
*/
public function homepage(Request $request): Response
{
return $this->redirectToRoute('app_login', [], Response::HTTP_SEE_OTHER);
}
public function mainNav(): Response
{
$lastUsername = $this->session->get(Security::LAST_USERNAME);
$menu = $this->session->get($lastUsername."_menu");
return $this->render('nav.html.twig', [
'menu' => $menu
]);
}
public function notifications(Request $request, EntityManagerInterface $entityManager): Response
{
$lastUsername = $this->session->get(Security::LAST_USERNAME);
$userData = $request->getSession()->get($lastUsername);
$organizationId = 0;
$organizationSession = $request->getSession()->get('organization_session');
if($organizationSession)
{
$organizationId = $organizationSession['organization_id'];
}
// -----------------------------------------------------------
$notifications = $entityManager->getRepository(Notification::class)->getNotifications($organizationId, $userData);
return $this->render('notifications.html.twig', [
'notifications' => $notifications
]);
}
/**
* @Route("/filter", name="filter_index", methods={"GET", "POST"})
*/
public function filtro(Request $request): Response {
$lastUsername = $this->session->get(Security::LAST_USERNAME);
$filter = $request->get('filter');
if($filter)
{
$month = $this->session->set("month", $filter['month']);
$year = $this->session->set("year", $filter['year']);
}
if($request->get('clear'))
{
$this->session->remove("month");
$this->session->remove("year");
}
$referer = $request->headers->get('referer');
return new RedirectResponse($referer);
}
}