add JasonTable class

This commit is contained in:
2024-08-02 15:40:13 +03:00
parent 67a3f5770e
commit f53346610e
5 changed files with 80 additions and 103 deletions

View File

@ -11,17 +11,13 @@ 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|array|false $beforePrintCell;
private \Closure|false $beforePrintHook;
private \Closure|false $afterPrintHook;
private string $baseUrl;
private array $data;
@ -57,16 +53,6 @@ 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 = [];
@ -118,7 +104,7 @@ class ListJsonTable
}
foreach ($row as $key => $ceil) {
if ($this->issetColumn($key) and $this->is_fillable($key)) {
if($this->beforePrintCell and $ceil) {
if($this->beforePrintCell and $ceil !== null) {
$ceil = $this->getCustomCeil($key, $ceil);
}
$this->html .= "<td>" . $ceil . "</td>";
@ -294,37 +280,10 @@ class ListJsonTable
}
}
public function render(): void
{
echo $this->html;
}
public function setBeforePrintCell(\Closure $closure): void
{
$this->beforePrintCell = $closure;
}
public function columns(array $data): void
{
foreach ($data as $key => $value) {
$this->beforePrintCell[$key] = $value;
}
}
public function getCustomCeil(string $key, string $ceil)
{
if (is_array($this->beforePrintCell)) {
foreach ($this->beforePrintCell as $column => $closure) {
if ($key == $column) {
$hook = $closure;
$ceil = $hook($ceil);
}
}
} else {
$hook = $this->beforePrintCell;
$ceil = $hook($key, $ceil);
}
return $ceil;
}
// public function columns(array $data): void
// {
// foreach ($data as $key => $value) {
// $this->beforePrintCell[$key] = $value;
// }
// }
}