From df4f744f6ddfeb0b10c5fcf4c1fbbd37fb075f78 Mon Sep 17 00:00:00 2001 From: msquare Date: Mon, 14 Aug 2023 16:02:11 +0200 Subject: [PATCH] fixes #1180: meeting/news pagination --- resources/views/pages/news/overview.twig | 2 +- src/Controllers/NewsController.php | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/resources/views/pages/news/overview.twig b/resources/views/pages/news/overview.twig index e3adc0b6..542161d1 100644 --- a/resources/views/pages/news/overview.twig +++ b/resources/views/pages/news/overview.twig @@ -33,7 +33,7 @@ diff --git a/src/Controllers/NewsController.php b/src/Controllers/NewsController.php index e8e9d311..0b9a163c 100644 --- a/src/Controllers/NewsController.php +++ b/src/Controllers/NewsController.php @@ -130,6 +130,10 @@ class NewsController extends BaseController $query = $query->where('is_meeting', true); } + $count = $query->count(); + $pagesCount = max(1, ceil($count / $perPage)); + $page = max(1, min($page, $pagesCount)); + $news = $query ->with('user') ->withCount('comments') @@ -140,14 +144,13 @@ class NewsController extends BaseController ->limit($perPage) ->offset(($page - 1) * $perPage) ->get(); - $pagesCount = ceil($query->count() / $perPage); return $this->renderView( 'pages/news/overview.twig', [ 'news' => $news, - 'pages' => max(1, $pagesCount), - 'page' => max(1, min($page, $pagesCount)), + 'pages' => $pagesCount, + 'page' => $page, 'only_meetings' => $onlyMeetings, 'is_overview' => true, ]