Skip to content

Commit d2cbbe6

Browse files
committed
Query::paginate() method added
1 parent 646b1fd commit d2cbbe6

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
66

77
## [1.4.0] - [UNRELEASED]
88
### Fixed
9-
- iconv(): error supressor for //IGNORE added #184
9+
- iconv(): error suppressor for //IGNORE added #184
1010
- Typo Folder attribute fullName changed to full_name
1111

1212
### Added
@@ -20,6 +20,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
2020
- Message::getHTMLBody($callback) extended
2121
- Masks added (take look at the examples for more information on masks)
2222
- More examples added
23+
- Query::paginate() method added
2324

2425
### Affected Classes
2526
- [Folder::class](src/IMAP/Folder.php)

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,13 @@ $aMessage = $oFolder->query()->since('15.03.2018')->limit(10, 2)->get();
331331
```
332332

333333
#### Pagination
334+
Paginate a query:
335+
``` php
336+
/** @var \Webklex\IMAP\Folder $oFolder */
337+
338+
/** @var \Illuminate\Pagination\LengthAwarePaginator $paginator */
339+
$paginator = $oFolder->query()->since('15.03.2018')->paginate();
340+
```
334341
Paginate a message collection:
335342
``` php
336343
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
@@ -700,6 +707,8 @@ if you're just wishing a feature ;)
700707
| setFetchFlags | boolean $fetch_flags | WhereQuery | Set the fetch flags option |
701708
| leaveUnread | | WhereQuery | Don't mark all messages as "read" while fetching: |
702709
| markAsRead | | WhereQuery | Mark all messages as "read" while fetching |
710+
| paginate | int $perPage = 5, $page = null, $pageName = 'imap_page' | LengthAwarePaginator | Paginate the current query. |
711+
703712
704713
### [Attachment::class](src/IMAP/Attachment.php)
705714

src/IMAP/Query/Query.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,22 @@ public function get() {
191191
}
192192
}
193193

194+
/**
195+
* Paginate the current query
196+
* @param int $per_page
197+
* @param null $page
198+
* @param string $page_name
199+
*
200+
* @return \Illuminate\Pagination\LengthAwarePaginator
201+
* @throws GetMessagesFailedException
202+
*/
203+
public function paginate($per_page = 5, $page = null, $page_name = 'imap_page'){
204+
$this->page = $page > $this->page ? $page : $this->page;
205+
$this->limit = $per_page;
206+
207+
return $this->get()->paginate($per_page = 5, $this->page, $page_name);
208+
}
209+
194210
/**
195211
* Get the raw IMAP search query
196212
*

0 commit comments

Comments
 (0)