/**
  * Decrease movie likes
  * @param MoviesLikes $entity
  */
 protected function decreaseLikes(MoviesLikes $entity)
 {
     $movie = $entity->getMovie();
     $movie->setLikes($movie->getLikes() - 1);
     $this->em->persist($movie);
     $this->em->flush();
 }
示例#2
0
 /**
  * Perform like action
  * @param Request $request
  * @param $id
  * @return JsonResponse
  */
 public function likeAction(Request $request, $id)
 {
     $em = $this->getDoctrine()->getManager();
     $me = $this->get('security.context')->getToken()->getUser();
     $movie = $em->getRepository('AppBundle:Movies')->find($id);
     $response = new \stdClass();
     $response->saved = 0;
     if ($movie instanceof Movies && $movie->getUser()->getId() != $me->getId()) {
         $this->delete_hate($me->getId(), $id);
         $like = new MoviesLikes();
         $like->setMovie($movie);
         $like->setUser($me);
         $em->persist($like);
         $em->flush();
         if ($like->getId() > 0) {
             $response->saved = 1;
         }
     }
     return new JsonResponse($response);
 }