Esempio n. 1
0
 public function indexAction()
 {
     $security = $this->container->get('security.context');
     if (!$security->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         return $this->redirect($this->generateUrl('fos_user_security_login'));
     }
     $token = $security->getToken();
     // Si la requête courante n'est pas derrière un pare-feu, $token est null
     $userAccount = $token->getUser();
     // Sinon , on récupère l'utilisateur
     $em = $this->getDoctrine()->getManager();
     $request = $this->get('request');
     if ($request->query->get('id') != null) {
         $id = $request->query->get('id');
         $album = $em->getRepository('DBdbBundle:Album')->findById($id);
         $Image = new Multimedia();
         $Image->setUser($userAccount);
         $Image->setAlbum($album[0]);
         $formImg = $this->CreateForm(new MultimediaType(), $Image);
         if ($request->getMethod() == 'POST') {
             $formImg->bind($request);
             if ($formImg->IsValid()) {
                 $em->persist($Image);
                 $em->flush();
             }
         }
         $list_img = $em->getRepository('DBdbBundle:Multimedia')->findByAlbums($userAccount, $album);
         $list_album = $em->getRepository('DBdbBundle:Album')->findByUser($userAccount);
         $album = $em->getRepository('DBdbBundle:Album')->findById($id);
         if (count($list_img) == 0) {
             $listmult = $list_img;
         }
         for ($i = 0; $i < count($list_img); $i++) {
             $list_comment = $em->getRepository('DBdbBundle:MultimediaComment')->findByMultimedia($list_img[$i]);
             $listmult[$i]['comment'] = $list_comment;
             $listmult[$i]['image'] = $list_img[$i];
         }
         return $this->render('QuelpImageBundle:Gallerie:image.html.twig', array('img_form' => $formImg->createView(), 'list_img' => $listmult, 'list_album' => $list_album, 'def_albumId' => $album[0]));
     }
     return $this->forward('QuelpImageBundle:Albums:index');
 }
Esempio n. 2
0
 public function indexAction()
 {
     $security = $this->container->get('security.context');
     if (!$security->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         return $this->redirect($this->generateUrl('fos_user_security_login'));
     }
     $token = $security->getToken();
     // Si la requête courante n'est pas derrière un pare-feu, $token est null
     $userAccount = $token->getUser();
     // Sinon , on récupère l'utilisateur
     $em = $this->getDoctrine()->getManager();
     $albums = new Album();
     $Image = new Multimedia();
     $albums->setUser($userAccount);
     $Image->setUser($userAccount);
     $formImg = $this->CreateForm(new MultimediaType(), $Image);
     $formAlb = $this->CreateForm(new AlbumType(), $albums);
     $request = $this->get('request');
     if ($request->getMethod() == 'POST') {
         $formImg->bind($request);
         $formAlb->bind($request);
         if ($formImg->IsValid()) {
             if ($formAlb->IsValid()) {
                 $em->persist($albums);
                 $em->flush();
                 $Image->setAlbum($albums);
             }
             if ($Image->getEditDate() != null) {
                 $em->persist($Image);
                 $em->flush();
             }
         }
     }
     $list_albums = $em->getRepository('DBdbBundle:Album')->findUser($userAccount);
     return $this->render('QuelpImageBundle:Gallerie:albums.html.twig', array('img_form' => $formImg->createView(), 'alb_form' => $formAlb->createView(), 'list_albums' => $list_albums));
 }