/**
  * Delete a comment with its children
  *
  * @param Request $request
  * @param string  $id
  *
  * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function deleteAction(Request $request, $id)
 {
     $manager = $this->getManagerForClass($this->commentClassName);
     $comment = $manager->find($this->commentClassName, $id);
     if (null === $comment) {
         throw new NotFoundHttpException(sprintf('Comment with id %s not found.', $id));
     }
     if ($comment->getAuthor() !== $this->getUser()) {
         throw new AccessDeniedException('You are not allowed to delete this comment.');
     }
     $this->commentManager->remove($comment);
     return new JsonResponse();
 }
 /**
  * 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]);
 }