This commit is contained in:
kali
2024-04-03 18:25:38 +03:00
parent 09b5167a1a
commit cfe5b3cca5
17 changed files with 227 additions and 147 deletions

View File

@ -12,10 +12,14 @@ class TableJsonWidget extends BaseWidget
private string $html = '';
private string $json;
private int $count = 0;
private \Closure|false $beforePrintCell;
private array $data;
public function __construct(string $json)
{
$this->beforePrintCell = false;
$this->json = $json;
$this->data = json_decode($this->json, true);
}
@ -33,6 +37,7 @@ class TableJsonWidget extends BaseWidget
}
$this->html .= "<thead><tr>";
$this->html .= "<th>" . "ID" . "</th>";
foreach ($this->data['meta']['columns'] as $key => $column){
$this->html .= "<th>" . $column . "</th>";
}
@ -44,8 +49,15 @@ class TableJsonWidget extends BaseWidget
if ($this->data['data']){
foreach ($this->data['data'] as $col){
$this->html .= "<tr>";
$this->count += 1;
$this->html .= "<td>" . $this->count . "</td>";
foreach ($col as $key => $row){
if ($this->issetColumn($key)){
if ($this->beforePrintCell){
$hook = $this->beforePrintCell;
$row = $hook($key, $row);
}
$this->html .= "<td>" . $row . "</td>";
}
}
@ -97,4 +109,9 @@ class TableJsonWidget extends BaseWidget
{
echo $this->html;
}
public function setBeforePrintCell(\Closure $closure): void
{
$this->beforePrintCell = $closure;
}
}