<?php
namespace App\Controller;
use App\Entity\Contact;
use App\Form\ContactType;
use App\Repository\MealRepository;
use App\Repository\TagsRepository;
use App\Repository\AllergenRepository;
use App\Repository\IngredientRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class HomeController extends AbstractController
{
#[Route('/', name: 'home.index', methods:['GET'])]
public function index(MealRepository $mRepository, AllergenRepository $aRepository, TagsRepository $tRepository, IngredientRepository $iRepository): Response
{
$types = $mRepository->getAllMealTypes();
$meals = $mRepository->findAll();
$displayedMeals = $mRepository->getDisplayedMeal();
$allergens = $aRepository->findAll();
$tags = $tRepository->findAll();
$ingredients = $iRepository->findAll();
return $this
->render('pages/home.html.twig', [
'controller_name' => 'HomeController',
'meals' => $meals,
'nmbr_DisplayedMeals' => $displayedMeals->count(),
'nmbr_type' => $types->count(),
'allergens' => $allergens,
'tags' => $tags,
'ingredients' => $ingredients,
]);
}
#[Route('/accueil', name: 'public.index', methods:['GET'])]
public function publicIndex(MealRepository $repository, EntityManagerInterface $manager, Request $request): Response
{
$contact = new Contact();
$form = $this->createForm(ContactType::class, $contact);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid())
{
$contact = $form->getData();
$manager->persist($contact);
$manager->flush();
$this->addFlash(
'success',
'Votre demande de contact a été envoyé'
);
return $this->redirectToRoute('public.index');
}
$meals = $repository->findAll();
$types = $repository->getAllMealTypes();
return $this->render('pages/public/index.html.twig', [
'meals' => $meals,
'types' => $types,
'form' => $form->createView(),
]);
}
}