pagination fix

This commit is contained in:
2024-07-31 15:49:40 +03:00
parent 647fe34d11
commit f5f6504545
3 changed files with 33 additions and 12 deletions

View File

@ -3,6 +3,9 @@
namespace Itguild\Tables;
use Exception;
use http\Message;
class Pagination
{
@ -14,13 +17,21 @@ class Pagination
private string $baseUrl;
public function __construct($countItem, $perPage, $currentPage, $baseUrl)
// public function __construct(int $countItem, array $params, string $baseUrl)
// public function __construct($countItem, $perPage, $currentPage, $baseUrl)
/**
* @throws Exception
*/
public function __construct(array $options,)
{
$this->countItem = $countItem;
$this->perPage = $perPage;
$this->currentPage = $currentPage;
$this->baseUrl = $baseUrl;
if (!$options['countItem']) {
throw new Exception(message: "countItem is not valid");
}
$this->countItem = $options['countItem'];
$this->perPage = $options['perPage'] ?? 10;
$this->currentPage = $options['currentPage'] ?? 1;
$this->baseUrl = $options['baseUrl'];
$this->baseUrl .= $options['prefix'] ?? '/page';
$this->countPages = ceil($this->countItem / $this->perPage);
}