Skip to content

Commit

Permalink
Merge pull request #75 from computerfr33k/master
Browse files Browse the repository at this point in the history
Use Length Aware Paginator
  • Loading branch information
fenos committed Mar 14, 2016
2 parents ab3f565 + 55ab0b9 commit 9b4153a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/Notifynder/Notifications/NotificationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Fenos\Notifynder\Contracts\NotifynderNotification;
use Fenos\Notifynder\Exceptions\NotificationNotFoundException;
use Fenos\Notifynder\Models\Notification as NotificationModel;
use Illuminate\Pagination\Paginator;
use Illuminate\Pagination\LengthAwarePaginator;

/**
* Class NotifynderNotification
Expand Down Expand Up @@ -181,8 +181,8 @@ public function getNotRead($to_id, $limit = null, $paginate = null, $orderDate =

if(is_int(intval($paginate)) && $paginate)
{
return (new Paginator($notifications->parse(), $limit, $paginate, [
'path' => Paginator::resolveCurrentPath(),
return (new LengthAwarePaginator($notifications->parse(), $notifications->total(), $limit, $paginate, [
'path' => LengthAwarePaginator::resolveCurrentPath()
]));
}

Expand All @@ -209,8 +209,8 @@ public function getAll($to_id, $limit = null, $paginate = null, $orderDate = 'de

if(is_int(intval($paginate)) && $paginate)
{
return (new Paginator($notifications->parse(), $limit, $paginate, [
'path' => Paginator::resolveCurrentPath(),
return (new LengthAwarePaginator($notifications->parse(), $notifications->total(), $limit, $paginate, [
'path' => LengthAwarePaginator::resolveCurrentPath()
]));
}

Expand Down
14 changes: 2 additions & 12 deletions src/Notifynder/Notifications/NotificationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,8 @@ public function getNotRead(

$query = $this->applyFilter($filterScope, $query);

if ( is_int($limit)) {
$query->limit($limit);
}

if (is_int(intval($paginate)) && $paginate) {
$query->skip(($paginate - 1) * $limit)->take($limit + 1);
return $query->paginate($limit);
}

return $query->get();
Expand Down Expand Up @@ -280,14 +276,8 @@ public function getAll(

$query = $this->applyFilter($filterScope, $query);


// if the limit is set
if ( is_int($limit)) {
$query->limit($limit);
}

if (is_int(intval($paginate)) && $paginate) {
$query->skip(($paginate - 1) * $limit)->take($limit + 1);
return $query->paginate($limit);
}

return $query->get();
Expand Down

0 comments on commit 9b4153a

Please sign in to comment.