Newscoop\Entity\Repository\CommentRepository::getDirectReplies PHP Méthode

getDirectReplies() public méthode

Get direct replies to a comment
public getDirectReplies ( $commentId )
$commentId return array
    public function getDirectReplies($commentId)
    {
        $em = $this->getEntityManager();
        $qb = $em->createQueryBuilder();
        $qb->add('select', 'c.id')->add('from', 'Newscoop\\Entity\\Comment c')->add('where', 'c.parent = :p_comment_id')->setParameter('p_comment_id', $commentId);
        $query = $qb->getQuery();
        $commentIds = $query->getArrayResult();
        $clearCommentIds = array();
        foreach ($commentIds as $key => $value) {
            $clearCommentIds[] = $value['id'];
        }
        return $clearCommentIds;
    }

Usage Example

 /**
  * @param \Newscoop\Entity\Repository\CommentRepository $commentRepository
  */
 public function it_should_get_all_replies($commentRepository)
 {
     $commentRepository->getDirectReplies(33)->willReturn(array(20));
     $commentRepository->getDirectReplies(20)->willReturn(array());
     $this->getAllReplies(33, $commentRepository)->shouldReturn(array(33, 20));
 }