1 | <?php |
||
8 | namespace Pager; |
||
9 | |||
10 | class Pagination{ |
||
11 | |||
12 | public static $current; |
||
13 | protected static $page; |
||
14 | protected static $lastpage; |
||
15 | |||
16 | /** |
||
17 | * Returns paging buttons for the number of records |
||
18 | * @param int $records The total number of records |
||
19 | * @param string $pageURL The URL of the page you are creating the paging for |
||
20 | * @param int $start The start number for the results |
||
21 | * @param string $additional Any additional get values to include in the URL |
||
22 | * @param int $maxshown The number of records that are shown on each page |
||
23 | * @param int $numpagesshown The number of pagination buttons to display |
||
24 | * @return string Returns the pagination menu |
||
25 | */ |
||
26 | public static function paging($records, $pageURL, $start = 0, $additional = '', $maxshown = 50, $numpagesshown = 11){ |
||
53 | |||
54 | /** |
||
55 | * Gets the current page |
||
56 | * @param int $records The total number of records |
||
57 | * @param int $maxshown The number of records that are shown on each page |
||
58 | * @param int $numpages The number of pagination buttons to display |
||
59 | * return void Nothing is returned |
||
60 | */ |
||
61 | protected static function getPage($records, $maxshown, $numpages){ |
||
62 | $show = floor($numpages / 2); |
||
63 | if(self::$lastpage > $numpages){ |
||
64 | if(self::$current > $show){self::$page = self::$current - $show;}else{self::$page = 1;} |
||
65 | |||
66 | if(self::$current < (self::$lastpage - $show)){ |
||
67 | self::$lastpage = self::$current + $show; |
||
68 | if(self::$current <= $show){self::$lastpage = self::$current + ($numpages - self::$current);} |
||
69 | } |
||
70 | else{self::$page = self::$current - ($numpages - ((ceil($records / $maxshown) - self::$current)) - 1);} |
||
71 | } |
||
72 | else{self::$page = 1;} |
||
73 | } |
||
75 |