<?php
namespace App\Controller;
use App\Repository\AlbumRepository;
use App\Repository\PicturesRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class PicturesViewController extends AbstractController
{
private $entitymanager;
public function __construct(EntityManagerInterface $entityManagerInterface)
{
return $this->entitymanager = $entityManagerInterface;
}
// VOIR LES PHOTOS
#[Route('/album/{id}', name: 'pictures_album')]
public function index(PicturesRepository $picturesRepository, $id, AlbumRepository $albumRepository): Response
{
$album = $albumRepository->findOneById($id);
$pictures = $picturesRepository->findPictures($id);
return $this->render('pictures_view/index.html.twig', [
'pictures' => $pictures,
'album' => $album
]);
}
// SUPPRIMER UNE PHOTO
#[Route('/album/delete/{id}', name: 'pictures_delete')]
public function delete(PicturesRepository $picturesRepository, $id): Response
{
$photo = $picturesRepository->findOneById($id);
$album = $photo->getAlbum();
$this->entitymanager->remove($photo);
$this->entitymanager->flush();
$this->addFlash('success', 'Photo supprimée avec succès');
return $this->redirectToRoute('picture_dashboard', ['id' => $album->getId()]);
}
}