Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
9e7c83b680 | |||
b374744261 | |||
c6918c85b3 | |||
d98ddded07 | |||
1bd82eb40b | |||
4a12eeccfd |
@ -20,7 +20,7 @@ class JasonTable
|
||||
$this->beforePrintCell = $closure;
|
||||
}
|
||||
|
||||
public function getCustomCell(string $key, string $cell)
|
||||
public function getCustomCell(string $key, string|null $cell)
|
||||
{
|
||||
if (is_array($this->beforePrintCell)) {
|
||||
foreach ($this->beforePrintCell as $currentKey => $closure) {
|
||||
|
@ -29,7 +29,7 @@ class ListJsonTable extends JasonTable
|
||||
|
||||
#[NoReturn] public function __construct(string $json)
|
||||
{
|
||||
$this->beforePrintCell = false;
|
||||
$this->beforePrintCell = [];
|
||||
$this->json = $json;
|
||||
$this->data = json_decode($this->json, true);
|
||||
$this->baseUrl = $this->data['meta']['baseUrl'] ?? '';
|
||||
@ -86,7 +86,7 @@ class ListJsonTable extends JasonTable
|
||||
}
|
||||
foreach ($row as $key => $cell) {
|
||||
if ($this->issetColumn($key) and $this->is_fillable($key)) {
|
||||
if($this->beforePrintCell and $cell !== null) {
|
||||
if($this->beforePrintCell) {
|
||||
$cell = $this->getCustomCell($key, $cell);
|
||||
}
|
||||
$this->html .= "<td>" . $cell . "</td>";
|
||||
@ -276,10 +276,10 @@ class ListJsonTable extends JasonTable
|
||||
if ($this->pagination) {
|
||||
$options = [
|
||||
'countItem' => $this->data['meta']['total'],
|
||||
'perPage' => $this->data['meta']['perPage'],
|
||||
'currentPage' => $this->data['meta']['currentPage'],
|
||||
'baseUrl' => $this->baseUrl,
|
||||
'prefix' => $this->data['meta']['paginationPrefix'],
|
||||
'perPage' => $this->data['meta']['perPage'] ?? 10,
|
||||
'currentPage' => $this->data['meta']['currentPage'] ?? 1,
|
||||
'baseUrl' => $this->baseUrl ?? '',
|
||||
'prefix' => $this->data['meta']['paginationPrefix'] ?? '/page',
|
||||
];
|
||||
$pagination = new Pagination($options);
|
||||
$pagination->create();
|
||||
|
@ -13,9 +13,14 @@ class ViewJsonTable extends JasonTable
|
||||
private array $dataJson;
|
||||
public function __construct($json)
|
||||
{
|
||||
$this->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
|
||||
@ -23,9 +28,9 @@ class ViewJsonTable extends JasonTable
|
||||
$paramsStr = $this->createParams($this->data['meta']['params']);
|
||||
|
||||
//Хук перед выводом ячейки
|
||||
if (isset($this->beforePrintTable)){
|
||||
$hook = $this->beforePrintTable;
|
||||
$this->html = $hook();
|
||||
if (isset($this->beforePrintHook)){
|
||||
$hook = $this->beforePrintHook;
|
||||
$this->html .= $hook();
|
||||
}
|
||||
|
||||
$this->html .= "<table $paramsStr>";
|
||||
@ -34,7 +39,7 @@ class ViewJsonTable extends JasonTable
|
||||
{
|
||||
foreach ($this->data['meta']['rows'] as $key => $row){
|
||||
if ($this->issetRow($key)){
|
||||
if ($this->beforePrintCell and $this->dataJson[$key] !== null) {
|
||||
if ($this->beforePrintCell) {
|
||||
$this->dataJson[$key] = $this->getCustomCell($key, $this->dataJson[$key]);
|
||||
}
|
||||
$this->html .= "<tr><th>" . $row . "</th><td>" . $this->dataJson[$key] . "</td></tr>";
|
||||
@ -60,8 +65,8 @@ class ViewJsonTable extends JasonTable
|
||||
{
|
||||
$this->html .= "</table>";
|
||||
|
||||
if(isset($this->afterPrintTable)){
|
||||
$hookAfter = $this->afterPrintTable;
|
||||
if(isset($this->afterPrintHook)){
|
||||
$hookAfter = $this->afterPrintHook;
|
||||
$this->html .= $hookAfter();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user