mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2026-04-01 17:45:31 +00:00
fix pagination
This commit is contained in:
parent
851efe0392
commit
d9ecec44c0
3 changed files with 58 additions and 39 deletions
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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…
Add table
Add a link
Reference in a new issue