46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
|
<?php
|
||
|
|
||
|
|
||
|
namespace app;
|
||
|
class foo
|
||
|
{
|
||
|
public array $informationArray;
|
||
|
|
||
|
/**
|
||
|
* @param array $columns
|
||
|
* @param array $data
|
||
|
* @return string|null
|
||
|
*/
|
||
|
public function createJsonArray(array $columns, array $data, string $title): ?string
|
||
|
{
|
||
|
if ($columns && $data) {
|
||
|
$this->informationArray = [
|
||
|
"meta" => [
|
||
|
"title" => $title,
|
||
|
"columns" => $columns,
|
||
|
"perPage" => 10,
|
||
|
"currentPage" => 1,
|
||
|
"params" =>
|
||
|
[
|
||
|
"class" => "table table-bordered",
|
||
|
"border" => "1"
|
||
|
]
|
||
|
],
|
||
|
"data" => $data
|
||
|
];
|
||
|
return $this->toJson($this->informationArray);
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @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;
|
||
|
}
|
||
|
}
|