| Conditions | 3 |
| Paths | 3 |
| Total Lines | 19 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | public function getPagination(string $page, int $totalPosts):array |
||
| 13 | { |
||
| 14 | if(!$this->startsWith($page, "page-")) |
||
| 15 | { |
||
| 16 | throw new \Exception("Pagination Error", "404"); |
||
| 17 | } |
||
| 18 | $pageNo = $this->removeFromBeginning($page, "page-"); |
||
| 19 | $offset = ($pageNo-1) * Constant::POSTS_PER_PAGE; |
||
| 20 | $totalPages = ceil($totalPosts / Constant::POSTS_PER_PAGE); |
||
| 21 | |||
| 22 | if($pageNo > $totalPages) |
||
| 23 | { |
||
| 24 | throw new \Error("Pagination Number not found", "404"); |
||
| 25 | } |
||
| 26 | |||
| 27 | return array( |
||
| 28 | "pageNo" => $pageNo, |
||
| 29 | "offset" => $offset, |
||
| 30 | "totalPages" => $totalPages |
||
| 31 | ); |
||
| 34 | } |