From eb48f95a3d48ce7119ac471c2a85771489514309 Mon Sep 17 00:00:00 2001 From: Daniel Pett Date: Thu, 26 May 2022 09:05:03 +0100 Subject: [PATCH] Fix pagination 1. Add model 2. Change function in controller 3. Update view Closes #409 --- app/Http/Controllers/aboutusController.php | 24 +++---------- app/Models/PressRoom.php | 39 ++++++++++++++++++++++ resources/views/aboutus/press.blade.php | 4 +-- 3 files changed, 46 insertions(+), 21 deletions(-) create mode 100644 app/Models/PressRoom.php diff --git a/app/Http/Controllers/aboutusController.php b/app/Http/Controllers/aboutusController.php index 17aae015..df8e3c00 100644 --- a/app/Http/Controllers/aboutusController.php +++ b/app/Http/Controllers/aboutusController.php @@ -4,6 +4,7 @@ use App\Models\Directors; use App\Models\Governance; +use App\Models\PressRoom; use App\Models\PressTerms; use App\Models\SpoliationClaims; use App\Models\StaffProfiles; @@ -98,7 +99,8 @@ public function governance(): View $mission = Governance::getGovernanceByType('Mission'); $education = Governance::getGovernanceByType('Education Report'); $research = Governance::getGovernanceByType('Research'); - return view('aboutus.governance', compact( + return view('aboutus.governance', + compact( 'policy', 'strategy', 'review', 'report', 'mission', 'education', 'research' @@ -113,24 +115,8 @@ public function governance(): View */ public function press(Request $request): View { - $perPage = 6; - $directus = $this->getApi(); - $directus->setEndpoint('pressroom_files'); - $directus->setArguments( - array( - 'fields' => '*.*.*', - 'limit' => $perPage, - 'offset' => ($request['page'] - 1) * $perPage, - 'meta' => '*', - 'sort' => '-release_date' - ) - ); - $press = $directus->getData(); - $currentPage = LengthAwarePaginator::resolveCurrentPage(); - $total = $press['meta']['total_count']; - $paginator = new LengthAwarePaginator($press, $total, $perPage, $currentPage); - $paginator->setPath('press-room'); - return view('aboutus.press', compact('press', 'paginator')); + $press = PressRoom::list($request); + return view('aboutus.press', compact( 'press')); } /** diff --git a/app/Models/PressRoom.php b/app/Models/PressRoom.php new file mode 100644 index 00000000..a2cd61c6 --- /dev/null +++ b/app/Models/PressRoom.php @@ -0,0 +1,39 @@ +setEndpoint('pressroom_files'); + $directus->setArguments( + array( + 'fields' => '*.*.*', + 'limit' => $perPage, + 'offset' => ($request['page'] - 1) * $perPage, + 'meta' => '*', + 'sort' => '-release_date' + ) + ); + $press = $directus->getData(); + $currentPage = LengthAwarePaginator::resolveCurrentPage(); + $total = $press['meta']['total_count']; + $paginator = new LengthAwarePaginator($press, $total, $perPage, $currentPage); + $paginator->setPath(route('press-room')); + return $paginator; + } +} diff --git a/resources/views/aboutus/press.blade.php b/resources/views/aboutus/press.blade.php index 554215a5..291af47f 100644 --- a/resources/views/aboutus/press.blade.php +++ b/resources/views/aboutus/press.blade.php @@ -16,10 +16,10 @@ @section('releases')
- @foreach($press['data'] as $release) + @foreach($press->items()['data'] as $release) @endforeach
- {{ $paginator->appends(request()->except('page'))->links() }} + {{ $press->appends(request()->except('page'))->links() }}
@endsection