Example #1
0
 public function pushProductInListAction($idProduct, $idList)
 {
     $item = new Items();
     $em = $this->getDoctrine()->getManager();
     $productRepository = $em->getRepository('URProductBundle:Product');
     $listRepository = $em->getRepository('URUserBundle:Lists');
     $product = $productRepository->findById($idProduct)[0];
     $list = $listRepository->findById($idList)[0];
     $item->setProduct($product);
     $item->setList($list);
     $em->persist($item);
     $em->flush();
     $list->setDate(new \Datetime());
     if (($nbItem = $list->getNbItems()) == 0) {
         $list->setType(1);
     }
     $list->setNbItems($nbItem + 1);
     $em->persist($list);
     $em->flush();
     return new Response('Produit ajouté');
 }
Example #2
0
 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>");
 }