public function addCommentWidgetAction(request $request, $idTarget = NULL)
 {
     $history = new History();
     $rate = new Rate();
     $rateInfo = new RateInfo();
     $em = $this->getDoctrine()->getManager();
     $form = $this->get('form.factory')->create(new CommentAdd(), $rate);
     if ($form->handleRequest($request)->isValid()) {
         $idTarget = $form["idTarget"]->getData();
         $rate->setUser($this->getUser());
         $rate->setDate(new \Datetime());
         $rate->setActive(1);
         $em->persist($rate);
         $em->flush();
         $rateInfo->setType(1);
         $rateInfo->setRate($rate);
         $rateInfo->setIdTarget($idTarget);
         $rateInfo->setIdTargetType(2);
         $em->persist($rateInfo);
         $em->flush();
         $history->setUser($this->getUser());
         $history->setActionType(6);
         $history->setIdType(2);
         $history->setIdTarget($idTarget);
         $history->setDate(new \Datetime());
         $em->persist($history);
         $em->flush();
         $this->get('session')->getFlashBag()->add('success', 'Commentaire ajouté');
         return $this->redirect($this->generateUrl('ur_product_view', array('id' => $idTarget)));
     }
     return $this->render('URRateBundle:Default:addComment.html.twig', array('form' => $form->createView(), 'idTarget' => $idTarget));
 }
 public function dislikeAction($id)
 {
     $rate = new Rate();
     $rateInfo = new RateInfo();
     $history = new History();
     $item = new Items();
     if ($user = $this->getUser()) {
         $em = $this->getDoctrine()->getManager();
         $rate->setUser($user);
         $rate->setDate(new \Datetime());
         $rate->setActive(1);
         $em->persist($rate);
         $em->flush();
         // Add Action Dislike
         $rateInfo->setType(3);
         $rateInfo->setRate($rate);
         $rateInfo->setIdTarget($id);
         $rateInfo->setIdTargetType(2);
         $em->persist($rateInfo);
         $em->flush();
         // Set Historique
         $history->setUser($user);
         $history->setActionType(3);
         $history->setIdType(2);
         $history->setIdTarget($id);
         $history->setDate(new \Datetime());
         $em->persist($history);
         $em->flush();
         $productRepository = $em->getRepository('URProductBundle:Product');
         $product = $productRepository->findById($id)[0];
         // Ajout liste Dislike
         $listRepository = $em->getRepository('URUserBundle:Lists');
         $list = $listRepository->findByTypeUser(4, $user->getId())[0];
         $item->setProduct($product);
         $item->setList($list);
         $em->persist($item);
         $em->flush();
         $list->setNbItems($list->getNbItems() + 1);
         $em->persist($list);
         $em->flush();
         return new Response("<div class='alert alert-success alert-dismissible' style='text-align:center;' role='alert'>\n                <button type='button' class='close' data-dismiss='alert' aria-label='Close'>\n                <span aria-hidden='true'>&times;</span>\n                </button>\n                Vote enregistré.\n                </div>");
     } else {
         return new Response("<div class='alert alert-warning alert-dismissible' style='text-align:center;' role='alert'>\n                <button type='button' class='close' data-dismiss='alert' aria-label='Close'>\n                <span aria-hidden='true'>&times;</span>\n                </button>\n                Vous devez être connecté pour noter un produit.\n                </div>");
     }
     return new Response("<div class='alert alert-error alert-dismissible' style='text-align:center;' role='alert'>\n                <button type='button' class='close' data-dismiss='alert' aria-label='Close'>\n                <span aria-hidden='true'>&times;</span>\n                </button>\n                Erreur de connexion avec le serveur.\n                </div>");
 }