beforePrintCell = false;
$this->json = $json;
$this->data = json_decode($this->json, true);
}
public function beginTable(): void
{
$paramsStr = $this->createParams($this->data['meta']['params']);
$this->html = "
";
}
public function createThead(): void
{
if (!isset($this->data['meta']['columns'])){
return;
}
$this->html .= "";
$this->html .= "" . "ID" . " | ";
foreach ($this->data['meta']['columns'] as $key => $column){
$this->html .= "" . $column . " | ";
}
$this->html .= "
";
}
public function createTbody(): void
{
if ($this->data['data']){
foreach ($this->data['data'] as $col){
$this->html .= "";
$this->count += 1;
$this->html .= "" . $this->count . " | ";
foreach ($col as $key => $row){
if ($this->issetColumn($key)){
if ($this->beforePrintCell){
$hook = $this->beforePrintCell;
$row = $hook($key, $row);
}
$this->html .= "" . $row . " | ";
}
}
$this->html .= "
";
}
}
}
private function issetColumn($column)
{
if (isset($this->data['meta']['columns'])){
foreach ($this->data['meta']['columns'] as $key => $currentColumn){
if ($key === $column){
return true;
}
}
}
return false;
}
public function create()
{
$this->beginTable();
$this->createThead();
$this->createTbody();
$this->endTable();
}
public function tableAction($json): void
{
$tableJson = json_decode($json, true);
foreach ($tableJson as $key => $value) {
echo "";
echo "" . $key . " | ";
echo "" . $value . " | ";
echo "
";
}
}
public function endTable(): void
{
$this->html .= "
";
}
public function render(): void
{
echo $this->html;
}
public function setBeforePrintCell(\Closure $closure): void
{
$this->beforePrintCell = $closure;
}
}