forked from kuafuRace/phprap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkPager.php
More file actions
executable file
·88 lines (68 loc) · 2.86 KB
/
Copy pathLinkPager.php
File metadata and controls
executable file
·88 lines (68 loc) · 2.86 KB
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
<?php
namespace app\widgets;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
class LinkPager extends \yii\widgets\LinkPager
{
public $statisticPageLabel = '共 {totalPage}页 {totalRow} 条数据';
public $statisticPageClass = 'page-total';
public $hideOnSinglePage = false;
public function init() {
parent::init();
}
public function run()
{
if ($this->registerLinkTags) {
$this->registerLinkTags();
}
echo $this->renderPageButtons();
}
protected function renderPageButtons()
{
$pageCount = $this->pagination->getPageCount();
$totalCount = $this->pagination->totalCount;
if ($pageCount < 2 && $this->hideOnSinglePage) {
return '';
}
$buttons = [];
$currentPage = $this->pagination->getPage();
// statistic page
$statisticPageLabel = $this->statisticPageLabel;
if ($statisticPageLabel !== false) {
$statisticPageLabel = str_replace(['{totalPage}', '{totalRow}'], [$pageCount, $totalCount], $this->statisticPageLabel);
$buttons[] = $this->renderPageButton($statisticPageLabel, 0, $this->statisticPageClass, true, false);
}
// first page
$firstPageLabel = $this->firstPageLabel === true ? '1' : $this->firstPageLabel;
if ($firstPageLabel !== false) {
$buttons[] = $this->renderPageButton($firstPageLabel, 0, $this->firstPageCssClass, $currentPage <= 0, false);
}
// prev page
if ($this->prevPageLabel !== false) {
if (($page = $currentPage - 1) < 0) {
$page = 0;
}
$buttons[] = $this->renderPageButton($this->prevPageLabel, $page, $this->prevPageCssClass, $currentPage <= 0, false);
}
// internal pages
list($beginPage, $endPage) = $this->getPageRange();
for ($i = $beginPage; $i <= $endPage; ++$i) {
$buttons[] = $this->renderPageButton($i + 1, $i, null, $this->disableCurrentPageButton && $i == $currentPage, $i == $currentPage);
}
// next page
if ($this->nextPageLabel !== false) {
if (($page = $currentPage + 1) >= $pageCount - 1) {
$page = $pageCount - 1;
}
$buttons[] = $this->renderPageButton($this->nextPageLabel, $page, $this->nextPageCssClass, $currentPage >= $pageCount - 1, false);
}
// last page
$lastPageLabel = $this->lastPageLabel === true ? $pageCount : $this->lastPageLabel;
if ($lastPageLabel !== false) {
$buttons[] = $this->renderPageButton($lastPageLabel, $pageCount - 1, $this->lastPageCssClass, $currentPage >= $pageCount - 1, false);
}
$options = $this->options;
$tag = ArrayHelper::remove($options, 'tag', 'ul');
return Html::tag($tag, implode("\n", $buttons), $options);
}
}