6 Commits

Author SHA1 Message Date
a2284e3bf2 columns update 2024-08-08 13:26:45 +03:00
9e7c83b680 fix View Json Table 2024-08-07 14:31:07 +03:00
b374744261 Merge branch 'master' of https://git.itguild.info/ItGuild/tables 2024-08-07 14:21:00 +03:00
c6918c85b3 fix View Jason Table 2024-08-07 14:10:26 +03:00
d98ddded07 fix view json table 2024-08-07 12:43:14 +03:00
1bd82eb40b some fix 2024-08-07 12:16:42 +03:00
5 changed files with 37 additions and 22 deletions

View File

@ -5,7 +5,7 @@
"id": "ID", "id": "ID",
"email": "Email", "email": "Email",
"description": "Описание 1", "description": "Описание 1",
"description2": "Описание 2", "created_at": "Создан",
"status": "Статус" "status": "Статус"
}, },
"actions": ["view"], "actions": ["view"],
@ -22,15 +22,15 @@
"email", "description" "email", "description"
], ],
"data": [ "data": [
{"id": 1,"email":"fas1@mail.ru","description":"sdgsdfg","description2":"ffdghdas", "status": 1}, {"id": 1,"email":"fas1@mail.ru","description":"sdgsdfg","created_at":"2024-07-22 15:24:37", "status": 1},
{"id": 2,"email":"fas2@mail.ru","description":"fafdgdfgsdfdfs","description2":"ffdghdas", "status": 1}, {"id": 2,"email":"fas2@mail.ru","description":"fafdgdfgsdfdfs","created_at":"2024-04-22 15:56:37", "status": 1},
{"id": 3,"email":"fas3@mail.ru","description":"fafdgdssdfgdfs","description2":"ffdghdas", "status": 2}, {"id": 3,"email":"fas3@mail.ru","description":"fafdgdssdfgdfs","created_at":"2024-07-27 15:24:37", "status": 2},
{"id": 4,"email":"fas4@mail.ru","description":"fafddsfgsdvcbgdfs","description2":"ffdghdas", "status": 1}, {"id": 4,"email":"fas4@mail.ru","description":"fafddsfgsdvcbgdfs","created_at":"2024-07-04 15:24:37", "status": 1},
{"id": 5,"email":"fas5@mail.ru","description":"fafdgghjgfdfs","description2":"ffdghdas", "status": 1}, {"id": 5,"email":"fas5@mail.ru","description":"fafdgghjgfdfs","created_at":"2024-07-13 15:24:37", "status": 1},
{"id": 6,"email":"fas6@mail.ru","description":"fafddfgdhvgdfs","description2":"ffdghdas", "status": 1}, {"id": 6,"email":"fas6@mail.ru","description":"fafddfgdhvgdfs","created_at":"2024-07-20 15:24:37", "status": 1},
{"id": 7,"email":"fas7@mail.ru","description":"fafdfgnfdgdfs","description2":"ffdghdas", "status": 0}, {"id": 7,"email":"fas7@mail.ru","description":"fafdfgnfdgdfs","created_at":"2024-06-22 15:24:37", "status": 0},
{"id": 8,"email":"fas8@mail.ru","description":"fafdfghdfgdfs","description2":"ffdghdas", "status": 1}, {"id": 8,"email":"fas8@mail.ru","description":"fafdfghdfgdfs","created_at":"2023-12-12 15:12:37", "status": 1},
{"id": 12,"email":"dfdfd@mail.ru","description":"sdffhdfhggsdfg","description2":"ffdgdfgsdfghdas", "status": 99}, {"id": 12,"email":"dfdfd@mail.ru","description":"sdffhdfhggsdfg","created_at":"2024-03-11 17:24:37", "status": 99},
{"id": 13,"email":"dfsdfsddfd@mail.ru","description":"sdffhdfsdfshggsdfg","description2":"ffdgdsdffgsdfghdas", "status": 1} {"id": 13,"email":"dfsdfsddfd@mail.ru","description":"sdffhdfsdfshggsdfg","created_at":"2023-11-19 14:24:37", "status": 1}
] ]
} }

View File

@ -9,6 +9,10 @@ $table = new ListJsonTable($json);
//$table->columns([ //$table->columns([
$table->columns([ $table->columns([
[
'field' => 'created_at',
'format' => 'date:d-m-Y',
],
'status' => function ($cell) { 'status' => function ($cell) {
return getStatusLabel()[$cell]; return getStatusLabel()[$cell];
}, },

View File

@ -20,7 +20,7 @@ class JasonTable
$this->beforePrintCell = $closure; $this->beforePrintCell = $closure;
} }
public function getCustomCell(string $key, string $cell) public function getCustomCell(string $key, string|null $cell)
{ {
if (is_array($this->beforePrintCell)) { if (is_array($this->beforePrintCell)) {
foreach ($this->beforePrintCell as $currentKey => $closure) { foreach ($this->beforePrintCell as $currentKey => $closure) {

View File

@ -29,7 +29,7 @@ class ListJsonTable extends JasonTable
#[NoReturn] public function __construct(string $json) #[NoReturn] public function __construct(string $json)
{ {
$this->beforePrintCell = false; $this->beforePrintCell = [];
$this->json = $json; $this->json = $json;
$this->data = json_decode($this->json, true); $this->data = json_decode($this->json, true);
$this->baseUrl = $this->data['meta']['baseUrl'] ?? ''; $this->baseUrl = $this->data['meta']['baseUrl'] ?? '';
@ -86,7 +86,7 @@ class ListJsonTable extends JasonTable
} }
foreach ($row as $key => $cell) { foreach ($row as $key => $cell) {
if ($this->issetColumn($key) and $this->is_fillable($key)) { if ($this->issetColumn($key) and $this->is_fillable($key)) {
if($this->beforePrintCell and $cell !== null) { if($this->beforePrintCell) {
$cell = $this->getCustomCell($key, $cell); $cell = $this->getCustomCell($key, $cell);
} }
$this->html .= "<td>" . $cell . "</td>"; $this->html .= "<td>" . $cell . "</td>";
@ -287,10 +287,21 @@ class ListJsonTable extends JasonTable
} }
} }
// public function columns(array $data): void
// {
// foreach ($data as $key => $value) {
// $this->beforePrintCell[$key] = $value;
// }
// }
public function columns(array $data): void public function columns(array $data): void
{ {
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
$this->beforePrintCell[$key] = $value; foreach ($value as $currentKey => $currentValue) {
echo "<pre>";
print_r($currentValue);
// die();
}
} }
} }
} }

View File

@ -13,7 +13,7 @@ class ViewJsonTable extends JasonTable
private array $dataJson; private array $dataJson;
public function __construct($json) public function __construct($json)
{ {
$this->beforePrintCell = false; $this->beforePrintCell = [];
$this->json = $json; $this->json = $json;
$this->data = json_decode($this->json, true); $this->data = json_decode($this->json, true);
$this->dataJson = $this->data['data']; $this->dataJson = $this->data['data'];
@ -28,9 +28,9 @@ class ViewJsonTable extends JasonTable
$paramsStr = $this->createParams($this->data['meta']['params']); $paramsStr = $this->createParams($this->data['meta']['params']);
//Хук перед выводом ячейки //Хук перед выводом ячейки
if (isset($this->beforePrintTable)){ if (isset($this->beforePrintHook)){
$hook = $this->beforePrintTable; $hook = $this->beforePrintHook;
$this->html = $hook(); $this->html .= $hook();
} }
$this->html .= "<table $paramsStr>"; $this->html .= "<table $paramsStr>";
@ -39,7 +39,7 @@ class ViewJsonTable extends JasonTable
{ {
foreach ($this->data['meta']['rows'] as $key => $row){ foreach ($this->data['meta']['rows'] as $key => $row){
if ($this->issetRow($key)){ if ($this->issetRow($key)){
if ($this->beforePrintCell and $this->dataJson[$key] !== null) { if ($this->beforePrintCell) {
$this->dataJson[$key] = $this->getCustomCell($key, $this->dataJson[$key]); $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>";
@ -65,8 +65,8 @@ class ViewJsonTable extends JasonTable
{ {
$this->html .= "</table>"; $this->html .= "</table>";
if(isset($this->afterPrintTable)){ if(isset($this->afterPrintHook)){
$hookAfter = $this->afterPrintTable; $hookAfter = $this->afterPrintHook;
$this->html .= $hookAfter(); $this->html .= $hookAfter();
} }
} }