|
@@ -4,8 +4,8 @@ namespace App\Controller;
|
|
|
|
|
|
use App\Entity\Genre;
|
|
|
use App\Form\GenreType;
|
|
|
+use App\Service\GenreManager;
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
@@ -28,7 +28,7 @@ class GenreController extends AbstractController
|
|
|
/**
|
|
|
* @Route("/genre/ajouter", name="genre_ajouter")
|
|
|
*/
|
|
|
- public function ajouterAction(Request $request, EntityManagerInterface $em)
|
|
|
+ public function ajouterAction(Request $request, GenreManager $genreManager)
|
|
|
{
|
|
|
$genre = new Genre();
|
|
|
$form = $this->createForm(GenreType::class, $genre);
|
|
@@ -36,8 +36,7 @@ class GenreController extends AbstractController
|
|
|
$form->handleRequest($request);
|
|
|
if ($form->isSubmitted() && $form->isValid())
|
|
|
{
|
|
|
- $em->persist($genre);
|
|
|
- $em->flush();
|
|
|
+ $genreManager->add($genre);
|
|
|
$this->addFlash('success', 'Le genre a été ajouté');
|
|
|
return $this->redirectToRoute('genre_liste');
|
|
|
}
|
|
@@ -50,7 +49,7 @@ class GenreController extends AbstractController
|
|
|
/**
|
|
|
* @Route("/genre/modifier/{id}", name="genre_modifier")
|
|
|
*/
|
|
|
- public function modifierAction(Request $request, Genre $genre, EntityManagerInterface $em)
|
|
|
+ public function modifierAction(Request $request, Genre $genre, EntityManagerInterface $em, GenreManager $genreManager)
|
|
|
{
|
|
|
$form = $this->createForm(GenreType::class, $genre);
|
|
|
$form->handleRequest($request);
|
|
@@ -58,7 +57,7 @@ class GenreController extends AbstractController
|
|
|
|
|
|
if ($form->isSubmitted() && $form->isValid())
|
|
|
{
|
|
|
- $em->flush();
|
|
|
+ $genreManager->edit($genre);
|
|
|
$this->addFlash('success', 'Le genre a été modifié');
|
|
|
return $this->redirectToRoute('genre_liste');
|
|
|
}
|
|
@@ -73,19 +72,13 @@ class GenreController extends AbstractController
|
|
|
/**
|
|
|
* @Route("/genre/supprimer/{id}", name="genre_supprimer")
|
|
|
*/
|
|
|
- public function supprimerAction(Request $request, Genre $genre, EntityManagerInterface $em)
|
|
|
+ public function supprimerAction(Request $request, Genre $genre, GenreManager $genreManager)
|
|
|
{
|
|
|
$form = $this->get('form.factory')->create();
|
|
|
$form->handleRequest($request);
|
|
|
if ($form->isSubmitted() && $form->isValid())
|
|
|
{
|
|
|
- $films = $em->getRepository('App:Film')->findFilmWithGenre(array($genre->getName()));
|
|
|
- foreach ($films as $film)
|
|
|
- {
|
|
|
- $film->removeGenre($genre);
|
|
|
- }
|
|
|
- $em->remove($genre);
|
|
|
- $em->flush();
|
|
|
+ $genreManager->del($genre);
|
|
|
$this->addFlash('success', 'Le genre '.$genre->getName().' a bien été supprimé.');
|
|
|
return $this->redirectToRoute('genre_liste');
|
|
|
}
|