Newscoop\NewscoopBundle\Controller\BackendJournalistDashboardController::loadUsersAction PHP Метод

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

public loadUsersAction ( Request $request )
$request Symfony\Component\HttpFoundation\Request
    public function loadUsersAction(Request $request)
    {
        $em = $this->get('em');
        $userService = $this->get('user');
        $cacheService = $this->get('newscoop.cache');
        $linkService = $this->get('article.link');
        $author = $userService->getCurrentUser()->getAuthor();
        if (!$author) {
            return new JsonResponse(array('error' => 'No Author'));
        }
        $criteria = $this->getCriteria($request);
        $cacheKey = $cacheService->getCacheKey(array('author_articles__' . md5(serialize($criteria)), $author->getId()));
        if ($cacheService->contains($cacheKey)) {
            $responseArray = $cacheService->fetch($cacheKey);
        } else {
            $articlesQuery = $em->getRepository('Newscoop\\Entity\\Article')->getArticlesForAuthor($author->getId(), $criteria);
            $totalCount = $articlesQuery->getHint('knp_paginator.count');
            $dirtyArticles = $articlesQuery->getResult();
            $articles = array();
            foreach ($dirtyArticles as $key => $article) {
                $articles[] = array('id' => $article->getNumber() . '_' . $article->getLanguageId(), 'name' => $article->getName(), 'published' => $article->getPublished(), 'reads' => $article->getReads(), 'link' => $linkService->getLink($article));
            }
            $responseArray = array('records' => $articles, 'queryRecordCount' => count($articles), 'totalRecordCount' => $totalCount);
            $cacheService->save($cacheKey, $responseArray);
        }
        return new JsonResponse($responseArray);
    }
BackendJournalistDashboardController