src/Controller/HomeController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Contracts\Translation\TranslatorInterface;
  4. use App\Entity\SettingsRol;
  5. use App\Entity\MobileAppControlEvent;
  6. use App\Entity\SettingsGeneral;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. class HomeController extends AbstractController
  11. {
  12.     private $translator;
  13.     public function __construct(TranslatorInterface $translator)
  14.     {
  15.         $this->translator $translator;
  16.     }
  17.     /**
  18.      * @Route("/", name="homepage")
  19.      */
  20.     public function index(Request $request)
  21.     {
  22.         $entityManager $this->getDoctrine()->getManager();
  23.         $user $this->getUser();
  24.         if ($user) {
  25.             $userId $user->getId();
  26.             $userRole $user->getUserrol();
  27.             $modules $entityManager->getRepository(SettingsRol::class)->find($userRole);
  28.             $request->getSession()->set('_modules'$modules);
  29.             if ($userRole !== 'ROLE_ADMIN' && !$request->getSession()->get('_modules')->getMadmin()) {
  30.                 $events $entityManager->getRepository(MobileAppControlEvent::class)->findByUserId($userId);
  31.                 $assignedEvents = [];
  32.                 foreach ($events as $event) {
  33.                     $assignedEvents[] = $event->getEventId();
  34.                 }
  35.                 $request->getSession()->set('_assignedEvent'$assignedEvents);
  36.             }
  37.         }
  38.         $settingsGeneral $entityManager->getRepository(SettingsGeneral::class)->find(1);
  39.         // Redireccionar a los eventos directamente si el usuario ya está logueado
  40.         return $this->redirectToRoute('get_events_select');
  41.         // if ($settingsGeneral && $settingsGeneral->getSeeHome()) {
  42.         //     return $this->render('home/index.html.twig');
  43.         // } else {
  44.         //     return $this->redirectToRoute('events');
  45.         // }
  46.     }
  47.     /**
  48.      * @Route("/ChangeLanguage/{idioma}", name="change_language")
  49.      */
  50.     public function changeLanguage(Request $request$idioma)
  51.     {
  52.         $request->getSession()->set('_locale'$idioma);
  53.         return $this->redirect($request->headers->get('referer'));
  54.     }
  55. }