beforePrintCell = [];
$this->json = $json;
$this->data = json_decode($this->json, true);
$this->dataJson = $this->data['data'];
$this->beforePrintHook = function () {
};
$this->afterPrintHook = function () {
};
}
public function beginTable(): void
{
$paramsStr = $this->createParams($this->data['meta']['params']);
//Хук перед выводом ячейки
if (isset($this->beforePrintHook)){
$hook = $this->beforePrintHook;
$this->html .= $hook();
}
$this->html .= "
";
}
public function createRows(): string
{
foreach ($this->data['meta']['rows'] as $key => $row){
if ($this->issetRow($key)){
if ($this->beforePrintCell) {
$this->dataJson[$key] = $this->getCustomCell($key, $this->dataJson[$key]);
}
$this->html .= "" . $row . " | " . $this->dataJson[$key] . " |
";
}
}
return $this->html;
}
private function issetRow($column): bool
{
if (isset($this->data['meta']['rows'])){
foreach ($this->data['meta']['rows'] as $key => $currentColumn){
if ($key === $column){
return true;
}
}
}
return false;
}
public function endTable(): void
{
$this->html .= "
";
if(isset($this->afterPrintHook)){
$hookAfter = $this->afterPrintHook;
$this->html .= $hookAfter();
}
}
public function create(): void
{
$this->beginTable();
$this->createRows();
$this->endTable();
}
public function rows(array $data): void
{
foreach ($data as $key => $value) {
$this->beforePrintCell[$key] = $value;
}
}
}