@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace Pager; |
3 | 3 | |
4 | -class Pagination{ |
|
4 | +class Pagination { |
|
5 | 5 | |
6 | 6 | public static $current; |
7 | 7 | protected static $page; |
@@ -17,29 +17,29 @@ discard block |
||
17 | 17 | * @param int $numpagesshown The number of pagination buttons to display |
18 | 18 | * @return string Returns the pagination menu |
19 | 19 | */ |
20 | - public static function paging($records, $pageURL, $start = 0, $additional = '', $maxshown = 50, $numpagesshown = 11){ |
|
21 | - if($records > $maxshown){ |
|
22 | - if($start >= 1){self::$current = $start;}else{self::$current = 1;} |
|
20 | + public static function paging($records, $pageURL, $start = 0, $additional = '', $maxshown = 50, $numpagesshown = 11) { |
|
21 | + if ($records > $maxshown) { |
|
22 | + if ($start >= 1) {self::$current = $start; }else {self::$current = 1; } |
|
23 | 23 | self::$lastpage = ceil($records / $maxshown); |
24 | 24 | |
25 | - if(!empty($additional)){$additional = 'search='.$additional.'&';} |
|
25 | + if (!empty($additional)) {$additional = 'search='.$additional.'&'; } |
|
26 | 26 | |
27 | 27 | self::getPage($records, $maxshown, $numpagesshown); |
28 | 28 | $paging = '<ul class="pagination">'; |
29 | - if(self::$current != 1){ |
|
30 | - if(self::$current != 2){$paging.= '<li><a href="'.$pageURL.'?'.$additional.'">«</a></li>';} |
|
31 | - $paging.= '<li><a href="'.$pageURL.'?'.$additional.'page='.($start - 1).'"><</a></li>'; |
|
29 | + if (self::$current != 1) { |
|
30 | + if (self::$current != 2) {$paging .= '<li><a href="'.$pageURL.'?'.$additional.'">«</a></li>'; } |
|
31 | + $paging .= '<li><a href="'.$pageURL.'?'.$additional.'page='.($start - 1).'"><</a></li>'; |
|
32 | 32 | } |
33 | - while(self::$page <= self::$lastpage){ |
|
34 | - if(self::$current == self::$page){$curselect = ' class="active"';}else{$curselect = '';} |
|
35 | - $paging.= '<li'.$curselect.'><a href="'.$pageURL.'?'.$additional.'page='.self::$page.'">'.self::$page.'</a></li>'; |
|
33 | + while (self::$page <= self::$lastpage) { |
|
34 | + if (self::$current == self::$page) {$curselect = ' class="active"'; }else {$curselect = ''; } |
|
35 | + $paging .= '<li'.$curselect.'><a href="'.$pageURL.'?'.$additional.'page='.self::$page.'">'.self::$page.'</a></li>'; |
|
36 | 36 | self::$page = (self::$page + 1); |
37 | 37 | } |
38 | - if(self::$current != self::$lastpage){ |
|
39 | - $paging.= '<li><a href="'.$pageURL.'?'.$additional.'page='.($start + 1).'">></a></li>'; |
|
40 | - if(self::$current != (self::$lastpage - 1)){$paging.= '<li><a href="'.$pageURL.'?'.$additional.'page='.ceil($records / $maxshown).'">»</a></li>';} |
|
38 | + if (self::$current != self::$lastpage) { |
|
39 | + $paging .= '<li><a href="'.$pageURL.'?'.$additional.'page='.($start + 1).'">></a></li>'; |
|
40 | + if (self::$current != (self::$lastpage - 1)) {$paging .= '<li><a href="'.$pageURL.'?'.$additional.'page='.ceil($records / $maxshown).'">»</a></li>'; } |
|
41 | 41 | } |
42 | - $paging.= '</ul>'; |
|
42 | + $paging .= '</ul>'; |
|
43 | 43 | return $paging; |
44 | 44 | } |
45 | 45 | return false; |
@@ -52,17 +52,17 @@ discard block |
||
52 | 52 | * @param int $numpages The number of pagination buttons to display |
53 | 53 | * return void Nothing is returned |
54 | 54 | */ |
55 | - protected static function getPage($records, $maxshown, $numpages){ |
|
55 | + protected static function getPage($records, $maxshown, $numpages) { |
|
56 | 56 | $show = floor($numpages / 2); |
57 | - if(self::$lastpage > $numpages){ |
|
58 | - if(self::$current > $show){self::$page = self::$current - $show;}else{self::$page = 1;} |
|
57 | + if (self::$lastpage > $numpages) { |
|
58 | + if (self::$current > $show) {self::$page = self::$current - $show; }else {self::$page = 1; } |
|
59 | 59 | |
60 | - if(self::$current < (self::$lastpage - $show)){ |
|
60 | + if (self::$current < (self::$lastpage - $show)) { |
|
61 | 61 | self::$lastpage = self::$current + $show; |
62 | - if(self::$current <= $show){self::$lastpage = self::$current + ($numpages - self::$current);} |
|
62 | + if (self::$current <= $show) {self::$lastpage = self::$current + ($numpages - self::$current); } |
|
63 | 63 | } |
64 | - else{self::$page = self::$current - ($numpages - ((ceil($records / $maxshown) - self::$current)) - 1);} |
|
64 | + else {self::$page = self::$current - ($numpages - ((ceil($records / $maxshown) - self::$current)) - 1); } |
|
65 | 65 | } |
66 | - else{self::$page = 1;} |
|
66 | + else {self::$page = 1; } |
|
67 | 67 | } |
68 | 68 | } |