@@ -26,7 +26,7 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | public function __construct(int $page, int $limit, int $total, int $length = 3, bool $uiKeys = true) |
| 28 | 28 | { |
| 29 | - $this->totalPages = (int)ceil($total / $limit); |
|
| 29 | + $this->totalPages = (int) ceil($total / $limit); |
|
| 30 | 30 | $this->page = $page > 1 ? ($page > $this->totalPages ? 1 : $page) : 1; |
| 31 | 31 | $this->limit = $limit > 0 ? $limit : 10; |
| 32 | 32 | $this->total = $total; |
@@ -37,24 +37,24 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | private function init(): string |
| 39 | 39 | { |
| 40 | - $pos = 'full'; |
|
| 40 | + $pos = 'full'; |
|
| 41 | 41 | |
| 42 | - switch ($this->page) { |
|
| 43 | - case (($this->page - $this->length) < 3): |
|
| 44 | - $pos = 'noLeftDots'; |
|
| 45 | - break; |
|
| 46 | - case (($this->page - $this->length) >= 3 && ($this->totalPages - $this->page - $this->length) > 1): |
|
| 47 | - $pos = 'center'; |
|
| 48 | - break; |
|
| 49 | - case (abs($this->totalPages - $this->page - $this->length) >= 0): |
|
| 50 | - $pos = 'noRightDots'; |
|
| 51 | - break; |
|
| 52 | - case ($this->totalPages < 7): |
|
| 53 | - $pos = 'full'; |
|
| 54 | - break; |
|
| 55 | - } |
|
| 42 | + switch ($this->page) { |
|
| 43 | + case (($this->page - $this->length) < 3): |
|
| 44 | + $pos = 'noLeftDots'; |
|
| 45 | + break; |
|
| 46 | + case (($this->page - $this->length) >= 3 && ($this->totalPages - $this->page - $this->length) > 1): |
|
| 47 | + $pos = 'center'; |
|
| 48 | + break; |
|
| 49 | + case (abs($this->totalPages - $this->page - $this->length) >= 0): |
|
| 50 | + $pos = 'noRightDots'; |
|
| 51 | + break; |
|
| 52 | + case ($this->totalPages < 7): |
|
| 53 | + $pos = 'full'; |
|
| 54 | + break; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - return $pos; |
|
| 57 | + return $pos; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | if ($this->page > 3) { |
| 100 | - $result['second'] = 2; |
|
| 101 | - } |
|
| 100 | + $result['second'] = 2; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | return $this->uiKeys ? $result : []; |
| 104 | 104 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | if ($this->totalPages - $this->page + $this->length > 3) { |
| 123 | - $result['preLast'] = $this->totalPages - 1; |
|
| 123 | + $result['preLast'] = $this->totalPages - 1; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | return $this->uiKeys ? $result : []; |
@@ -134,21 +134,21 @@ discard block |
||
| 134 | 134 | $result = []; |
| 135 | 135 | $for = []; |
| 136 | 136 | |
| 137 | - if ($this->page - $this->length > 1) { |
|
| 138 | - $result[] = 1; |
|
| 139 | - } |
|
| 137 | + if ($this->page - $this->length > 1) { |
|
| 138 | + $result[] = 1; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | 141 | if ($this->pos !== 'noLeftDots') { |
| 142 | - if ($this->uiKeys) { |
|
| 143 | - $result['leftDots'] = '...'; |
|
| 144 | - } else { |
|
| 145 | - $result[] = '...'; |
|
| 146 | - } |
|
| 142 | + if ($this->uiKeys) { |
|
| 143 | + $result['leftDots'] = '...'; |
|
| 144 | + } else { |
|
| 145 | + $result[] = '...'; |
|
| 146 | + } |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - foreach (range($this->page - 1, $this->page - $this->length) as $value) { |
|
| 149 | + foreach (range($this->page - 1, $this->page - $this->length) as $value) { |
|
| 150 | 150 | if ($value > 0) { |
| 151 | - $for[] = $value; |
|
| 151 | + $for[] = $value; |
|
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | |
@@ -162,22 +162,22 @@ discard block |
||
| 162 | 162 | { |
| 163 | 163 | $result = []; |
| 164 | 164 | |
| 165 | - foreach (range($this->page + 1, $this->page + $this->length) as $value) { |
|
| 166 | - if ($value <= $this->totalPages) { |
|
| 167 | - $result[] = $value; |
|
| 168 | - } |
|
| 169 | - } |
|
| 165 | + foreach (range($this->page + 1, $this->page + $this->length) as $value) { |
|
| 166 | + if ($value <= $this->totalPages) { |
|
| 167 | + $result[] = $value; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | 171 | if ($this->pos !== 'noRightDots') { |
| 172 | - if ($this->uiKeys) { |
|
| 173 | - $result['rightDots'] = '...'; |
|
| 174 | - } else { |
|
| 175 | - $result[] = '...'; |
|
| 176 | - } |
|
| 172 | + if ($this->uiKeys) { |
|
| 173 | + $result['rightDots'] = '...'; |
|
| 174 | + } else { |
|
| 175 | + $result[] = '...'; |
|
| 176 | + } |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | if ($this->totalPages - $this->page - $this->length > 0) { |
| 180 | - $result[] = $this->totalPages; |
|
| 180 | + $result[] = $this->totalPages; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | return $result; |
@@ -185,13 +185,13 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | private function getCurrent(): array |
| 187 | 187 | { |
| 188 | - if ($this->uiKeys) { |
|
| 189 | - $result['current'] = $this->page; |
|
| 190 | - } else { |
|
| 191 | - $result[] = $this->page; |
|
| 192 | - } |
|
| 188 | + if ($this->uiKeys) { |
|
| 189 | + $result['current'] = $this->page; |
|
| 190 | + } else { |
|
| 191 | + $result[] = $this->page; |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - return $result; |
|
| 194 | + return $result; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |