예제 #1
0
 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));
 }
예제 #2
0
 public function viewAction($id)
 {
     $history = new History();
     if (empty($product = $this->getDoctrine()->getRepository('URProductBundle:Product')->find($id))) {
         throw new NotFoundHttpException('Cet article n\'existe pas');
     }
     // Specifications :
     $specs = $this->getDoctrine()->getRepository('URProductBundle:Specification')->findFor($id);
     // Magasins :
     $sells = $this->getDoctrine()->getRepository('URStoreBundle:StoreSell')->findStoresForProduct($id);
     // Rates :
     if ($user = $this->getUser()) {
         $like = $this->getDoctrine()->getRepository('URRateBundle:RateInfo')->findLikeForUserTarget($user->getId(), $id);
         $dislike = $this->getDoctrine()->getRepository('URRateBundle:RateInfo')->findDislikeForUserTarget($user->getId(), $id);
         $history->setUser($user);
         $history->setActionType(1);
         $history->setIdType(2);
         $history->setIdTarget($id);
         $history->setDate(new \Datetime());
         $em = $this->getDoctrine()->getManager();
         $em->persist($history);
         $em->flush();
     }
     return $this->render('URProductBundle:Default:view.html.twig', array('product' => $product, 'specs' => $specs, 'sells' => $sells, 'like' => !empty($like), 'dislike' => !empty($dislike)));
 }
예제 #3
0
 public function user_editAction(Request $request)
 {
     $history = new History();
     if ($user = $this->getUser()) {
         $user->setAddress($this->getDoctrine()->getRepository('URCoreBundle:Address')->find($user->getId_address()));
         $form = $this->get('form.factory')->create(new UserType(), $user);
         if ($form->handleRequest($request)->isValid()) {
             // $user = $form->getData();
             $em = $this->getDoctrine()->getManager();
             $em->persist($user->getAddress());
             $em->flush();
             $em->persist($user);
             $em->flush();
             $this->get('session')->getFlashBag()->add('success', 'Profil mis à jour.');
             $history->setUser($user);
             $history->setActionType(7);
             $history->setDate(new \Datetime());
             $em->persist($history);
             $em->flush();
             return $this->redirect($this->generateUrl('ur_user_me'));
         }
     } else {
         throw new AccessDeniedException('Vous devez être connecté pour accéder à cette page.');
     }
     return $this->render('URUserBundle:Default:edit.html.twig', array('form' => $form->createView()));
 }
예제 #4
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>");
 }