/**
  * @Security("is_granted('IS_AUTHENTICATED_REMEMBERED')")
  */
 public function favAction($slug, Request $request)
 {
     if ($request->isXmlHttpRequest()) {
         $em = $this->getDoctrine()->getManager();
         $advert = $em->getRepository('FBAdvertBundle:Advert')->findOneBySlug($slug);
         if ($advert === null) {
             return new JsonResponse();
         }
         $favorite = $em->getRepository('FBAdvertBundle:Favorite')->getFavorite($this->getUser(), $advert);
         if ($favorite === null) {
             $favorite = new Favorite();
             $favorite->setUser($this->getUser());
             $favorite->setAdvert($advert);
             $em->persist($favorite);
             $em->flush();
             return new JsonResponse(true);
         } else {
             $em->remove($favorite);
             $em->flush();
             return new JsonResponse(false);
         }
     }
     return $this->redirect($this->generateUrl('fb_advert_view', array('slug' => $slug)));
 }
 /**
  * Add favorites
  *
  * @param \FB\AdvertBundle\Entity\Favorite $favorites
  * @return Advert
  */
 public function addFavorite(\FB\AdvertBundle\Entity\Favorite $favorites)
 {
     $this->favorites[] = $favorites;
     $favorites->setAdvert($this);
     return $this;
 }