<?php
namespace App\Controller;
use App\Entity\Realisation;
use App\Repository\CategorieRepository;
use App\Repository\RealisationRepository;
use Doctrine\ORM\NonUniqueResultException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class AchievementController extends AbstractController
{
private $repository;
private $categorieRepository;
public function __construct(RealisationRepository $repository, CategorieRepository $categorieRepository)
{
$this->repository = $repository;
$this->categorieRepository = $categorieRepository;
}
/**
* @Route("/realisations", name="achievements")
*/
public function index(): Response
{
$realisations = $this->repository->findAll();
$categories = $this->categorieRepository->findAll();
$lasts = $this->repository->findLastOfCategory();
return $this->render('achievement/index.html.twig', [
'realisations' => $realisations,
'categories' => $categories,
'lasts' => $lasts,
'titre' => 'Nos réalisations',
'sousTitre' => 'découvrez',
'banner' => 'facade-maison.jpg',
]);
}
/**
* @Route("/realisation/{slug}", name="realisation")
* @throws NonUniqueResultException
*/
public function show($slug)
{
$realisation = $this->repository->findOneBySlug($slug);
if (!$realisation){
return $this->redirectToRoute('realisations');
}
$realByCat = $this->repository->findByCategory($realisation->getCategorie()->getId(), $realisation->getId());
// dd($realByCat);
return $this->render('achievement/show.html.twig', [
'realisation' => $realisation,
'others' => $realByCat,
'titre' => $realisation->getNom(),
'sousTitre' => 'nos réalisations',
'banner' => 'facade-maison.jpg',
]);
}
}