| 
					
				 | 
			
			
				@@ -3,12 +3,15 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 namespace AppBundle\Controller; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use AppBundle\Entity\Commentaire; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use AppBundle\Entity\Realisateur; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use Symfony\Component\HttpFoundation\JsonResponse; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use Symfony\Component\Routing\Annotation\Route; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use Symfony\Component\HttpFoundation\Request; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use AppBundle\Entity\Film; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use AppBundle\Form\FilmType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use Symfony\Component\Serializer\Tests\Fixtures\NullableConstructorArgumentDummy; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 class VideothequeController extends Controller 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -42,12 +45,25 @@ class VideothequeController extends Controller 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		$film = new Film; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		$film->setAuthered($this->getUser()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		$form = $this->createForm(FilmType::class, $film); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $em = $this->getDoctrine()->getManager(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		$form->handleRequest($request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		if ($form->isSubmitted() && $form->isValid()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			$film = $form->getData(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			$em = $this->getDoctrine()->getManager(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $realisateurs = $film->getRealisateurs(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            foreach ($realisateurs as $realisateur) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if ($realisateur->getId() == null) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    $recherche = $em->getRepository('AppBundle:Realisateur')->findOneBy(array('nomComplet'=>$realisateur->getNomComplet())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if ($recherche != null) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        $film->removeRealisateur($realisateur); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        $film->addRealisateur($recherche); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			$em->persist($film); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			$em->flush(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			$this->addFlash('success', 'Le film a été ajouté'); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -56,7 +72,6 @@ class VideothequeController extends Controller 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return $this->render('@App/videotheque/ajouter.html.twig', array( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			'form'	=>	$form->createView(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			'film'	=>	$film 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -67,11 +82,23 @@ class VideothequeController extends Controller 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		$form = $this->createForm(FilmType::class, $film); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		$form->handleRequest($request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $em = $this->getDoctrine()->getManager(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		if ($form->isSubmitted() && $form->isValid()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $em = $this->getDoctrine()->getManager(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			$film = $form->getData(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $realisateurs = $film->getRealisateurs(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            foreach ($realisateurs as $realisateur) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if ($realisateur->getId() == null) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    $recherche = $em->getRepository('AppBundle:Realisateur')->findOneBy(array('nomComplet'=>$realisateur->getNomComplet())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if ($recherche != null) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        $film->removeRealisateur($realisateur); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        $film->addRealisateur($recherche); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			$em->flush(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			$this->addFlash('success', 'Le film a été modifié'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			return $this->redirectToRoute('videotheque_liste'); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -79,7 +106,7 @@ class VideothequeController extends Controller 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return $this->render('@App/videotheque/modifier.html.twig', array( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			'form'	=> $form->createView() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			'form'	=> $form->createView(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -139,4 +166,22 @@ class VideothequeController extends Controller 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         )); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @Route("/ajax_req_realisateurs", name="videotheque_ajax_realisateurs") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public function ajaxRealisateurs(Request $request) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $realisateurs = $this 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ->getDoctrine() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ->getManager() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ->getRepository('AppBundle:Realisateur') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ->findNomsComplets(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        foreach ($realisateurs as $key=>$nom) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $liste[$key] = $this->get('serializer')->serialize($nom, 'json'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return new JsonResponse($liste); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |