]> Raphaël G. Git Repositories - blogbundle/blobdiff - Controller/KeywordController.php
Restore root default route
[blogbundle] / Controller / KeywordController.php
index d76540405c7acfceeceff41b4286c78707d944c9..b0c9eb2e594fa4e07a8efe9c27c3625669b5870c 100644 (file)
@@ -30,39 +30,18 @@ class KeywordController extends AbstractController {
         * @return Response The rendered view
         */
        public function index(Request $request): Response {
-               //With keywords
-               if ($count = $this->doctrine->getRepository(Keyword::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 keywords (page: %page%)', ['%page%' => $page]));
-                       }
-
-                       //Without keywords
-                       if (empty($this->context['keywords'] = $this->doctrine->getRepository(Keyword::class)->findAllAsArray($page, $this->limit))) {
-                               //Throw 404
-                               throw $this->createNotFoundException($this->translator->trans('Unable to find keywords'));
-                       }
-
-                       //With prev link
-                       if ($page > 0) {
-                               //Set keywords older
-                               $this->context['head']['prev'] = $this->context['keywords_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 keywords newer
-                               $this->context['head']['next'] = $this->context['keywords_next'] = $this->generateUrl($request->attributes->get('_route'), ['page' => $page + 1]+$request->attributes->get('_route_params'));
-                       }
+               //With not enough keywords
+               if (($this->count = $this->doctrine->getRepository(Keyword::class)->findCountAsInt()) < $this->page * $this->limit) {
+                       //Throw 404
+                       throw $this->createNotFoundException($this->translator->trans('Unable to find keywords'));
+               }
 
+               //Get keywords
+               if ($this->context['keywords'] = $this->doctrine->getRepository(Keyword::class)->findAllAsArray($this->page, $this->limit)) {
                        //Set modified
                        $this->modified = max(array_map(function ($v) { return $v['modified']; }, $this->context['keywords']));
                //Without keywords
                } else {
-                       //Set empty keywords
-                       $this->context['keywords'] = [];
-
                        //Set empty modified
                        $this->modified = new \DateTime('-1 year');
                }
@@ -119,7 +98,7 @@ class KeywordController extends AbstractController {
                );
 
                //Set title
-               $this->context['title'] = $this->translator->trans('Keywords list');
+               $this->context['title']['page'] = $this->translator->trans('Keywords list');
 
                //Set description
                $this->context['description'] = $this->translator->trans('Welcome to raphaël\'s developer diary keyword listing');
@@ -148,7 +127,7 @@ class KeywordController extends AbstractController {
                //With invalid slug
                if ($slug !== $this->context['keyword']['slug']) {
                        //Redirect on correctly spelled keyword
-                       return $this->redirectToRoute('rapsys_blog_keyword_view', ['id' => $this->context['keyword']['id'], 'slug' => $this->context['keyword']['slug']], Response::HTTP_MOVED_PERMANENTLY);
+                       return $this->redirectToRoute('rapsysblog_keyword_view', ['id' => $this->context['keyword']['id'], 'slug' => $this->context['keyword']['slug']], Response::HTTP_MOVED_PERMANENTLY);
                }
 
                //Set modified
@@ -212,7 +191,7 @@ class KeywordController extends AbstractController {
                );
 
                //Set title
-               $this->context['title'] = $this->context['keyword']['title'];
+               $this->context['title']['page'] = $this->context['keyword']['title'];
 
                //Set description
                $this->context['description'] = $this->context['keyword']['description'];