Skip to content

Commit

Permalink
Fixed Query::paginate()
Browse files Browse the repository at this point in the history
  • Loading branch information
Max13 committed Oct 2, 2020
1 parent 2eeef00 commit 3f3907a
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,21 +251,19 @@ public function getMessage($msgno, $msglist = null){
* @throws GetMessagesFailedException
*/
public function paginate($per_page = 5, $page = null, $page_name = 'imap_page'){
$this->page = $page > $this->page ? $page : $this->page;
$this->limit = $per_page;

$messages = $this->get();
if (($count = $messages->count()) > 0) {
$limit = $this->limit > $count ? $count : $this->limit;
$collection = array_fill(0, $messages->total() - $limit, true);
$messages->each(function($message) use(&$collection){
$collection[] = $message;
});
}else{
$collection = array_fill(0, $messages->total(), true);
if (
$page === null
&& isset($_GET[$page_name])
&& $_GET[$page_name] > 0
) {
$this->page = intval($_GET[$page_name]);
} elseif ($page > 0) {
$this->page = $page;
}

return MessageCollection::make($collection)->paginate($per_page, $this->page, $page_name);
$this->limit = $per_page;

return $this->get()->paginate($per_page, $this->page, $page_name);
}

/**
Expand Down

0 comments on commit 3f3907a

Please sign in to comment.