/** * Returns a flat array of comments of a specific thread. * * @param ThreadInterface $thread * @param integer $depth * @return array of ThreadInterface */ public function findCommentsByThread(ThreadInterface $thread, $depth = null, $sorterAlias = null) { $qb = $this->repository->createQueryBuilder()->field('thread.$id')->equals($thread->getId())->sort('ancestors', 'ASC'); if ($depth > 0) { // Queries for an additional level so templates can determine // if the final 'depth' layer has children. $qb->field('depth')->lte($depth + 1); } $comments = $qb->getQuery()->execute(); if (null !== $sorterAlias) { $sorter = $this->sortingFactory->getSorter($sorterAlias); $comments = $sorter->sortFlat($comments); } return $comments; }
/** * Returns a flat array of comments of a specific thread. * * @param ThreadInterface $thread * @param integer $depth * @return array of ThreadInterface */ public function findCommentsByThread(ThreadInterface $thread, $depth = null, $sorterAlias = null) { $qb = $this->repository->createQueryBuilder('c')->join('c.thread', 't')->where('t.id = :thread')->orderBy('c.ancestors', 'ASC')->setParameter('thread', $thread->getId()); if ($depth > 0) { // Queries for an additional level so templates can determine // if the final 'depth' layer has children. $qb->andWhere('c.depth <= :depth')->setParameter('depth', $depth + 1); } $comments = $qb->getQuery()->execute(); if (null !== $sorterAlias) { $sorter = $this->getSortingFactory()->getSorter($sorterAlias); $comments = $sorter->sortFlat($comments); } return $comments; }