/**
  * {@inheritdoc}
  */
 public function saveComment(CommentInterface $comment)
 {
     if (null === $comment->getThread()) {
         throw new InvalidArgumentException('The comment must have a thread');
     }
     $event = new CommentPersistEvent($comment);
     $this->dispatcher->dispatch(Events::COMMENT_PRE_PERSIST, $event);
     if ($event->isPersistenceAborted()) {
         return false;
     }
     $this->doSaveComment($comment);
     $event = new CommentEvent($comment);
     $this->dispatcher->dispatch(Events::COMMENT_POST_PERSIST, $event);
     return true;
 }
 /**
  * {@inheritDoc}
  */
 public function saveComment(CommentInterface $comment)
 {
     if (!$this->threadAcl->canView($comment->getThread())) {
         throw new AccessDeniedException();
     }
     if (!$this->commentAcl->canReply($comment->getParent())) {
         throw new AccessDeniedException();
     }
     $newComment = $this->isNewComment($comment);
     if (!$newComment && !$this->commentAcl->canEdit($comment)) {
         throw new AccessDeniedException();
     }
     if (($comment::STATE_DELETED === $comment->getState() || $comment::STATE_DELETED === $comment->getPreviousState()) && !$this->commentAcl->canDelete($comment)) {
         throw new AccessDeniedException();
     }
     $this->realManager->saveComment($comment);
     if ($newComment) {
         $this->commentAcl->setDefaultAcl($comment);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function addComment(CommentInterface $comment, CommentInterface $parent = null)
 {
     if (!$this->threadAcl->canView($comment->getThread())) {
         throw new AccessDeniedException();
     }
     if (!$this->commentAcl->canReply($parent)) {
         throw new AccessDeniedException();
     }
     $this->realManager->addComment($comment, $parent);
     $this->commentAcl->setDefaultAcl($comment);
 }
 /**
  * Adds a comment
  *
  * @param CommentInterface $comment
  */
 protected function doSaveComment(CommentInterface $comment)
 {
     $this->dm->persist($comment->getThread());
     $this->dm->persist($comment);
     $this->dm->flush();
 }
 /**
  * Adds a comment
  *
  * @param CommentInterface $comment
  */
 public function addComment(CommentInterface $comment)
 {
     if (null !== $comment->getId()) {
         throw new InvalidArgumentException('Can not add already saved comment');
     }
     if (null === $comment->getThread()) {
         throw new InvalidArgumentException('The comment must have a thread');
     }
     $thread = $comment->getThread();
     $thread->incrementNumComments(1);
     $thread->setLastCommentAt(new DateTime());
     $this->em->persist($thread);
     $this->em->persist($comment);
     $this->em->flush();
 }
 /**
  * Checks if the current user is able to edit a comment.
  *
  * @param CommentInterface $comment
  *
  * @return bool If the user is able to comment
  */
 public function canEditComment(CommentInterface $comment)
 {
     if (!$comment->getThread()->isCommentable()) {
         return false;
     }
     if (null === $this->commentAcl) {
         return false;
     }
     return $this->commentAcl->canEdit($comment);
 }