Skip to content

Commit 47dca77

Browse files
committed
Messagecollection class created
1 parent fd55c1f commit 47dca77

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

src/IMAP/MessageCollection.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/*
3+
* File: ClientManager.php
4+
* Category: Collection
5+
* Author: M. Goldenbaum
6+
* Created: 16.03.18 03:13
7+
* Updated: -
8+
*
9+
* Description:
10+
* -
11+
*/
12+
13+
namespace Webklex\IMAP;
14+
15+
use Illuminate\Pagination\LengthAwarePaginator;
16+
use Illuminate\Support\Collection;
17+
use Illuminate\Pagination\Paginator;
18+
19+
/**
20+
* Class MessageCollection
21+
*
22+
* @package Webklex\IMAP
23+
*/
24+
class MessageCollection extends Collection {
25+
26+
/**
27+
* Paginate the current collection.
28+
*
29+
* @param int $perPage
30+
* @param null $page
31+
* @param string $pageName
32+
*
33+
* @return LengthAwarePaginator
34+
*/
35+
public function paginate($perPage = 15, $page = null, $pageName = 'page') {
36+
$page = $page ?: Paginator::resolveCurrentPage($pageName);
37+
38+
$results = ($total = $this->count()) ? $this->forPage($page, $perPage) : $this->all();
39+
40+
return $this->paginator($results, $total, $perPage, $page, [
41+
'path' => Paginator::resolveCurrentPath(),
42+
'pageName' => $pageName,
43+
]);
44+
}
45+
46+
/**
47+
* Create a new length-aware paginator instance.
48+
*
49+
* @param array $items
50+
* @param int $total
51+
* @param int $perPage
52+
* @param int $currentPage
53+
* @param array $options
54+
*
55+
* @return LengthAwarePaginator
56+
*/
57+
protected function paginator($items, $total, $perPage, $currentPage, array $options) {
58+
return new LengthAwarePaginator($items, $total, $perPage, $currentPage, $options);
59+
}
60+
}

0 commit comments

Comments
 (0)