Browse Source

fix pagination

main
ghost 1 year ago
parent
commit
d9ecec44c0
  1. 33
      src/Controller/SearchController.php
  2. 24
      src/Controller/TorrentController.php
  3. 40
      templates/default/torrent/list.html.twig

33
src/Controller/SearchController.php

@ -21,39 +21,8 @@ class SearchController extends AbstractController
return $this->render( return $this->render(
'default/search/module.html.twig', '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;
}
} }

24
src/Controller/TorrentController.php

@ -221,7 +221,7 @@ class TorrentController extends AbstractController
); );
// Init request // 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; $page = $request->get('page') ? (int) $request->get('page') : 1;
// Get total torrents // Get total torrents
@ -322,8 +322,14 @@ class TorrentController extends AbstractController
} }
return $this->render('default/torrent/list.html.twig', [ return $this->render('default/torrent/list.html.twig', [
'query' => $request->query->get('query'), 'query' => urldecode($request->get('query')),
'torrents' => $torrents 'torrents' => $torrents,
'pagination' =>
[
'page' => $page,
'pages' => ceil($total / $this->getParameter('app.pagination')),
'total' => $total
]
]); ]);
} }
@ -379,7 +385,7 @@ class TorrentController extends AbstractController
// Generate keywords // Generate keywords
$keywords = []; $keywords = [];
$query = explode(' ', mb_strtolower($request->query->get('query'))); $query = explode(' ', mb_strtolower(urldecode($request->query->get('query'))));
foreach ($torrent->getKeywords() as $keyword) foreach ($torrent->getKeywords() as $keyword)
{ {
if (in_array($keyword, $query)) if (in_array($keyword, $query))
@ -452,8 +458,13 @@ class TorrentController extends AbstractController
} }
return $this->render('default/torrent/list.html.twig', [ 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( return $this->render(
'default/torrent/list.rss.twig', 'default/torrent/list.rss.twig',
[ [
'query' => $request->query->get('query'),
'torrents' => $torrents 'torrents' => $torrents
], ],
$response $response

40
templates/default/torrent/list.html.twig

@ -137,6 +137,46 @@
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
{% if pagination.pages > 1 %}
<div class="margin-t-16-px text-right">
{{ 'Page' | trans | lower }} {{ pagination.page }} / {{ pagination.pages }}
{% if query %}
{% if pagination.page > 1 %}
{% if pagination.page == 2 %}
<a rel="nofollow" class="button margin-l-8-px" href="{{ path('torrent_search', { query : query | url_encode(true) | raw }) }}">
{{ 'Back' | trans | lower }}
</a>
{% else %}
<a rel="nofollow" class="button margin-l-8-px" href="{{ path('torrent_search', { query : query | url_encode(true), page : pagination.page - 1 }) }}">
{{ 'Back' | trans | lower }}
</a>
{% endif %}
{% endif %}
{% if pagination.page < pagination.pages %}
<a rel="nofollow" class="button margin-l-8-px" href="{{ path('torrent_search', { query : query | url_encode(true), page : pagination.page + 1 }) }}">
{{ 'Next' | trans | lower }}
</a>
{% endif %}
{% else %}
{% if pagination.page > 1 %}
{% if pagination.page == 2 %}
<a rel="nofollow" class="button margin-l-8-px" href="{{ path('torrent_recent') }}">
{{ 'Back' | trans | lower }}
</a>
{% else %}
<a rel="nofollow" class="button margin-l-8-px" href="{{ path('torrent_recent', { page : pagination.page - 1 }) }}">
{{ 'Back' | trans | lower }}
</a>
{% endif %}
{% endif %}
{% if pagination.page < pagination.pages %}
<a rel="nofollow" class="button margin-l-8-px" href="{{ path('torrent_recent', { page : pagination.page + 1 }) }}">
{{ 'Next' | trans | lower }}
</a>
{% endif %}
{% endif %}
</div>
{% endif %}
{% else %} {% else %}
<div class="padding-24-px margin-y-8-px border-radius-3-px background-color-night"> <div class="padding-24-px margin-y-8-px border-radius-3-px background-color-night">
<div class="text-center"> <div class="text-center">

Loading…
Cancel
Save