42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Magnetico\Entity\Torrent;
|
|
use App\Search\TorrentSearcher;
|
|
use Pagerfanta\Adapter\DoctrineORMAdapter;
|
|
use Pagerfanta\Pagerfanta;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\{Request, Response};
|
|
|
|
class TorrentController extends AbstractController
|
|
{
|
|
private const PER_PAGE = 20;
|
|
|
|
public function searchTorrent(Request $request, TorrentSearcher $searcher): Response
|
|
{
|
|
$query = $request->query->get('query', '');
|
|
$page = (int) $request->query->get('page', '1');
|
|
$orderBy = $request->query->get('order-by');
|
|
$order = $request->query->get('order', 'asc');
|
|
|
|
$pagerAdapter = new DoctrineORMAdapter($searcher->createSearchQueryBuilder($query, $orderBy, $order));
|
|
$pager = new Pagerfanta($pagerAdapter);
|
|
$pager
|
|
->setCurrentPage($page)
|
|
->setMaxPerPage(self::PER_PAGE)
|
|
;
|
|
|
|
return $this->render('search_results.html.twig', [
|
|
'torrents' => $pager,
|
|
'searchQuery' => $query,
|
|
]);
|
|
}
|
|
|
|
public function showTorrent(Torrent $torrent): Response
|
|
{
|
|
return $this->render('torrent_show.html.twig', [
|
|
'torrent' => $torrent,
|
|
]);
|
|
}
|
|
} |