2024-07-16 13:37:34 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace kernel\IGTabel;
|
|
|
|
|
|
|
|
use app\helpers\Debug;
|
|
|
|
|
|
|
|
class JSONCreator
|
|
|
|
{
|
|
|
|
protected array $informationArray = [];
|
|
|
|
|
|
|
|
public function __construct(array $meta, array $data)
|
|
|
|
{
|
|
|
|
$params = empty($meta['params']) ? ["class" => "table table-bordered", "border" => "1"] : $meta['params'];
|
2024-07-26 12:42:44 +03:00
|
|
|
if ($meta) {
|
2024-07-16 13:37:34 +03:00
|
|
|
$this->informationArray = [
|
|
|
|
"meta" => [
|
2024-07-23 15:22:33 +03:00
|
|
|
"columns" => $meta['columns'] ?? [],
|
|
|
|
"rows" => $meta['rows'] ?? [],
|
2024-07-16 13:37:34 +03:00
|
|
|
"perPage" => $meta['perPage'] ?? 10,
|
|
|
|
"currentPage" => $meta['currentPage'] ?? 1,
|
|
|
|
"baseUrl" => $meta['baseUrl'] ?? '',
|
|
|
|
"actions" => $meta['actions'] ?? '',
|
|
|
|
"params" => $params
|
|
|
|
|
|
|
|
],
|
2024-07-26 12:42:44 +03:00
|
|
|
"data" => $data ?? []
|
2024-07-16 13:37:34 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $infArr
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
protected function toJson(array $infArr): ?string
|
|
|
|
{
|
|
|
|
if ($infArr)
|
|
|
|
return json_encode($infArr, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function getJson(): ?string
|
|
|
|
{
|
|
|
|
return $this->toJson($this->informationArray);
|
|
|
|
}
|
|
|
|
}
|