forked from nlmayday/PhpLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Page.php
60 lines (53 loc) · 2.43 KB
/
Page.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
<?php
class Page
{
public static function pagination($currentPageNum, $totalCount, $pageUrl = '', $pageSize = 24, $skipCount = 5, $currentStyleName = 'current', $currentUseLink = false, $preText = 'Prev', $nextText = 'Next', $firstText = 'First', $lastText = 'Last')
{
$returnValue = '';
$begin = 1;
$end = 1;
$totalpage = floor($totalCount / $pageSize);
if ($totalCount % $pageSize > 0) {
$totalpage ++;
}
$begin = $currentPageNum - $skipCount;
$end = $currentPageNum + $skipCount;
if ($begin <= 0) {
$end = $end - $begin + 1;
$begin = 1;
}
if ($end > $totalpage) {
$end = $totalpage;
}
for ($count = $begin; $count <= $end; $count ++) {
if ($count == $currentPageNum) {
if ($currentUseLink) {
$returnValue .= '<li class="' . $currentStyleName . '"><a href="' . $pageUrl . $count . '"><span>' . $count . '</span></a></li>';
} else {
$returnValue .= '<li class="' . $currentStyleName . '"><span>' . $count . '</span></li>';
}
} else {
$returnValue .= '<li><a href="' . $pageUrl . $count . '"><span>' . $count . '</span></a></li>';
}
}
if ($currentPageNum - $skipCount > 1) {
$returnValue = '<li class="ellipsis">...</li>' . $returnValue;
}
if ($currentPageNum + $skipCount < $totalpage) {
$returnValue = $returnValue . '<li class="ellipsis">...</li>';
}
if ($currentPageNum > 1) {
$returnValue = '<li><a href="' . $pageUrl . ($currentPageNum - 1) . '"><span>' . $preText . '</span></a></li>' . $returnValue;
}
if ($currentPageNum < $totalpage) {
$returnValue = $returnValue . '<li><a href="' . $pageUrl . ($currentPageNum + 1) . '"><span>' . $nextText . '</span></a></li>';
}
if (! empty($firstText) && $currentPageNum > 1) {
$returnValue = '<li><a href="' . $pageUrl . '1"><span>' . $firstText . '</span></a></li>' . $returnValue;
}
if (! empty($lastText) && $currentPageNum < $totalpage) {
$returnValue = $returnValue . '<li><a href="' . $pageUrl . $totalpage . '"><span>' . $lastText . '</span></a></li>';
}
return $returnValue;
}
}