pagination

This commit is contained in:
Билай Станислав 2024-07-31 14:26:26 +03:00
parent d6d703aaa6
commit 1714afcf3f
4 changed files with 40 additions and 7 deletions

18
composer.lock generated Normal file
View File

@ -0,0 +1,18 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "76e2cbfc39ced89c5f5aa46d0b1474c7",
"packages": [],
"packages-dev": [],
"aliases": [],
"minimum-stability": "dev",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.6.0"
}

View File

@ -8,6 +8,10 @@
},
"params": {"class": "table table-bordered", "border": "1"}
},
"paginationParams": {
"perPage": "5",
"currentPage": "1"
},
"data": [
{"email":"fas1@mail.ru","description":"sdgsdfg","description2":"ffdghdas"},
{"email":"fas2@mail.ru","description":"fafdgdfgsdfdfs","description2":"ffdghdas"},

View File

@ -191,6 +191,11 @@ class ListJsonTable
public function endTable(): void
{
$this->html .= "</table>";
// $pagination = new Pagination($this->data['meta']['total'], $this->data['meta']['perPage'], $this->data['meta']['currentPage'], $this->baseUrl);
$pagination = new Pagination(count($this->data['data']), $this->data['paginationParams'], $this->baseUrl);
var_dump(count($this->data['data']));
$pagination->create();
$this->html .= $pagination->fetch();
$hookAfter = $this->afterPrintHook;
$this->html .= $hookAfter($this->data['meta']);
}

View File

@ -14,17 +14,18 @@ class Pagination
private string $baseUrl;
public function __construct($countItem, $perPage, $currentPage, $baseUrl)
// public function __construct($countItem, $perPage, $currentPage, $baseUrl)
public function __construct(int $countItem, array $params, string $baseUrl)
{
$this->countItem = $countItem;
$this->perPage = $perPage;
$this->currentPage = $currentPage;
$this->perPage = $params['perPage'];
$this->currentPage = $params['currentPage'];
$this->baseUrl = $baseUrl;
$this->countPages = ceil($this->countItem / $perPage);
$this->countPages = ceil($this->countItem / $this->perPage);
}
public function create()
public function create(): void
{
$prev = $this->currentPage - 1 >= 1 ? $this->currentPage - 1 : null;
$next = $this->currentPage + 1 <= $this->countPages ? $this->currentPage + 1 : null;
@ -42,12 +43,17 @@ class Pagination
echo $this->html;
}
public function fetch()
public function fetch(): string
{
return $this->html;
}
private function getTemplate()
public function hookBefore(): void
{
}
private function getTemplate(): string
{
return '<nav aria-label="Page navigation example">
<ul class="pagination">