/** * {@inheritdoc} */ public function setParent(CommentInterface $parent) { $this->parent = $parent; if (!$parent->getId()) { throw new InvalidArgumentException('Parent comment must be persisted.'); } $ancestors = $parent->getAncestors(); $ancestors[] = $parent->getId(); $this->setAncestors($ancestors); }
/** * 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(); }