From d9ecec44c0facc7170502a6c9b93f33e93399e83 Mon Sep 17 00:00:00 2001 From: ghost Date: Sat, 14 Oct 2023 18:41:23 +0300 Subject: [PATCH] fix pagination --- src/Controller/SearchController.php | 33 +------------------ src/Controller/TorrentController.php | 24 +++++++++----- templates/default/torrent/list.html.twig | 40 ++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 39 deletions(-) diff --git a/src/Controller/SearchController.php b/src/Controller/SearchController.php index 30b06b6..0bc57fb 100644 --- a/src/Controller/SearchController.php +++ b/src/Controller/SearchController.php @@ -21,39 +21,8 @@ class SearchController extends AbstractController return $this->render( 'default/search/module.html.twig', [ - 'query' => $query, + 'query' => urldecode($query), ] ); } - - private function initUser( - Request $request, - UserService $userService, - ActivityService $activityService - ): ?\App\Entity\User - { - // Init user - if (!$user = $userService->findUserByAddress($request->getClientIp())) - { - $user = $userService->addUser( - $request->getClientIp(), - time(), - $this->getParameter('app.locale'), - explode('|', $this->getParameter('app.locales')), - $activityService->getEventCodes(), - $this->getParameter('app.theme'), - $this->getParameter('app.sensitive'), - $this->getParameter('app.yggdrasil'), - $this->getParameter('app.approved') - ); - - // Add user join event - $activityService->addEventUserAdd( - $user->getId(), - time() - ); - } - - return $user; - } } \ No newline at end of file diff --git a/src/Controller/TorrentController.php b/src/Controller/TorrentController.php index 76b09a7..3b0bd1b 100644 --- a/src/Controller/TorrentController.php +++ b/src/Controller/TorrentController.php @@ -221,7 +221,7 @@ class TorrentController extends AbstractController ); // Init request - $query = $request->get('query') ? explode(' ', $request->get('query')) : []; + $query = $request->get('query') ? explode(' ', urldecode($request->get('query'))) : []; $page = $request->get('page') ? (int) $request->get('page') : 1; // Get total torrents @@ -322,8 +322,14 @@ class TorrentController extends AbstractController } return $this->render('default/torrent/list.html.twig', [ - 'query' => $request->query->get('query'), - 'torrents' => $torrents + 'query' => urldecode($request->get('query')), + 'torrents' => $torrents, + 'pagination' => + [ + 'page' => $page, + 'pages' => ceil($total / $this->getParameter('app.pagination')), + 'total' => $total + ] ]); } @@ -379,7 +385,7 @@ class TorrentController extends AbstractController // Generate keywords $keywords = []; - $query = explode(' ', mb_strtolower($request->query->get('query'))); + $query = explode(' ', mb_strtolower(urldecode($request->query->get('query')))); foreach ($torrent->getKeywords() as $keyword) { if (in_array($keyword, $query)) @@ -452,8 +458,13 @@ class TorrentController extends AbstractController } return $this->render('default/torrent/list.html.twig', [ - 'query' => $request->query->get('query'), - 'torrents' => $torrents + 'torrents' => $torrents, + 'pagination' => + [ + 'page' => $page, + 'pages' => ceil($total / $this->getParameter('app.pagination')), + 'total' => $total + ] ]); } @@ -531,7 +542,6 @@ class TorrentController extends AbstractController return $this->render( 'default/torrent/list.rss.twig', [ - 'query' => $request->query->get('query'), 'torrents' => $torrents ], $response diff --git a/templates/default/torrent/list.html.twig b/templates/default/torrent/list.html.twig index 951eade..3b2ce7a 100644 --- a/templates/default/torrent/list.html.twig +++ b/templates/default/torrent/list.html.twig @@ -137,6 +137,46 @@ {% endfor %} + {% if pagination.pages > 1 %} +
+ {{ 'Page' | trans | lower }} {{ pagination.page }} / {{ pagination.pages }} + {% if query %} + {% if pagination.page > 1 %} + {% if pagination.page == 2 %} + + {{ 'Back' | trans | lower }} + + {% else %} + + {{ 'Back' | trans | lower }} + + {% endif %} + {% endif %} + {% if pagination.page < pagination.pages %} + + {{ 'Next' | trans | lower }} + + {% endif %} + {% else %} + {% if pagination.page > 1 %} + {% if pagination.page == 2 %} + + {{ 'Back' | trans | lower }} + + {% else %} + + {{ 'Back' | trans | lower }} + + {% endif %} + {% endif %} + {% if pagination.page < pagination.pages %} + + {{ 'Next' | trans | lower }} + + {% endif %} + {% endif %} +
+ {% endif %} {% else %}