Ejemplo n.º 1
0
 /**
  * Visualise un produit
  * @author Eric
  * 
  * @param Product $product
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  * @ParamConverter("product", options={
  *      "mapping": {"idproduct": "id"},
  *      "repository_method" = "findOneProductWithAllElement"
  * })
  */
 public function showAction(Product $product, Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $comment = new Comment();
     $comment->setProduct($product);
     $formComment = $this->createForm(new CommentType(), $comment, ['attr' => ['novalidate' => 'novalidate']])->add('submit', 'submit', ['label' => 'Enregistrer', 'attr' => ['class' => 'btn btn-primary']]);
     $formComment->handleRequest($request);
     if ($formComment->isValid()) {
         $comment->setClient($this->getUser());
         $em->persist($comment);
         $em->flush();
         $this->get('session')->getFlashBag()->add("success", "Le commenataire a bien été ajouté");
         return $this->redirectToRoute('troiswa_front_product_show', ['idproduct' => $product->getId()]);
     }
     $comments = $em->getRepository('TroiswaFrontBundle:Comment')->findCommentsByProductId($product->getId());
     return $this->render('TroiswaFrontBundle:Product:show.html.twig', ['product' => $product, 'form_comment' => $formComment->createView(), 'comments' => $comments]);
 }
Ejemplo n.º 2
0
 public function produitAction(Product $product, Request $request)
 {
     //pour créer le formulaire automtqm dans le fichier show.html.twig
     $comment = new Comment();
     $em = $this->getDoctrine()->getManager();
     //la requette pour recuperer le commentaire dans la base de donnée
     $commentaires = $em->getRepository('TroiswaFrontBundle:Comment')->findBy(['produit' => $product]);
     //dump($commentaires);
     //die;
     $comment->setProduit($product);
     $formComment = $this->createForm(new CommentType(), $comment, ['attr' => ['novalidate' => 'novalidate']])->add('submit', 'submit', ['label' => 'Enregistrer']);
     //pour enregistrer dans la base de donnée
     $formComment->handleRequest($request);
     if ($formComment->isValid()) {
         //pour verifier la connection du client si non connecter pas possible
         $comment->setClient($this->getUser());
         $comment->setProduit($product);
         $em->persist($comment);
         $em->flush();
         $this->get('session')->getFlashBag()->add('success', 'Le commentaire est enregistré');
         return $this->redirectToRoute('troiswa_front_product', ['id' => $product->getId()]);
     }
     return $this->render("TroiswaFrontBundle:ProductFront:show.html.twig", ["product" => $product, "form_comment" => $formComment->createView(), 'AfficheCommentaires' => $commentaires]);
 }
Ejemplo n.º 3
0
 public function displayCommentFormProductAction(Product $product, Request $originalRequest, Request $request)
 {
     $comment = new Comment();
     $comment->setProduct($product);
     //        dump($this->getUser());
     //        die;
     $author = $this->getUser();
     $formComment = $this->createForm(new CommentType(), $comment);
     // hydrate le formulaire avec les informations stockées dans S_POST
     $formComment->handleRequest($originalRequest);
     //        dump($idprod);
     //        die();
     if ($formComment->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $comment->setAuthor($author);
         $comment->setProduct($product);
         $em->persist($comment);
         $em->flush();
         // affichage du message du succès d'envoi du commentaire
         $this->get('session')->getFlashBag()->add('success', "Votre commentaire a bien été enregistré");
         return $this->forward('TroiswaFrontBundle:Main:displayCommentFormProduct', ['product' => $product, 'originalRequest' => $request]);
     }
     return $this->render("TroiswaFrontBundle:Product:product-comment.html.twig", array("formComment" => $formComment->createView()));
 }