<?php
namespace App\Controller;
use App\Entity\Gallery;
use App\Repository\GalleryRepository;
use App\Repository\SectionTitleRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class GalleryController extends AbstractController
{
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* @Route("/mediatheque-bilimon-academie", name="app_gallery")
*/
public function index(SectionTitleRepository $sectionTitleRepository, GalleryRepository $repository): Response
{
$galleryTitle = $sectionTitleRepository->findTitleByTag('gallery_index');
$gallery = $repository->findByIsActive(1);
return $this->render('gallery/index.html.twig', [
'galleryTitle' => $galleryTitle,
'galeries' => $gallery
]);
}
/**
* @Route("/mediatheque/{slug}", name="app_gallery_show")
*/
public function show($slug)
{
$gallery = $this->entityManager->getRepository(Gallery::class)->findOneBySlug($slug);
// $products = $this->entityManager->getRepository(Product::class)->findByIsBest(1);
if (!$gallery) {
return $this->redirectToRoute('app_gallery');
}
return $this->render('gallery/show.html.twig', [
'galeries' => $gallery,
// 'products' => $products
]);
}
}