X-Git-Url: https://git.rapsys.eu/blogbundle/blobdiff_plain/43e1b8410eb706b470cce88978a302ad9b9452a7..dd71a2da0c3191983cde5e2b25fc1d238fc48cd1:/Controller/ArticleController.php diff --git a/Controller/ArticleController.php b/Controller/ArticleController.php index 8effb17..9cdb247 100644 --- a/Controller/ArticleController.php +++ b/Controller/ArticleController.php @@ -30,39 +30,18 @@ class ArticleController extends AbstractController { * @return Response The rendered view */ public function index(Request $request): Response { - //With articles - if ($count = $this->doctrine->getRepository(Article::class)->findCountAsInt()) { - //Negative page or over page - if (($page = (int) $request->get('page', 0)) < 0 || $page > $count / $this->limit) { - //Throw 404 - throw $this->createNotFoundException($this->translator->trans('Unable to find articles (page: %page%)', ['%page%' => $page])); - } - - //Without articles - if (empty($this->context['articles'] = $this->doctrine->getRepository(Article::class)->findAllAsArray($page, $this->limit))) { - //Throw 404 - throw $this->createNotFoundException($this->translator->trans('Unable to find articles')); - } - - //With prev link - if ($page > 0) { - //Set articles older - $this->context['head']['prev'] = $this->context['articles_prev'] = $this->generateUrl($request->attributes->get('_route'), ['page' => $page - 1]+$request->attributes->get('_route_params')); - } - - //With next link - if ($count > ($page + 1) * $this->limit) { - //Set articles newer - $this->context['head']['next'] = $this->context['articles_next'] = $this->generateUrl($request->attributes->get('_route'), ['page' => $page + 1]+$request->attributes->get('_route_params')); - } + //With not enough articles + if (($this->count = $this->doctrine->getRepository(Article::class)->findCountAsInt()) < $this->page * $this->limit) { + //Throw 404 + throw $this->createNotFoundException($this->translator->trans('Unable to find articles')); + } + //Get articles + if ($this->context['articles'] = $this->doctrine->getRepository(Article::class)->findAllAsArray($this->page, $this->limit)) { //Set modified $this->modified = max(array_map(function ($v) { return $v['modified']; }, $this->context['articles'])); - //Without articles + //Without keywords } else { - //Set empty articles - $this->context['articles'] = []; - //Set empty modified $this->modified = new \DateTime('-1 year'); } @@ -189,17 +168,6 @@ class ArticleController extends AbstractController { } } - //Set keywords - $this->context['head']['keywords'] = implode( - ', ', - array_map( - function ($v) { - return $v['title']; - }, - $this->context['article']['keywords'] - ) - ); - //Set keywords $this->context['head']['keywords'] = implode( ', ',