public function existVoteUser(Photo $photo, $user)
 {
     //todo : vérifier l'user
     $qb = $this->createQueryBuilder('v');
     $qb->where('v.photo = :photo')->setParameter('photo', $photo->getId())->andWhere('v.user = :user')->setParameter('user', $user);
     return $qb->getQuery()->getResult();
 }
Example #2
0
 public function testgetDescriptif()
 {
     $maPhoto = new Photo();
     $maPhoto->setDescriptif('ok good');
     $this->assertTrue($maPhoto->slugify());
     $this->assertEquals('ok good', $maPhoto->getDescriptif());
 }
 public function voirAction(Photo $photo)
 {
     $em = $this->getDoctrine()->getManager();
     //je crée mon évènement avec les bons paramètres
     /*
     $event = new AugmenteVuesEvent($photo, $this->getUser());
     $this->get('event_dispatcher')
         ->dispatch(AugmenteVuesEvents::onViewPhoto, $event);
     $photo->setNbVues($event.getPhoto());
     */
     //on est limité à 1 vue par user et par photo
     if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         if (!$photo->getUsersView()->contains($this->getUser())) {
             $photo->addUsersView($this->getUser());
             $photo->setNbVues($photo->getNbVues() + 1);
             $em->persist($photo);
             $em->flush();
         }
     }
     //on va récupérer tous les commentaires par ordre décroissant sur le champ createdAt
     $commentairesRecup = $em->getRepository('PersoGalerieBundle:Commentaire')->getCommentairesByPhotoDesc($photo);
     if (null != $this->getUser()) {
         $commentaire = new Commentaire();
         $commentaire->setUser($this->getUser());
         $form = $this->createForm(new CommentaireType(), $commentaire);
         $request = $this->get('request');
         if ($request->getMethod() == 'POST') {
             $form->submit($request);
             if ($form->isValid()) {
                 $em = $this->getDoctrine()->getManager();
                 $photo->addCommentaire($commentaire);
                 $em->persist($commentaire);
                 $em->flush();
                 $flash = $this->get('translator')->trans('alert.info.commentOk');
                 $this->get('session')->getFlashBag()->add('success', $flash);
                 return $this->redirect($this->generateUrl('perso_galerie_viewOne', array('slug' => $photo->getSlug())));
             }
         }
         return $this->render('PersoGalerieBundle:Galerie:voir.html.twig', array('photo' => $photo, 'form' => $form->createView(), 'commentaires' => $commentairesRecup));
     }
     return $this->render('PersoGalerieBundle:Galerie:voir.html.twig', array('photo' => $photo, 'commentaires' => $commentairesRecup));
 }
 public function getCommentairesByPhotoDesc(Photo $photo)
 {
     $qb = $this->createQueryBuilder('c');
     $qb->join('c.photo', 'p')->where('p.id = :id')->setParameter('id', $photo->getId())->orderBy('c.createdAt', 'DESC');
     return $qb->getQuery()->getResult();
 }