forked from lubiana/futtern
#33: limit orders on first page and paginate
This commit is contained in:
parent
7e53705b4b
commit
5d41b6fef5
4 changed files with 57 additions and 19 deletions
|
@ -14,11 +14,32 @@ use Symfony\Component\Routing\Attribute\Route;
|
|||
#[Route('/food/order')]
|
||||
final class FoodOrderController extends AbstractController
|
||||
{
|
||||
#[Route('/', name: 'app_food_order_index', methods: ['GET'])]
|
||||
public function index(FoodOrderRepository $foodOrderRepository): Response
|
||||
#[Route(
|
||||
path: '/list/{page}',
|
||||
name: 'app_food_order_index',
|
||||
requirements: [
|
||||
'page' => '\d+',
|
||||
],
|
||||
methods: ['GET']
|
||||
)]
|
||||
public function index(FoodOrderRepository $foodOrderRepository, int $page = 1): Response
|
||||
{
|
||||
$days = 4;
|
||||
if ($page > 1) {
|
||||
$days = 0;
|
||||
}
|
||||
$nextPage = $page + 1;
|
||||
$prevPage = $page - 1;
|
||||
$itemsPerPage = 10;
|
||||
if($foodOrderRepository->count() < $page * $itemsPerPage) {
|
||||
$nextPage = $page;
|
||||
}
|
||||
|
||||
return $this->render('food_order/index.html.twig', [
|
||||
'food_orders' => $foodOrderRepository->findLatestEntries(),
|
||||
'food_orders' => $foodOrderRepository->findLatestEntries(page: $page, pagesize: $itemsPerPage, days: $days),
|
||||
'current_page' => $page,
|
||||
'next_page' => $nextPage,
|
||||
'prev_page' => $prevPage,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue