-
Notifications
You must be signed in to change notification settings - Fork 2
/
ReverseLinkPager.php
95 lines (77 loc) · 2.36 KB
/
ReverseLinkPager.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace loveorigami\pagination;
use yii\widgets\LinkPager;
use yii\helpers\Html;
/**
* Created by PhpStorm.
* User: loveorigami
* Date: 07.11.2014
* Time: 9:53
*/
class ReverseLinkPager extends LinkPager
{
public $nextPageLabel = '«';
public $prevPageLabel = '»';
protected function renderPageButtons()
{
if (($pageCount = $this->pagination->getPageCount()) <= 1)
return '';
list($beginPage, $endPage) = $this->getPageRange();
// currentPage is calculated in getPageRange()
$currentPage = $this->pagination->getPage(false);
$buttons = array();
// first page
if ($this->firstPageLabel !== false) {
$buttons[] = $this->renderPageButton(
$this->firstPageLabel,
$pageCount - 1,
$this->firstPageCssClass,
$currentPage >= $pageCount - 1,
false
);
}
// next page
if (($page = $currentPage + 1) >= $pageCount - 1)
$page = $pageCount - 1;
$buttons[] = $this->renderPageButton(
$this->nextPageLabel,
$page,
$this->nextPageCssClass,
$currentPage >= $pageCount - 1, false
);
// internal pages
for ($i = $endPage; $i >= $beginPage; --$i) {
$buttons[] = $this->renderPageButton(
$i + 1,
$i,
null,
false,
$i == $currentPage
);
}
// prev page
if (($page = $currentPage - 1) < 0)
$page = 0;
$buttons[] = $this->renderPageButton(
$this->prevPageLabel,
$page,
$this->prevPageCssClass,
$currentPage <= 0,
false
);
// last page
if ($this->lastPageLabel !== false) {
$buttons[] = $this->renderPageButton(
$this->lastPageLabel,
0,
$this->lastPageCssClass,
$currentPage <= 0,
false
);
}
return Html::tag('ul', implode("\n", $buttons), $this->options);
}
/**
* @return array the begin and end pages that need to be displayed.
*/
}