Newscoop\NewscoopBundle\Controller\CommentsController::createCommentsArray PHP Метод

createCommentsArray() приватный Метод

Creates comments array for paginator
private createCommentsArray ( Knp\Bundle\PaginatorBundle $pagination, Newscoop\Services\ImageService $imageService ) : array
$pagination Knp\Bundle\PaginatorBundle Pagination
$imageService Newscoop\Services\ImageService Image service
Результат array
    private function createCommentsArray($pagination, $imageService)
    {
        $em = $this->container->get('em');
        $counter = 1;
        $commentService = $this->container->get('comment');
        $commentsArray = array();
        $commentIds = array();
        foreach ($pagination as $key => $value) {
            $commentIds[] = $value[0]->getId();
        }
        if (!empty($commentIds)) {
            $qb = $em->createQueryBuilder();
            $comments = $qb->from('Newscoop\\Entity\\Comment', 'c', 'c.id')->select('c', 'cc', 'u')->leftJoin('c.commenter', 'cc')->leftJoin('cc.user', 'u')->where($qb->expr()->in('c.id', $commentIds))->getQuery()->getResult();
            foreach ($pagination as $comment) {
                $comment = $comment[0];
                $thread = $em->getRepository('Newscoop\\Entity\\Article')->findOneBy(array('number' => $comment->getThread()));
                $threadSection = $thread->getSection();
                if (!$threadSection) {
                    $thread->setSection(new Section(0, 'No section'));
                }
                $commentsArray[] = array('banned' => $commentService->isBanned($comments[$comment->getId()]->getCommenter()), 'avatarHash' => md5($comments[$comment->getId()]->getCommenter()->getEmail()), 'user' => $comments[$comment->getId()]->getCommenter()->getUser() ? new \MetaUser($comments[$comment->getId()]->getCommenter()->getUser()) : null, 'issueNumber' => $thread->getIssueId(), 'section' => $threadSection ? $threadSection->getName() : '', 'comment' => $comment, 'index' => $counter, 'article' => $thread);
                $counter++;
            }
            return $commentsArray;
        }
        return $commentIds;
    }