Newscoop\GimmeBundle\Controller\EditorialCommentsApiController::getCommentsAction PHP Метод

getCommentsAction() публичный Метод

Get editorial comments
public getCommentsAction ( Request $request, $number, $language, $order )
$request Symfony\Component\HttpFoundation\Request
    public function getCommentsAction(Request $request, $number, $language, $order)
    {
        $em = $this->container->get('em');
        $editorialComments = $em->getRepository('Newscoop\\ArticlesBundle\\Entity\\EditorialComment')->getAllByArticleNumber($number)->getResult();
        if ($order == 'nested' && $editorialComments) {
            $root = new \Node(0, 0, '');
            $reSortedComments = array();
            foreach ($editorialComments as $comment) {
                $reSortedComments[$comment->getId()] = $comment;
            }
            ksort($reSortedComments);
            foreach ($reSortedComments as $comment) {
                if ($comment->getParent() instanceof EditorialComment) {
                    $node = new \Node($comment->getId(), $comment->getParent()->getId(), $comment);
                } else {
                    $node = new \Node($comment->getId(), 0, $comment);
                }
                $root->insertNode($node);
            }
            $editorialComments = $root->flatten(false);
        }
        $paginator = $this->get('newscoop.paginator.paginator_service');
        $paginator->setUsedRouteParams(array('number' => $number, 'language' => $language));
        $editorialComments = $paginator->paginate($editorialComments);
        return $editorialComments;
    }