-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeedsPaginator.php
42 lines (39 loc) · 1.2 KB
/
FeedsPaginator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* Arikaim
*
* @link http://www.arikaim.com
* @copyright Copyright (c) Konstantin Atanasov <[email protected]>
* @license http://www.arikaim.com/license
*
*/
namespace Arikaim\Core\Paginator;
use Arikaim\Core\Paginator\PaginatorInterface;
use Arikaim\Core\Paginator\Paginator;
/**
* Paginate feed collection with unknow last page.
*/
class FeedsPaginator extends Paginator implements PaginatorInterface
{
/**
* Constructor
*
* @param FeedCollection $source
* @param integer $page
* @param string|integer $perPage
*/
public function __construct($source, int $page = 1, int $perPage = Paginator::DEFAULT_PER_PAGE)
{
$this->currentPage = $page;
$this->perPage = $perPage;
$this->items = $source->fetch($page,$perPage)->getItems();
if (empty($source->getPageKey()) == true) {
$this->total = \count($this->items);
$this->items = $this->sliceItems($this->items);
$this->lastPage = $this->calcLastPage();
} else {
$this->lastPage = Self::UNKNOWN;
$this->total = Self::UNKNOWN;
}
}
}