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 .= ""; foreach ($this->data['meta']['columns'] as $key => $column){ $this->html .= ""; } $this->html .= ""; } public function createTbody(): void { if ($this->data['data']){ foreach ($this->data['data'] as $col){ $this->html .= ""; $this->count += 1; $this->html .= ""; foreach ($col as $key => $row){ if ($this->issetColumn($key)){ if ($this->beforePrintCell){ $hook = $this->beforePrintCell; $row = $hook($key, $row); } $this->html .= ""; } } $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 ""; echo ""; echo ""; } } public function endTable(): void { $this->html .= "
" . "ID" . "" . $column . "
" . $this->count . "" . $row . "
" . $key . "" . $value . "
"; } public function render(): void { echo $this->html; } public function setBeforePrintCell(\Closure $closure): void { $this->beforePrintCell = $closure; } }