src/Controller/HomeController.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Contact;
  4. use App\Form\ContactType;
  5. use App\Repository\MealRepository;
  6. use App\Repository\TagsRepository;
  7. use App\Repository\AllergenRepository;
  8. use App\Repository\IngredientRepository;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. class HomeController extends AbstractController
  16. {
  17.     #[Route('/'name'home.index'methods:['GET'])]
  18.     public function index(MealRepository $mRepositoryAllergenRepository $aRepositoryTagsRepository $tRepositoryIngredientRepository $iRepository): Response
  19.     {
  20.         $types $mRepository->getAllMealTypes();
  21.         $meals $mRepository->findAll();
  22.         $displayedMeals $mRepository->getDisplayedMeal();
  23.         $allergens $aRepository->findAll();
  24.         $tags $tRepository->findAll();
  25.         $ingredients $iRepository->findAll();
  26.         return $this
  27.         ->render('pages/home.html.twig', [
  28.             'controller_name' => 'HomeController',
  29.             'meals' => $meals,
  30.             'nmbr_DisplayedMeals' => $displayedMeals->count(),
  31.             'nmbr_type' => $types->count(),
  32.             'allergens' => $allergens,
  33.             'tags' => $tags,
  34.             'ingredients' => $ingredients,
  35.         ]);
  36.     }
  37.     #[Route('/accueil'name'public.index'methods:['GET'])]
  38.     public function publicIndex(MealRepository $repositoryEntityManagerInterface $managerRequest $request): Response
  39.     {
  40.         $contact = new Contact();
  41.         $form $this->createForm(ContactType::class, $contact);
  42.             
  43.         $form->handleRequest($request);
  44.         if($form->isSubmitted() && $form->isValid())
  45.         {
  46.             $contact $form->getData();
  47.     
  48.             $manager->persist($contact);
  49.             $manager->flush();
  50.     
  51.             $this->addFlash(
  52.                 'success',
  53.                 'Votre demande de contact a été envoyé'
  54.             );
  55.     
  56.             return $this->redirectToRoute('public.index');
  57.         }
  58.         $meals $repository->findAll();
  59.         $types $repository->getAllMealTypes();
  60.         return $this->render('pages/public/index.html.twig', [
  61.             'meals' => $meals,
  62.             'types' => $types,
  63.             'form' => $form->createView(),
  64.         ]);
  65.     }
  66. }