bd 6.0
This commit is contained in:
@ -6,6 +6,7 @@ abstract class ActionColumn
|
||||
{
|
||||
protected string $baseUrl;
|
||||
protected string $prefix;
|
||||
|
||||
protected int $id;
|
||||
public function __construct(string $baseUrl, int $id)
|
||||
{
|
||||
|
16
src/table/ActionColumn/EditActionColumn.php
Normal file
16
src/table/ActionColumn/EditActionColumn.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace itguild\forms\table\ActionColumn;
|
||||
|
||||
class EditActionColumn extends ActionColumn
|
||||
{
|
||||
|
||||
protected string $prefix = "/form-edit/";
|
||||
|
||||
public function fetch(): string
|
||||
{
|
||||
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||
return " <a href='$link' class='btn btn-primary'>Редактировать</a> ";
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ namespace itguild\forms\table;
|
||||
|
||||
use itguild\forms\debug\Debug;
|
||||
use itguild\forms\table\ActionColumn\DeleteActionColumn;
|
||||
use itguild\forms\table\ActionColumn\EditActionColumn;
|
||||
use itguild\forms\table\ActionColumn\ViewActionColumn;
|
||||
use itguild\forms\traits\CreateParams;
|
||||
use itguild\forms\widgets\BaseWidget;
|
||||
@ -17,6 +18,7 @@ class ListJsonTable
|
||||
|
||||
private int $count = 0;
|
||||
private \Closure|false $beforePrintCell;
|
||||
private \Closure|false $beforePrint;
|
||||
private string $baseUrl;
|
||||
private array $data;
|
||||
|
||||
@ -34,7 +36,14 @@ class ListJsonTable
|
||||
public function beginTable(): void
|
||||
{
|
||||
$paramsStr = $this->createParams($this->data['meta']['params']);
|
||||
$this->html = "<table $paramsStr>";
|
||||
$hook = $this->beforePrint;
|
||||
$this->html .= $hook();
|
||||
$this->html .= "<table $paramsStr>";
|
||||
}
|
||||
|
||||
public function beforePrint(\Closure $closure): void
|
||||
{
|
||||
$this->beforePrint = $closure;
|
||||
}
|
||||
|
||||
public function createThead(): void
|
||||
@ -91,6 +100,9 @@ class ListJsonTable
|
||||
case 'delete':
|
||||
$this->actionsArray[] = DeleteActionColumn::class;
|
||||
break;
|
||||
case 'edit':
|
||||
$this->actionsArray[] = EditActionColumn::class;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,9 @@ class ViewJsonTable
|
||||
private string $json;
|
||||
|
||||
private \Closure|false $beforePrintCell;
|
||||
private \Closure|false $beforePrintTable;
|
||||
|
||||
private \Closure|false $afterPrintTable;
|
||||
|
||||
private array $dataJson;
|
||||
public function __construct($json)
|
||||
@ -22,17 +25,18 @@ class ViewJsonTable
|
||||
$this->json = $json;
|
||||
$this->data = json_decode($this->json, true);
|
||||
$this->dataJson = json_decode($this->data['data']['data'], true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function beginTable(): void
|
||||
{
|
||||
|
||||
$paramsStr = $this->createParams($this->data['meta']['params']);
|
||||
$this->html = "<table $paramsStr>";
|
||||
$hook = $this->beforePrintTable;
|
||||
$this->html = $hook();
|
||||
$this->html .= "<table $paramsStr>";
|
||||
}
|
||||
public function createColum()
|
||||
public function createColum(): string
|
||||
{
|
||||
foreach ($this->data['meta']['columns'] as $key => $column){
|
||||
if ($this->issetColumn($key)){
|
||||
@ -66,7 +70,10 @@ class ViewJsonTable
|
||||
|
||||
public function endTable()
|
||||
{
|
||||
$this->html .= "</table";
|
||||
$this->html .= "</table>";
|
||||
$hookAfter = $this->afterPrintTable;
|
||||
$this->html .= $hookAfter();
|
||||
|
||||
}
|
||||
|
||||
public function create()
|
||||
@ -76,6 +83,17 @@ class ViewJsonTable
|
||||
$this->endTable();
|
||||
}
|
||||
|
||||
|
||||
public function beforeTable(\Closure $closure): void
|
||||
{
|
||||
$this->beforePrintTable = $closure;
|
||||
}
|
||||
|
||||
public function afterTable(\Closure $closure): void
|
||||
{
|
||||
$this->afterPrintTable = $closure;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
|
22
src/table/actionBtn/ActionBtn.php
Normal file
22
src/table/actionBtn/ActionBtn.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace itguild\forms\table\actionBtn;
|
||||
|
||||
abstract class ActionBtn
|
||||
{
|
||||
|
||||
protected string $baseUrl;
|
||||
protected string $prefix;
|
||||
|
||||
protected int $id;
|
||||
public function __construct(string $baseUrl, int $id)
|
||||
{
|
||||
$this->baseUrl = $baseUrl;
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
abstract public function fetch();
|
||||
|
||||
}
|
13
src/table/actionBtn/ToDeleteBtn.php
Normal file
13
src/table/actionBtn/ToDeleteBtn.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace itguild\forms\table\actionBtn;
|
||||
|
||||
class ToDeleteBtn extends ActionBtn
|
||||
{
|
||||
protected string $prefix = "/form-delete/";
|
||||
|
||||
public function fetch(): string
|
||||
{
|
||||
return "<a class='btn btn-danger' href='$this->baseUrl$this->prefix$this->id' style='margin: 3px'>Удалить</a>";
|
||||
}
|
||||
}
|
13
src/table/actionBtn/ToEditBtn.php
Normal file
13
src/table/actionBtn/ToEditBtn.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace itguild\forms\table\actionBtn;
|
||||
|
||||
class ToEditBtn extends ActionBtn
|
||||
{
|
||||
protected string $prefix = "/form-edit/";
|
||||
|
||||
public function fetch(): string
|
||||
{
|
||||
return "<a class='btn btn-warning' href='$this->baseUrl$this->prefix$this->id' style='margin: 3px'>Редактировать</a>";
|
||||
}
|
||||
}
|
13
src/table/actionBtn/ToListBtn.php
Normal file
13
src/table/actionBtn/ToListBtn.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace itguild\forms\table\actionBtn;
|
||||
|
||||
class ToListBtn extends ActionBtn
|
||||
{
|
||||
protected string $prefix = "/form-result/";
|
||||
|
||||
public function fetch(): string
|
||||
{
|
||||
return "<a class='btn btn-primary' href='$this->baseUrl$this->prefix$this->id' style='margin: 3px'>Список</a>";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user