Пример #1
0
 /**
  * Displays a form to create a new Comment entity.
  *
  * @Route("/saveComment/", name="comment_new")
  * @Method("POST")
  * @Template()
  */
 public function newAction(Request $request)
 {
     $commentForUserRequest = $request->request->get('commentForUser');
     $auctionRequest = $request->request->getInt('auction');
     $descriptionRequest = $request->request->get('description');
     $em = $this->getDoctrine()->getManager();
     $auction = $em->getRepository('AppBundle:Auction')->find($auctionRequest);
     $commentForUser = $em->getRepository('ApplicationSonataUserBundle:User')->findOneBy(array('username' => $commentForUserRequest));
     $entity = new Comment();
     $entity->setDescription($descriptionRequest);
     $entity->setAuction($auction);
     $auction->addComment($entity);
     $user = $this->get('security.token_storage')->getToken()->getUser();
     $entity->setUserSendComment($user);
     $entity->setUserReceivedComment($commentForUser);
     $seller = $auction->getUser();
     if ($user == $seller) {
         $entity->setBuyer(false);
     } else {
         $entity->setBuyer(true);
     }
     $em = $this->getDoctrine()->getManager();
     $em->persist($entity);
     $em->flush();
     return $this->redirect($this->generateUrl('comment_show', array('id' => $entity->getId())));
 }
Пример #2
0
 /**
  * Add comment
  *
  * @param \AppBundle\Entity\Comment $comment
  *
  * @return Auction
  */
 public function addComment(\AppBundle\Entity\Comment $comment)
 {
     $this->comment[] = $comment;
     $comment->setAuction($this);
     return $this;
 }