/** * List comments made on a product * * @param Request $request * @param integer|string $id * * @AclAncestor("pim_enrich_product_comment") * * @return \Symfony\Component\HttpFoundation\Response */ public function listCommentsAction(Request $request, $id) { $product = $this->findProductOr404($id); $comment = $this->commentBuilder->buildComment($product, $this->getUser()); $createForm = $this->formFactory->create('pim_comment_comment', $comment); $comments = $this->commentManager->getComments($product); $replyForms = []; foreach ($comments as $comment) { $reply = $this->commentBuilder->buildReply($comment, $this->getUser()); $replyForm = $this->formFactory->create('pim_comment_comment', $reply, ['is_reply' => true]); $replyForms[$comment->getId()] = $replyForm->createView(); } return $this->templating->renderResponse('PimCommentBundle:Comment:_commentList.html.twig', ['createForm' => $createForm->createView(), 'replyForms' => $replyForms, 'comments' => $comments]); }
/** * @param Request $request * * @throws \LogicException * * @return \Symfony\Component\HttpFoundation\Response */ public function createAction(Request $request) { if (true !== $request->isXmlHttpRequest()) { throw new \LogicException('The request should be an Xml Http request.'); } $comment = $this->commentBuilder->buildCommentWithoutSubject($this->getUser()); $createForm = $this->formFactory->create('pim_comment_comment', $comment); $createForm->submit($request); if (true !== $createForm->isValid()) { return new JsonResponse('The form is not valid.', 400); } $this->commentManager->save($comment); $reply = $this->commentBuilder->buildReply($comment, $this->getUser()); $replyForm = $this->formFactory->create('pim_comment_comment', $reply, ['is_reply' => true]); return $this->templating->renderResponse('PimCommentBundle:Comment:_thread.html.twig', ['replyForms' => [$comment->getId() => $replyForm->createView()], 'comment' => $comment]); }