<?php
namespace App\Controller;
use App\Entity\Coordonnee;
use App\service\SendMailService;
use App\Repository\MenuRepository;
use App\Repository\CoordonneeRepository;
use App\Repository\PublicationRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class DefaultController extends AbstractController
{
#[Route('/', name: 'app_homepage')]
public function index(): Response
{
$menu = null;
return $this->render('frontend.html.twig', compact('menu'));
}
#[Route('/m/{slug}', name: 'app_detail_menu')]
public function detailMenu(MenuRepository $MenuRepo,PublicationRepository $PubRepo,CoordonneeRepository $coordonneeRepository,$slug = null): Response
{
$menu = $MenuRepo->findBy(["slug" => $slug])[0];
$publications = $PubRepo->findBy(['menu' => $menu->getId()]);
$coordonnees = $coordonneeRepository->findOneBy([],['id' => 'DESC'],1);
switch ($menu->getId()) {
case '2':
return $this->render('pages/apropos.html.twig', compact('publications','menu'));
break;
case '3':
return $this->render('pages/services.html.twig', compact('publications','menu'));
break;
case '4':
return $this->render('pages/realisations.html.twig', compact('publications','menu'));
break;
case '5':
return $this->render('pages/contact.html.twig', compact('publications','menu','coordonnees'));
break;
default:
return $this->render('frontend.html.twig', compact('menu'));
break;
}
}
#[Route('/contact/traitement', name: 'app_contact')]
public function contact(Request $request, SendMailService $mail, $menu = null)
{
if($request->isMethod('POST')){
$form = $request->request->all();
//envoie de mail
$mail->mailContact($form);
}
return $this->render('frontend.html.twig', compact('menu'));
}
#[Route('/realisation/{slug}', name: 'app_detail_realisation')]
public function detailRealisation(Request $request, PublicationRepository $pr, $slug = null)
{
$p = $pr->findBy(["slug" => $slug])[0];
$aps = $pr->findBy([],['id' => 'DESC'],6);
$menu = $p->getMenu();
return $this->render('pages/detail.realisation.html.twig', compact('p','menu','aps'));
}
#[Route('/Admin2ei', name: 'app_administration')]
public function dashboard(): Response
{
return $this->render('backend.html.twig');
}
}