Skip to content

Commit

Permalink
Merge pull request #410
Browse files Browse the repository at this point in the history
Fix pagination for press room files
  • Loading branch information
portableant authored May 26, 2022
2 parents 8186cc2 + eb48f95 commit 0e691d5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
24 changes: 5 additions & 19 deletions app/Http/Controllers/aboutusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'
Expand All @@ -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'));
}

/**
Expand Down
39 changes: 39 additions & 0 deletions app/Models/PressRoom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Models;

use App\DirectUs;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;


class PressRoom extends Model
{

/**
* @param string $sort
* @param int $limit
* @return LengthAwarePaginator
*/
public static function list(Request $request): LengthAwarePaginator
{
$perPage = 6;
$directus = new DirectUs();
$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(route('press-room'));
return $paginator;
}
}
4 changes: 2 additions & 2 deletions resources/views/aboutus/press.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
@section('releases')
<div class="container">
<div class="row">
@foreach($press['data'] as $release)
@foreach($press->items()['data'] as $release)
<x-press-card :release="$release"></x-press-card>
@endforeach
</div>
{{ $paginator->appends(request()->except('page'))->links() }}
{{ $press->appends(request()->except('page'))->links() }}
</div>
@endsection

0 comments on commit 0e691d5

Please sign in to comment.