add hook afterPrint
This commit is contained in:
@ -7,6 +7,7 @@ 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
|
||||
{
|
||||
@ -17,34 +18,42 @@ class ListJsonTable
|
||||
|
||||
private int $count = 0;
|
||||
private \Closure|false $beforePrintCell;
|
||||
private \Closure|false $beforePrint;
|
||||
private \Closure|false $beforePrintHook;
|
||||
private \Closure|false $afterPrintHook;
|
||||
private string $baseUrl;
|
||||
private array $data;
|
||||
|
||||
private array $actionsArray = [];
|
||||
private array $customActionsArray = [];
|
||||
|
||||
public function __construct(string $json)
|
||||
#[NoReturn] public function __construct(string $json)
|
||||
{
|
||||
$this->beforePrintCell = false;
|
||||
$this->beforePrint = function () {
|
||||
};
|
||||
$this->json = $json;
|
||||
$this->data = json_decode($this->json, true);
|
||||
$this->baseUrl = $this->data['meta']['baseUrl'] ?? '';
|
||||
$this->beforePrintHook = function () {
|
||||
};
|
||||
$this->afterPrintHook = function () {
|
||||
};
|
||||
}
|
||||
|
||||
public function beginTable(): void
|
||||
{
|
||||
$paramsStr = $this->createParams($this->data['meta']['params']);
|
||||
$hook = $this->beforePrint;
|
||||
$this->html .= $hook();
|
||||
$hookBefore = $this->beforePrintHook;
|
||||
$this->html .= $hookBefore();
|
||||
$this->html .= "<table $paramsStr>";
|
||||
}
|
||||
|
||||
public function beforePrint(\Closure $closure): void
|
||||
{
|
||||
$this->beforePrint = $closure;
|
||||
$this->beforePrintHook = $closure;
|
||||
}
|
||||
|
||||
public function afterPrint(\Closure $closure): void
|
||||
{
|
||||
$this->afterPrintHook = $closure;
|
||||
}
|
||||
|
||||
public function createThead(): void
|
||||
@ -83,9 +92,14 @@ class ListJsonTable
|
||||
}
|
||||
}
|
||||
|
||||
$actions = $this->getActions($col["id"]);
|
||||
if (isset($col["id"])){
|
||||
$actions = $this->getActions($col["id"]);
|
||||
|
||||
$this->html .= "<td>$actions</td></tr>";
|
||||
$this->html .= "<td>$actions</td></tr>";
|
||||
}
|
||||
else {
|
||||
$this->html .= "<td></td></tr>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -177,6 +191,8 @@ class ListJsonTable
|
||||
public function endTable(): void
|
||||
{
|
||||
$this->html .= "</table>";
|
||||
$hookAfter = $this->afterPrintHook;
|
||||
$this->html .= $hookAfter();
|
||||
}
|
||||
|
||||
public function render(): void
|
||||
|
Reference in New Issue
Block a user