src/Controller/HomeController.php line 28

  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use App\Entity\MessageEntity;
  8. use App\Services\FlagsService;
  9. use Symfony\Contracts\Translation\TranslatorInterface;
  10. class HomeController extends AbstractController
  11. {   
  12.     private $flagsService;
  13.     private $flags;
  14.     private $translator;
  15.     public function __construct(FlagsService $flagsServiceTranslatorInterface $translator)
  16.     {
  17.         $this->flagsService $flagsService;
  18.         $this->translator $translator;
  19.     }
  20.     /**
  21.      * @Route("/{_locale}/messages", name="home")
  22.      */
  23.     public function home(EntityManagerInterface $entityManager): Response
  24.     {                   
  25.         $messages $entityManager->getRepository(MessageEntity::class)->findBy(['user' => $this->getUser()], ['status' => 'ASC''id' => 'DESC']);
  26.         
  27.         if ($messages == null) {
  28.             $this->addFlash('message'$this->translator->trans('no_messages_found'));
  29.             $this->addFlash('color''secondary');
  30.         }
  31.         $this->flags $this->flagsService->getflags();
  32.         return $this->render('index.html.twig', [
  33.             'messages' => $messages,
  34.             'flags' => $this->flags,
  35.         ]);
  36.     }
  37.     /**
  38.      * @Route("/{_locale}", name="index")
  39.      */
  40.     public function index(EntityManagerInterface $entityManager): Response
  41.     {   
  42.                 
  43.         $this->flags $this->flagsService->getflags();
  44.         return $this->render('home.html.twig', [
  45.             'flags' => $this->flags,
  46.             
  47.         ]);
  48.     }
  49.     
  50.     /**
  51.      * @Route("/", name="redirect_home")
  52.      */
  53.     public function tohome(): Response
  54.     {   
  55.         return $this->redirectToRoute('home', ['_locale' => 'en']);
  56.     }
  57. }