Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
9e7c83b680 | |||
b374744261 | |||
c6918c85b3 | |||
d98ddded07 | |||
1bd82eb40b | |||
4a12eeccfd | |||
71b2fdfb6b | |||
f53346610e | |||
67a3f5770e | |||
6d5f6a8665 | |||
2c1db8573c | |||
8d1dce0222 | |||
433cc85f54 | |||
39931b257b | |||
b7fe32b91d | |||
320e1070ba | |||
8bc8a75a53 | |||
f5f6504545 |
@ -2,26 +2,35 @@
|
||||
"meta": {
|
||||
"title": "forma 1",
|
||||
"columns": {
|
||||
"id": "ID",
|
||||
"email": "Email",
|
||||
"description": "Описание 1",
|
||||
"description2": "Описание 2"
|
||||
"description2": "Описание 2",
|
||||
"status": "Статус"
|
||||
},
|
||||
"actions": ["view"],
|
||||
"pagination": true,
|
||||
"perPage": "5",
|
||||
"currentPage": "1",
|
||||
"showActionColumn": true,
|
||||
"filter": true,
|
||||
"total": 10,
|
||||
"paginationPrefix": "/page",
|
||||
"params": {"class": "table table-bordered", "border": "1"}
|
||||
},
|
||||
"filters": [
|
||||
"email", "description"
|
||||
],
|
||||
"data": [
|
||||
{"email":"fas1@mail.ru","description":"sdgsdfg","description2":"ffdghdas"},
|
||||
{"email":"fas2@mail.ru","description":"fafdgdfgsdfdfs","description2":"ffdghdas"},
|
||||
{"email":"fas3@mail.ru","description":"fafdgdssdfgdfs","description2":"ffdghdas"},
|
||||
{"email":"fas4@mail.ru","description":"fafddsfgsdvcbgdfs","description2":"ffdghdas"},
|
||||
{"email":"fas5@mail.ru","description":"fafdgghjgfdfs","description2":"ffdghdas"},
|
||||
{"email":"fas6@mail.ru","description":"fafddfgdhvgdfs","description2":"ffdghdas"},
|
||||
{"email":"fas7@mail.ru","description":"fafdfgnfdgdfs","description2":"ffdghdas"},
|
||||
{"email":"fas8@mail.ru","description":"fafdfghdfgdfs","description2":"ffdghdas"},
|
||||
{"email":"dfdfd@mail.ru","description":"sdffhdfhggsdfg","description2":"ffdgdfgsdfghdas"},
|
||||
{"email":"dfsdfsddfd@mail.ru","description":"sdffhdfsdfshggsdfg","description2":"ffdgdsdffgsdfghdas"}
|
||||
{"id": 1,"email":"fas1@mail.ru","description":"sdgsdfg","description2":"ffdghdas", "status": 1},
|
||||
{"id": 2,"email":"fas2@mail.ru","description":"fafdgdfgsdfdfs","description2":"ffdghdas", "status": 1},
|
||||
{"id": 3,"email":"fas3@mail.ru","description":"fafdgdssdfgdfs","description2":"ffdghdas", "status": 2},
|
||||
{"id": 4,"email":"fas4@mail.ru","description":"fafddsfgsdvcbgdfs","description2":"ffdghdas", "status": 1},
|
||||
{"id": 5,"email":"fas5@mail.ru","description":"fafdgghjgfdfs","description2":"ffdghdas", "status": 1},
|
||||
{"id": 6,"email":"fas6@mail.ru","description":"fafddfgdhvgdfs","description2":"ffdghdas", "status": 1},
|
||||
{"id": 7,"email":"fas7@mail.ru","description":"fafdfgnfdgdfs","description2":"ffdghdas", "status": 0},
|
||||
{"id": 8,"email":"fas8@mail.ru","description":"fafdfghdfgdfs","description2":"ffdghdas", "status": 1},
|
||||
{"id": 12,"email":"dfdfd@mail.ru","description":"sdffhdfhggsdfg","description2":"ffdgdfgsdfghdas", "status": 99},
|
||||
{"id": 13,"email":"dfsdfsddfd@mail.ru","description":"sdffhdfsdfshggsdfg","description2":"ffdgdsdffgsdfghdas", "status": 1}
|
||||
]
|
||||
}
|
@ -6,11 +6,41 @@ use Itguild\Tables\ListJsonTable;
|
||||
|
||||
$json = file_get_contents('simple.json');
|
||||
$table = new ListJsonTable($json);
|
||||
$table->setBeforePrintCell(function ($key, $data) {
|
||||
return $key == "email" ? "<span style='color: aqua'>$data</span>" : $data;
|
||||
});
|
||||
|
||||
//$table->columns([
|
||||
$table->columns([
|
||||
'status' => function ($cell) {
|
||||
return getStatusLabel()[$cell];
|
||||
},
|
||||
'email' => function ($cell) {
|
||||
return "<span style='color: aqua'>$cell</span>";
|
||||
},
|
||||
'description' => function ($cell) {
|
||||
return "<span style='color: sienna'>$cell</span>";
|
||||
}
|
||||
]);
|
||||
//$table->setBeforePrintCell(function ($key, $data) {
|
||||
// return $key == "email" ? "<span style='color: aqua'>$data</span>" : $data;
|
||||
//});
|
||||
$table->afterPrint(function ($meta) {
|
||||
return "<div>After Print</div>";
|
||||
});
|
||||
$table->addColumn("Колонка 33", "k33", function ($id) {
|
||||
return "my ID: " . $id;
|
||||
});
|
||||
$table->addColumn("Колонка 34", "k34", function ($id) {
|
||||
return "some34";
|
||||
});
|
||||
$table->create();
|
||||
$table->render();
|
||||
|
||||
|
||||
function getStatusLabel(): array
|
||||
{
|
||||
return [
|
||||
0 => "На модерации",
|
||||
1 => "Активный",
|
||||
2 => "Модератор",
|
||||
99 => "Удален",
|
||||
];
|
||||
}
|
@ -7,5 +7,14 @@ use Itguild\Tables\ViewJsonTable;
|
||||
$json = file_get_contents('view.json');
|
||||
|
||||
$table = new ViewJsonTable($json);
|
||||
//$table->rows([
|
||||
$table->rows([
|
||||
'username' => function ($cell) {
|
||||
return "<span style='color: aqua'>$cell</span>";
|
||||
},
|
||||
'email' => function ($cell) {
|
||||
return "<span style='color: firebrick'>$cell</span>";
|
||||
}
|
||||
]);
|
||||
$table->create();
|
||||
$table->render();
|
48
src/Filter.php
Normal file
48
src/Filter.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Itguild\Tables;
|
||||
|
||||
class Filter
|
||||
{
|
||||
// private array $columnsForFilter;
|
||||
private string $column;
|
||||
private string $html = "";
|
||||
private string $baseUrl;
|
||||
|
||||
public function __construct(array $columns, string $baseUrl)
|
||||
{
|
||||
$this->columnsForFilter = $columns;
|
||||
$this->baseUrl = $baseUrl;
|
||||
}
|
||||
|
||||
public function create(): void
|
||||
{
|
||||
$this->html = str_replace('{action_link}', $this->baseUrl, $this->getTemplate());
|
||||
$this->html = str_replace('{column}', 'id', $this->html);
|
||||
}
|
||||
|
||||
public function render(): void
|
||||
{
|
||||
echo $this->html;
|
||||
}
|
||||
|
||||
public function fetch(): string
|
||||
{
|
||||
return $this->html;
|
||||
}
|
||||
|
||||
public function getColumnsForFilter(): array
|
||||
{
|
||||
return $this->columnsForFilter;
|
||||
}
|
||||
|
||||
public function getTemplate(): string
|
||||
{
|
||||
return '<nav aria-label="Filters example">
|
||||
<form action="{action_link}">
|
||||
<input type="text" name="{column}">
|
||||
|
||||
|
||||
</nav>';
|
||||
}
|
||||
}
|
49
src/JasonTable.php
Normal file
49
src/JasonTable.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Itguild\Tables;
|
||||
|
||||
class JasonTable
|
||||
{
|
||||
protected string $html = "";
|
||||
protected \Closure|array|false $beforePrintCell;
|
||||
protected \Closure|false $afterPrintHook;
|
||||
protected \Closure|false $beforePrintHook;
|
||||
|
||||
|
||||
public function render(): void
|
||||
{
|
||||
echo $this->html;
|
||||
}
|
||||
|
||||
public function setBeforePrintCell(\Closure $closure): void
|
||||
{
|
||||
$this->beforePrintCell = $closure;
|
||||
}
|
||||
|
||||
public function getCustomCell(string $key, string|null $cell)
|
||||
{
|
||||
if (is_array($this->beforePrintCell)) {
|
||||
foreach ($this->beforePrintCell as $currentKey => $closure) {
|
||||
if ($key == $currentKey) {
|
||||
$hook = $closure;
|
||||
$cell = $hook($cell);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$hook = $this->beforePrintCell;
|
||||
$cell = $hook($key, $cell);
|
||||
}
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
public function afterPrint(\Closure $closure): void
|
||||
{
|
||||
$this->afterPrintHook = $closure;
|
||||
}
|
||||
|
||||
public function beforePrint(\Closure $closure): void
|
||||
{
|
||||
$this->beforePrintHook = $closure;
|
||||
}
|
||||
}
|
@ -2,39 +2,40 @@
|
||||
|
||||
namespace Itguild\Tables;
|
||||
|
||||
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||
use Exception;
|
||||
use Itguild\Tables\ActionColumn\DeleteActionColumn;
|
||||
use Itguild\Tables\ActionColumn\EditActionColumn;
|
||||
use Itguild\Tables\ActionColumn\ViewActionColumn;
|
||||
use Itguild\Tables\traits\CreateParams;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
|
||||
class ListJsonTable
|
||||
class ListJsonTable extends JasonTable
|
||||
{
|
||||
use CreateParams;
|
||||
|
||||
private string $html = '';
|
||||
private string $json;
|
||||
|
||||
private int $count = 0;
|
||||
private \Closure|false $beforePrintCell;
|
||||
private \Closure|false $beforePrintHook;
|
||||
private \Closure|false $afterPrintHook;
|
||||
private string $baseUrl;
|
||||
private array $data;
|
||||
|
||||
private bool $pagination = true;
|
||||
private bool $showActionColumn = true;
|
||||
private bool|array $filters = false;
|
||||
|
||||
private array $actionsArray = [];
|
||||
private array $customActionsArray = [];
|
||||
private array $customColumnsArray = [];
|
||||
|
||||
#[NoReturn] public function __construct(string $json)
|
||||
{
|
||||
$this->beforePrintCell = false;
|
||||
$this->beforePrintCell = [];
|
||||
$this->json = $json;
|
||||
$this->data = json_decode($this->json, true);
|
||||
$this->baseUrl = $this->data['meta']['baseUrl'] ?? '';
|
||||
$this->pagination = $this->data['meta']['pagination'] ?? true;
|
||||
$this->showActionColumn = $this->data['meta']['showActionColumn'] ?? true;
|
||||
$this->filters = $this->data['filters'] ?? false;
|
||||
$this->beforePrintHook = function () {
|
||||
};
|
||||
$this->afterPrintHook = function () {
|
||||
@ -49,70 +50,73 @@ class ListJsonTable
|
||||
$this->html .= "<table $paramsStr>";
|
||||
}
|
||||
|
||||
public function beforePrint(\Closure $closure): void
|
||||
{
|
||||
$this->beforePrintHook = $closure;
|
||||
}
|
||||
|
||||
public function afterPrint(\Closure $closure): void
|
||||
{
|
||||
$this->afterPrintHook = $closure;
|
||||
}
|
||||
|
||||
public function createThead(): void
|
||||
{
|
||||
$columnKeys = [];
|
||||
if (!isset($this->data['meta']['columns'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->html .= "<thead><tr>";
|
||||
if (!$this->issetColumn("id")) {
|
||||
$this->html .= "<th>" . "ID" . "</th>";
|
||||
foreach ($this->data['meta']['columns'] as $key => $column) {
|
||||
if ($this->is_fillable($key)) {
|
||||
$this->html .= "<th>" . $column . "</th>";
|
||||
}
|
||||
$columnKeys[] = "id";
|
||||
}
|
||||
$columnKeys = $this->getColumnKeys($columnKeys);
|
||||
$columnKeys = array_merge($columnKeys, $this->getCustomColumnKeys());
|
||||
$this->getCustomHeadColumn();
|
||||
if ($this->showActionColumn) {
|
||||
$this->html .= "<th>Действия</th></th></tr></thead>";
|
||||
}
|
||||
if ($this->filters) {
|
||||
$this->getFilters($columnKeys);
|
||||
}
|
||||
}
|
||||
|
||||
public function createTbody(): void
|
||||
{
|
||||
if ($this->data['data']) {
|
||||
|
||||
$this->count = $this->data["meta"]["perPage"] * ($this->data['meta']["currentPage"] - 1);
|
||||
foreach ($this->data['data'] as $col) {
|
||||
foreach ($this->data['data'] as $row) {
|
||||
$this->html .= "<tr>";
|
||||
$this->count += 1;
|
||||
$id = $col["id"] ?? $this->count;
|
||||
$id = $row["id"] ?? $this->count;
|
||||
if (!$this->issetColumn("id")) {
|
||||
$this->html .= '<td><a href=' . $this->baseUrl . "/" . $id . '>' . $id . '</a></td>';
|
||||
foreach ($col as $key => $row) {
|
||||
}
|
||||
foreach ($row as $key => $cell) {
|
||||
if ($this->issetColumn($key) and $this->is_fillable($key)) {
|
||||
if($this->beforePrintCell) {
|
||||
$hook = $this->beforePrintCell;
|
||||
$row = $hook($key, $row);
|
||||
$cell = $this->getCustomCell($key, $cell);
|
||||
}
|
||||
|
||||
$this->html .= "<td>" . $row . "</td>";
|
||||
$this->html .= "<td>" . $cell . "</td>";
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($col["id"])){
|
||||
$actions = $this->getActions($col["id"]);
|
||||
$this->getCustomColumns($row["id"] ?? null);
|
||||
if ($this->showActionColumn) {
|
||||
if (isset($row["id"])) {
|
||||
$actions = $this->getActions($row["id"]);
|
||||
|
||||
$this->html .= "<td>$actions</td></tr>";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->html .= "<td></td></tr>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function addAction(string $actionColumn): void
|
||||
{
|
||||
$this->customActionsArray[] = $actionColumn;
|
||||
}
|
||||
|
||||
public function addColumn(string $label, string $key, \Closure $closure): void
|
||||
{
|
||||
$this->customColumnsArray[] = ['label' => $label, "key" => $key, "handler" => $closure];
|
||||
}
|
||||
|
||||
|
||||
private function setActions(): void
|
||||
{
|
||||
if (isset($this->data['meta']['actions'])) {
|
||||
@ -133,6 +137,41 @@ class ListJsonTable
|
||||
$this->actionsArray = array_merge($this->actionsArray, $this->customActionsArray);
|
||||
}
|
||||
|
||||
public function getCustomColumns($id = null): void
|
||||
{
|
||||
foreach ($this->customColumnsArray as $item) {
|
||||
$this->html .= "<td>" . $item['handler']($id) . "</td>";
|
||||
}
|
||||
}
|
||||
|
||||
public function getCustomHeadColumn(): void
|
||||
{
|
||||
foreach ($this->customColumnsArray as $item) {
|
||||
$this->html .= "<th>" . $item['label'] . "</th>";
|
||||
}
|
||||
}
|
||||
|
||||
protected function getCustomColumnKeys(): array
|
||||
{
|
||||
$keys = [];
|
||||
foreach ($this->customColumnsArray as $item) {
|
||||
$keys[] = $item['key'];
|
||||
}
|
||||
|
||||
return $keys;
|
||||
}
|
||||
|
||||
private function getColumnKeys(array $columnKeys): array
|
||||
{
|
||||
foreach ($this->data['meta']['columns'] as $key => $column) {
|
||||
if ($this->is_fillable($key)) {
|
||||
$this->html .= "<th>" . $column . "</th>";
|
||||
$columnKeys[] = $key;
|
||||
}
|
||||
}
|
||||
return $columnKeys;
|
||||
}
|
||||
|
||||
private function issetColumn($column): bool
|
||||
{
|
||||
if (isset($this->data['meta']['columns'])) {
|
||||
@ -146,6 +185,23 @@ class ListJsonTable
|
||||
return false;
|
||||
}
|
||||
|
||||
private function issetFilter($filter): bool
|
||||
{
|
||||
if (isset($this->data['filters'])) {
|
||||
foreach ($this->data['filters'] as $key => $currentFilter) {
|
||||
if (is_array($currentFilter)) {
|
||||
return false;
|
||||
} elseif (is_string($currentFilter)) {
|
||||
if ($currentFilter === $filter) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function is_fillable($column): bool
|
||||
{
|
||||
if (isset($this->data['meta']['fillable'])) {
|
||||
@ -170,6 +226,23 @@ class ListJsonTable
|
||||
return $actions;
|
||||
}
|
||||
|
||||
private function getFilters(array $columnKeys): void
|
||||
{
|
||||
$this->html .= "<tr><form action='$this->baseUrl/search'>";
|
||||
foreach ($columnKeys as $key){
|
||||
if ($this->issetFilter($key)){
|
||||
$this->html .= "<td><input type='text' name='$key'></td>";
|
||||
}
|
||||
else {
|
||||
$this->html .= "<td></td>";
|
||||
}
|
||||
}
|
||||
$this->html .= "</form></tr>";
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create(): void
|
||||
{
|
||||
$this->setActions();
|
||||
@ -181,7 +254,6 @@ class ListJsonTable
|
||||
|
||||
public function tableAction($json): void
|
||||
{
|
||||
|
||||
$tableJson = json_decode($json, true);
|
||||
|
||||
foreach ($tableJson as $key => $value) {
|
||||
@ -192,6 +264,9 @@ class ListJsonTable
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function endTable(): void
|
||||
{
|
||||
$this->html .= "</table>";
|
||||
@ -199,24 +274,23 @@ class ListJsonTable
|
||||
$this->html .= $hookAfter($this->data['meta']);
|
||||
|
||||
if ($this->pagination) {
|
||||
$pagination = new Pagination(
|
||||
$this->data['meta']['total'],
|
||||
$this->data['meta']['perPage'],
|
||||
$this->data['meta']['currentPage'],
|
||||
$this->baseUrl
|
||||
);
|
||||
$options = [
|
||||
'countItem' => $this->data['meta']['total'],
|
||||
'perPage' => $this->data['meta']['perPage'] ?? 10,
|
||||
'currentPage' => $this->data['meta']['currentPage'] ?? 1,
|
||||
'baseUrl' => $this->baseUrl ?? '',
|
||||
'prefix' => $this->data['meta']['paginationPrefix'] ?? '/page',
|
||||
];
|
||||
$pagination = new Pagination($options);
|
||||
$pagination->create();
|
||||
$this->html .= $pagination->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
public function render(): void
|
||||
public function columns(array $data): void
|
||||
{
|
||||
echo $this->html;
|
||||
}
|
||||
|
||||
public function setBeforePrintCell(\Closure $closure): void
|
||||
{
|
||||
$this->beforePrintCell = $closure;
|
||||
foreach ($data as $key => $value) {
|
||||
$this->beforePrintCell[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,9 @@
|
||||
namespace Itguild\Tables;
|
||||
|
||||
|
||||
use Exception;
|
||||
use http\Message;
|
||||
|
||||
class Pagination
|
||||
{
|
||||
|
||||
@ -14,13 +17,19 @@ class Pagination
|
||||
|
||||
private string $baseUrl;
|
||||
|
||||
public function __construct($countItem, $perPage, $currentPage, $baseUrl)
|
||||
// public function __construct(int $countItem, array $params, string $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);
|
||||
}
|
||||
@ -48,11 +57,6 @@ class Pagination
|
||||
return $this->html;
|
||||
}
|
||||
|
||||
public function hookBefore(): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private function getTemplate(): string
|
||||
{
|
||||
return '<nav aria-label="Page navigation example">
|
||||
|
@ -4,38 +4,33 @@ namespace Itguild\Tables;
|
||||
|
||||
use Itguild\Tables\traits\CreateParams;
|
||||
|
||||
class ViewJsonTable
|
||||
class ViewJsonTable extends JasonTable
|
||||
{
|
||||
use CreateParams;
|
||||
|
||||
private array $data;
|
||||
|
||||
private string $html = "";
|
||||
private string $json;
|
||||
|
||||
private \Closure|false $beforePrintCell;
|
||||
private \Closure|false $beforePrintTable;
|
||||
|
||||
private \Closure|false $afterPrintTable;
|
||||
|
||||
private array $dataJson;
|
||||
public function __construct($json)
|
||||
{
|
||||
$this->beforePrintCell = [];
|
||||
$this->json = $json;
|
||||
$this->data = json_decode($this->json, true);
|
||||
$this->dataJson = $this->data['data'];
|
||||
$this->beforePrintHook = function () {
|
||||
};
|
||||
$this->afterPrintHook = function () {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function beginTable(): void
|
||||
{
|
||||
$paramsStr = $this->createParams($this->data['meta']['params']);
|
||||
|
||||
//Хук перед выводом ячейки
|
||||
if (isset($this->beforePrintTable)){
|
||||
$hook = $this->beforePrintTable;
|
||||
$this->html = $hook();
|
||||
if (isset($this->beforePrintHook)){
|
||||
$hook = $this->beforePrintHook;
|
||||
$this->html .= $hook();
|
||||
}
|
||||
|
||||
$this->html .= "<table $paramsStr>";
|
||||
@ -44,20 +39,14 @@ class ViewJsonTable
|
||||
{
|
||||
foreach ($this->data['meta']['rows'] as $key => $row){
|
||||
if ($this->issetRow($key)){
|
||||
if (isset($this->beforePrintCell)){
|
||||
$hook = $this->beforePrintCell;
|
||||
$this->dataJson[$key] = $hook($key, $this->dataJson[$key]);
|
||||
if ($this->beforePrintCell) {
|
||||
$this->dataJson[$key] = $this->getCustomCell($key, $this->dataJson[$key]);
|
||||
}
|
||||
|
||||
$this->html .= "<tr><th>" . $row . ": </th><td>" . $this->dataJson[$key] . "</td></tr>";
|
||||
|
||||
$this->html .= "<tr><th>" . $row . "</th><td>" . $this->dataJson[$key] . "</td></tr>";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this->html;
|
||||
}
|
||||
|
||||
private function issetRow($column): bool
|
||||
{
|
||||
|
||||
@ -76,8 +65,8 @@ class ViewJsonTable
|
||||
{
|
||||
$this->html .= "</table>";
|
||||
|
||||
if(isset($this->afterPrintTable)){
|
||||
$hookAfter = $this->afterPrintTable;
|
||||
if(isset($this->afterPrintHook)){
|
||||
$hookAfter = $this->afterPrintHook;
|
||||
$this->html .= $hookAfter();
|
||||
}
|
||||
}
|
||||
@ -90,23 +79,10 @@ class ViewJsonTable
|
||||
}
|
||||
|
||||
|
||||
public function beforeTable(\Closure $closure): void
|
||||
public function rows(array $data): void
|
||||
{
|
||||
$this->beforePrintTable = $closure;
|
||||
}
|
||||
|
||||
public function afterTable(\Closure $closure): void
|
||||
{
|
||||
$this->afterPrintTable = $closure;
|
||||
}
|
||||
|
||||
public function render(): void
|
||||
{
|
||||
echo $this->html;
|
||||
}
|
||||
|
||||
public function setBeforePrintCell(\Closure $closure): void
|
||||
{
|
||||
$this->beforePrintCell = $closure;
|
||||
foreach ($data as $key => $value) {
|
||||
$this->beforePrintCell[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user