2018-06-20 23:37:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
2018-06-23 14:57:10 +00:00
|
|
|
use App\Magnetico\Entity\Torrent;
|
|
|
|
use App\Magnetico\Repository\TorrentRepository;
|
2018-06-20 23:37:35 +00:00
|
|
|
use Pagerfanta\Adapter\DoctrineORMAdapter;
|
|
|
|
use Pagerfanta\Pagerfanta;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
2018-06-22 19:58:36 +00:00
|
|
|
use Symfony\Component\HttpFoundation\{Request, Response};
|
2018-06-20 23:37:35 +00:00
|
|
|
|
|
|
|
class TorrentController extends Controller
|
|
|
|
{
|
|
|
|
private const PER_PAGE = 20;
|
|
|
|
|
2018-06-22 19:45:17 +00:00
|
|
|
public function searchTorrent(Request $request, TorrentRepository $repo): Response
|
2018-06-20 23:37:35 +00:00
|
|
|
{
|
|
|
|
$query = $request->query->get('query', '');
|
|
|
|
$page = (int) $request->query->get('page', '1');
|
|
|
|
|
|
|
|
$pagerAdapter = new DoctrineORMAdapter($repo->createFindLikeQueryBuilder($query));
|
|
|
|
$pager = new Pagerfanta($pagerAdapter);
|
|
|
|
$pager
|
|
|
|
->setCurrentPage($page)
|
|
|
|
->setMaxPerPage(self::PER_PAGE)
|
|
|
|
;
|
|
|
|
|
|
|
|
return $this->render('search_results.html.twig', [
|
|
|
|
'torrents' => $pager,
|
|
|
|
'searchQuery' => $query,
|
|
|
|
]);
|
|
|
|
}
|
2018-06-22 19:45:17 +00:00
|
|
|
|
|
|
|
public function showTorrent(Torrent $torrent): Response
|
|
|
|
{
|
|
|
|
return $this->render('torrent_show.html.twig', [
|
|
|
|
'torrent' => $torrent,
|
|
|
|
]);
|
|
|
|
}
|
2018-06-20 23:37:35 +00:00
|
|
|
}
|