|
1
|
|
|
<?php |
|
2
|
|
|
namespace Pager; |
|
3
|
|
|
|
|
4
|
|
|
class Pagination { |
|
5
|
|
|
public static $current; |
|
6
|
|
|
protected $queryString; |
|
7
|
|
|
|
|
8
|
|
|
protected static $page; |
|
9
|
|
|
protected static $pageURL; |
|
10
|
|
|
protected static $lastpage; |
|
11
|
|
|
|
|
12
|
|
|
public $pagerClass = 'pagination'; |
|
13
|
|
|
public $liActiveClass = 'active'; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Sets the class assigned to the UL element of the pagination object |
|
17
|
|
|
* @param string $class This should be the class or classes that you wish to give to the pagination object |
|
18
|
|
|
* @return $this |
|
19
|
|
|
*/ |
|
20
|
1 |
|
public function setPaginationClass($class){ |
|
21
|
1 |
|
if((!empty(trim($class)))){ |
|
22
|
1 |
|
$this->pagerClass = $class; |
|
23
|
|
|
} |
|
24
|
1 |
|
return $this; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Returns the class to give to the pagination object |
|
29
|
|
|
* @return type |
|
|
|
|
|
|
30
|
|
|
*/ |
|
31
|
1 |
|
public function getPaginationClass(){ |
|
32
|
1 |
|
return $this->pagerClass; |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Sets the active class to assign on the li elements |
|
37
|
|
|
* @param string $class This should be the class to assign on active elements |
|
38
|
|
|
* @return $this |
|
39
|
|
|
*/ |
|
40
|
1 |
|
public function setActiveClass($class){ |
|
41
|
1 |
|
if((!empty(trim($class)))){ |
|
42
|
1 |
|
$this->liActiveClass = $class; |
|
43
|
|
|
} |
|
44
|
1 |
|
return $this; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Returns the class to assign to active li elements |
|
49
|
|
|
* @return string $class This should be the class to assign on active elements |
|
50
|
|
|
*/ |
|
51
|
1 |
|
public function getActiveClass(){ |
|
52
|
1 |
|
return $this->liActiveClass; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Returns paging buttons for the number of records |
|
57
|
|
|
* @param int $records The total number of records |
|
58
|
|
|
* @param string $pageURL The URL of the page you are creating the paging for |
|
59
|
|
|
* @param int $start The start number for the results |
|
60
|
|
|
* @param int $maxshown The number of records that are shown on each page |
|
61
|
|
|
* @param int $numpagesshown The number of pagination buttons to display |
|
62
|
|
|
* @param boolean $arrows If you want arrows to display before and after for next and previous set to true (default) else set to false |
|
63
|
|
|
* @param array $additional Any additional get values to include in the URL |
|
64
|
|
|
* @return string Returns the pagination menu |
|
65
|
|
|
*/ |
|
66
|
1 |
|
public function paging($records, $pageURL, $start = 0, $maxshown = 50, $numpagesshown = 11, $arrows = true, $additional = array()) { |
|
67
|
1 |
|
self::$pageURL = $pageURL; |
|
68
|
1 |
|
$this->queryString = $additional; |
|
69
|
1 |
|
if ($records > $maxshown) { |
|
70
|
|
|
self::$current = $start >= 1 ? intval($start) : 1; |
|
71
|
|
|
self::$lastpage = ceil($records / $maxshown); |
|
72
|
|
|
$this->getPage($records, $maxshown, $numpagesshown); |
|
73
|
|
|
|
|
74
|
|
|
$paging = '<ul class="'.self::getPaginationClass().'">'.$this->preLinks($arrows); |
|
|
|
|
|
|
75
|
|
|
while (self::$page <= self::$lastpage) { |
|
76
|
|
|
$paging .= $this->buildLink(self::$page, self::$page, (self::$current == self::$page)); |
|
77
|
|
|
self::$page = (self::$page + 1); |
|
78
|
|
|
} |
|
79
|
|
|
return $paging.$this->postLinks($arrows).'</ul>'; |
|
80
|
|
|
} |
|
81
|
1 |
|
return false; |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Build a link item with the given values |
|
86
|
|
|
* @param string $link This should be any additional items to be included as part of the link |
|
87
|
|
|
* @param mixed $page This should be the link test on the link normally set as numbers but may be anything like arrows or dots etc |
|
88
|
|
|
* @param boolean $current If this is the current link item set this as true so the class is added to the link item |
|
89
|
|
|
* @return string This will return the paging item as a string |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function buildLink($link, $page, $current = false) { |
|
92
|
|
|
return '<li'.(($current === true && !empty(self::getActiveClass())) ? ' class="'.self::getActiveClass().'"' : '').'><a href="'.self::$pageURL.'?'.$this->buildQueryString($link).'" title="Page '.$page.'">'.$page.'</a></li>'; |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Builds the query string to add to the URL |
|
97
|
|
|
* @param mixed $page If the page variable is set to a number will add the page number to the query string else will not add any additional items |
|
98
|
|
|
* @return string The complete string will be returned to add to the link item |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function buildQueryString($page) { |
|
101
|
|
|
if (is_numeric($page)) { |
|
102
|
|
|
$this->queryString['page'] = $page; |
|
103
|
|
|
} |
|
104
|
|
|
return http_build_query(array_filter($this->queryString), '', '&'); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Gets the current page |
|
109
|
|
|
* @param int $records The total number of records |
|
110
|
|
|
* @param int $maxshown The number of records that are shown on each page |
|
111
|
|
|
* @param int $numpages The number of pagination buttons to display |
|
112
|
|
|
* return void Nothing is returned |
|
113
|
|
|
*/ |
|
114
|
|
|
protected function getPage($records, $maxshown, $numpages) { |
|
115
|
|
|
$show = floor($numpages / 2); |
|
116
|
|
|
if (self::$lastpage > $numpages) { |
|
117
|
|
|
self::$page = (self::$current > $show ? (self::$current - $show) : 1); |
|
118
|
|
|
if (self::$current < (self::$lastpage - $show)) { |
|
119
|
|
|
self::$lastpage = ((self::$current <= $show) ? (self::$current + ($numpages - self::$current)) : (self::$current + $show)); |
|
120
|
|
|
} |
|
121
|
|
|
else { self::$page = self::$current - ($numpages - ((ceil($records / $maxshown) - self::$current)) - 1); } |
|
122
|
|
|
} |
|
123
|
|
|
else { self::$page = 1; } |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Returns the previous arrows as long as arrows is set to true and the page is not the first page |
|
128
|
|
|
* @param boolean $arrows If you want to display previous arrows set to true else set to false |
|
129
|
|
|
* @return string Any previous link arrows will be returned as a string |
|
130
|
|
|
*/ |
|
131
|
|
|
protected function preLinks($arrows = true) { |
|
132
|
|
|
$paging = ''; |
|
133
|
|
|
if (self::$current != 1 && $arrows) { |
|
134
|
|
|
if (self::$current != 2) { $paging .= $this->buildLink('', '«'); } |
|
135
|
|
|
$paging .= $this->buildLink((self::$current - 1), '<'); |
|
136
|
|
|
} |
|
137
|
|
|
return $paging; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Returns the next arrows as long as arrows is set to true and the page is not the last page |
|
142
|
|
|
* @param boolean $arrows If you want to display next arrows set to true else set to false |
|
143
|
|
|
* @return string Any next link arrows will be returned as a string |
|
144
|
|
|
*/ |
|
145
|
|
|
protected function postLinks($arrows = true) { |
|
146
|
|
|
$paging = ''; |
|
147
|
|
|
if (self::$current != self::$lastpage && $arrows) { |
|
148
|
|
|
$paging .= $this->buildLink((self::$current + 1), '>'); |
|
149
|
|
|
if (self::$current != (self::$lastpage - 1)) { $paging .= $this->buildLink(self::$lastpage, '»'); } |
|
150
|
|
|
} |
|
151
|
|
|
return $paging; |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths