<?php
namespace App\Controller;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Entity\SettingsRol;
use App\Entity\MobileAppControlEvent;
use App\Entity\SettingsGeneral;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends AbstractController
{
private $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
/**
* @Route("/", name="homepage")
*/
public function index(Request $request)
{
$entityManager = $this->getDoctrine()->getManager();
$user = $this->getUser();
if ($user) {
$userId = $user->getId();
$userRole = $user->getUserrol();
$modules = $entityManager->getRepository(SettingsRol::class)->find($userRole);
$request->getSession()->set('_modules', $modules);
if ($userRole !== 'ROLE_ADMIN' && !$request->getSession()->get('_modules')->getMadmin()) {
$events = $entityManager->getRepository(MobileAppControlEvent::class)->findByUserId($userId);
$assignedEvents = [];
foreach ($events as $event) {
$assignedEvents[] = $event->getEventId();
}
$request->getSession()->set('_assignedEvent', $assignedEvents);
}
}
$settingsGeneral = $entityManager->getRepository(SettingsGeneral::class)->find(1);
// Redireccionar a los eventos directamente si el usuario ya está logueado
return $this->redirectToRoute('get_events_select');
// if ($settingsGeneral && $settingsGeneral->getSeeHome()) {
// return $this->render('home/index.html.twig');
// } else {
// return $this->redirectToRoute('events');
// }
}
/**
* @Route("/ChangeLanguage/{idioma}", name="change_language")
*/
public function changeLanguage(Request $request, $idioma)
{
$request->getSession()->set('_locale', $idioma);
return $this->redirect($request->headers->get('referer'));
}
}