From 87deac257688dacd16bc3bbacf35b90ecbcb52aa Mon Sep 17 00:00:00 2001 From: kali Date: Mon, 15 Apr 2024 17:46:33 +0300 Subject: [PATCH] bd 6.0 --- .../1c/1c1a65045d16ca598e290fed477b7831.php | 97 ++++++++ form.json | 12 + in1.php | 0 index.php | 11 +- src/app/controllers/AdminController.php | 37 +++ src/app/controllers/FormController.php | 229 +++++++++++++----- src/app/models/FormModel.php | 2 + src/builders/HiddenBuilder.php | 17 ++ src/core/cg_view/CgView.php | 58 +++++ .../FormResultNotFoundException.php | 11 + src/inputs/Hidden.php | 60 +++++ src/mappers/JsonInputMapper.php | 2 + src/table/ActionColumn/ActionColumn.php | 1 + src/table/ActionColumn/EditActionColumn.php | 16 ++ src/table/ListJsonTable.php | 14 +- src/table/ViewJsonTable.php | 30 ++- src/table/actionBtn/ActionBtn.php | 22 ++ src/table/actionBtn/ToDeleteBtn.php | 13 + src/table/actionBtn/ToEditBtn.php | 13 + src/table/actionBtn/ToListBtn.php | 13 + src/traits/CreateOption.php | 2 +- views/admin/index.php | 42 ++++ views/layouts/admin_layout.php | 25 ++ 23 files changed, 652 insertions(+), 75 deletions(-) create mode 100644 compilation_cache/1c/1c1a65045d16ca598e290fed477b7831.php create mode 100644 in1.php create mode 100644 src/app/controllers/AdminController.php create mode 100644 src/builders/HiddenBuilder.php create mode 100644 src/core/cg_view/CgView.php create mode 100644 src/exceptions/FormResultNotFoundException.php create mode 100644 src/inputs/Hidden.php create mode 100644 src/table/ActionColumn/EditActionColumn.php create mode 100644 src/table/actionBtn/ActionBtn.php create mode 100644 src/table/actionBtn/ToDeleteBtn.php create mode 100644 src/table/actionBtn/ToEditBtn.php create mode 100644 src/table/actionBtn/ToListBtn.php create mode 100644 views/admin/index.php create mode 100644 views/layouts/admin_layout.php diff --git a/compilation_cache/1c/1c1a65045d16ca598e290fed477b7831.php b/compilation_cache/1c/1c1a65045d16ca598e290fed477b7831.php new file mode 100644 index 0000000..141a7d7 --- /dev/null +++ b/compilation_cache/1c/1c1a65045d16ca598e290fed477b7831.php @@ -0,0 +1,97 @@ +source = $this->getSourceContext(); + + $this->blocks = [ + 'title' => [$this, 'block_title'], + 'content' => [$this, 'block_content'], + ]; + } + + protected function doGetParent(array $context) + { + // line 1 + return "layouts/simple.html.twig"; + } + + protected function doDisplay(array $context, array $blocks = []) + { + $macros = $this->macros; + $this->parent = $this->loadTemplate("layouts/simple.html.twig", "form/form.html.twig", 1); + $this->parent->display($context, array_merge($this->blocks, $blocks)); + } + + // line 3 + public function block_title($context, array $blocks = []) + { + $macros = $this->macros; + echo twig_escape_filter($this->env, ($context["title"] ?? null), "html", null, true); + } + + // line 5 + public function block_content($context, array $blocks = []) + { + $macros = $this->macros; + // line 6 + echo "

"; + echo twig_escape_filter($this->env, ($context["title"] ?? null), "html", null, true); + echo "

+"; + // line 7 + echo twig_escape_filter($this->env, $this->env->getFunction('create_form')->getCallable()(), "html", null, true); + echo " + +"; + } + + /** + * @codeCoverageIgnore + */ + public function getTemplateName() + { + return "form/form.html.twig"; + } + + /** + * @codeCoverageIgnore + */ + public function isTraitable() + { + return false; + } + + /** + * @codeCoverageIgnore + */ + public function getDebugInfo() + { + return array ( 63 => 7, 58 => 6, 54 => 5, 47 => 3, 36 => 1,); + } + + public function getSourceContext() + { + return new Source("", "form/form.html.twig", "/home/kali/php/untitled/views/form/form.html.twig"); + } +} diff --git a/form.json b/form.json index b4b7670..1d102ee 100755 --- a/form.json +++ b/form.json @@ -64,4 +64,16 @@ "class": "btn btn-primary" } ] +} +{ + "meta": { + "perpage": 3, + "actions": ["view", "edit", "delete"], + "fillable": ["description", "phone", "telega", "city"], + "status" : 1 + }, + "params": { + "class": "form-control", + "id": "form" + } } \ No newline at end of file diff --git a/in1.php b/in1.php new file mode 100644 index 0000000..e69de29 diff --git a/index.php b/index.php index b5bd296..07842fd 100755 --- a/index.php +++ b/index.php @@ -26,11 +26,12 @@ $router->get("/form-res/{id}", [\itguild\forms\app\controllers\FormResController $router->get("/input-type/{id}", [\itguild\forms\app\controllers\InputTypeController::class, "indexAction"]); $router->get("/input-value/{id}", [\itguild\forms\app\controllers\InputValueController::class, "indexAction"]); $router->post("/form-save/{id}", [\itguild\forms\app\controllers\FormController::class, "saveAction"]); -$router->get("/form-result/{id}", [\itguild\forms\app\controllers\FormController::class, "result"]); -$router->get("/form-result/{id}/{page}", [\itguild\forms\app\controllers\FormController::class, "result"]); -$router->get("/form-item/{id}", [\itguild\forms\app\controllers\FormController::class, "getResultItem"]); -$router->get("/form-delete/{id}", [\itguild\forms\app\controllers\FormController::class, "deleteItem"]); - +$router->get("/form-result/{id}/{page}?", [\itguild\forms\app\controllers\FormController::class, "resultAction"]); +$router->get("/form-item/{id}", [\itguild\forms\app\controllers\FormController::class, "viewAction"]); +$router->get("/form-delete/{id}", [\itguild\forms\app\controllers\FormController::class, "deleteAction"]); +$router->get("/form-edit/{id}", [\itguild\forms\app\controllers\FormController::class, "editAction"]); +$router->get("/admin/create-form", [\itguild\forms\app\controllers\AdminController::class, "createAction"]); +$router->post("/admin/save-form", [\itguild\forms\app\controllers\AdminController::class, "saveForm"]); $dispatcher = new Phroute\Phroute\Dispatcher($router->getData()); $response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); diff --git a/src/app/controllers/AdminController.php b/src/app/controllers/AdminController.php new file mode 100644 index 0000000..535db23 --- /dev/null +++ b/src/app/controllers/AdminController.php @@ -0,0 +1,37 @@ +viewPath = VIEW_PATH; + $view->layout = "/layouts/admin_layout.php"; + + $view->render("/admin/index.php", ['title' => "Создать форму", 'form' => new ActiveForm()]); + + } + public function saveForm() + { + $title = $_POST["title"]; + $params = $_POST["params"]; + if (isset($title) and isset($params)) { + $form = FormModel::Create(['title' => $title, 'status' => FormModel::STATUS_ACTIVE, 'params' => $params]); + echo "Форма сохранена!"; + } + } + + + +} \ No newline at end of file diff --git a/src/app/controllers/FormController.php b/src/app/controllers/FormController.php index 5c984c4..1274c66 100644 --- a/src/app/controllers/FormController.php +++ b/src/app/controllers/FormController.php @@ -6,65 +6,44 @@ use itguild\forms\app\core\BaseController; use itguild\forms\app\models\FormModel; use itguild\forms\app\models\FormResModel; use itguild\forms\app\models\InputValueModel; +use itguild\forms\debug\Debug; use itguild\forms\exceptions\FormNotFoundException; +use itguild\forms\exceptions\FormResultNotFoundException; use itguild\forms\Form; use itguild\forms\JsonForm; +use itguild\forms\table\actionBtn\ToDeleteBtn; +use itguild\forms\table\actionBtn\ToEditBtn; +use itguild\forms\table\actionBtn\ToListBtn; use itguild\forms\table\ListJsonTable; use itguild\forms\table\Pagination; use itguild\forms\table\ViewJsonTable; +use Twig\Error\LoaderError; +use Twig\Error\RuntimeError; +use Twig\Error\SyntaxError; use Twig\TwigFunction; class FormController extends BaseController { + /** + * @throws SyntaxError + * @throws FormNotFoundException + * @throws RuntimeError + * @throws LoaderError + */ public function indexAction($id): void { - // Инициализируем пустые массивы - $meta = []; - $formArr = []; - $formFieldsArr = []; - // Получение формы из БД и обработка мета данных формы $form = FormModel::find($id); if (!$form) { throw new FormNotFoundException($id); } - if (isset($form->params)) { - $allParams = json_decode($form->params, true); - $meta = array_merge($meta, $allParams['params']); - - } - $meta['action'] = "/form-save/" . $form->id; - $meta['method'] = "POST"; - $formArr['meta'] = $meta; - - // Обработка полей формы - if ($form->fields) { - $fields = $form->fields; - foreach ($fields as $field) { - $options = []; - $fieldArr = []; - $params = []; - if ($field->inputValue) { - foreach ($field->inputValue as $value) { - $options[$value['id']] = $value['value']; - } - } - - if ($field->params) { - $fieldArr = array_merge($fieldArr, json_decode($field->params, true)); - } - $fieldArr['name'] = $field->name ?? $fieldArr['name']; - $fieldArr['type'] = $field->inputType['type'] ? $field->inputType['type'] : "textInput"; - $fieldArr['options'] = $options; - $formArr['data'][] = $fieldArr; - } - } + $formArr = $this->createFormArr($form); $formArr['data'][] = ['type' => "button", 'typeInput' => "submit", "value" => "Отправить", "name" => "", "class" => "btn btn-primary"]; - //Debug::dd($fields); + //Debug::dd($formArr); $this->view->addFunction(new TwigFunction("create_form", function () use ($formArr) { $form = new JsonForm(json_encode($formArr)); @@ -78,7 +57,17 @@ class FormController extends BaseController public function saveAction($id): void { - $form = FormResModel::Create(['form_id' => $id, 'data' => json_encode($_POST),]); + if (isset($_POST["form_res_id"])) { + $formResId = $_POST["form_res_id"]; + unset($_POST["form_res_id"]); + FormResModel::where("id", $formResId)->update(["data" => json_encode($_POST)]); + } else { + $formRes = FormResModel::Create(['form_id' => $id, 'data' => json_encode($_POST),]); + $formResId = $formRes->id; + } + header('Location: ' . "/form-item/$formResId"); + exit; + } @@ -87,7 +76,7 @@ class FormController extends BaseController $form = Form::Create(['title' => "dsds", 'status' => 1, 'params' => "",]); } - public function result($id, $page = 1) + public function resultAction($id, $page = 1): void { $meta = []; @@ -102,22 +91,22 @@ class FormController extends BaseController $fillable = $formParams["meta"]["fillable"] ?? null; $actions = $formParams["meta"]["actions"] ?? null; $offset = ($page - 1) * $perPage; - $countItems = FormResModel::count(); + $countItems = FormResModel::where("status", 1)->count(); $table = FormResModel::where("form_id", $id)->where("status", FormResModel::STATUS_ACTIVE)->limit(3)->offset($offset)->get(); foreach ($table as $key => $item) { - $data[] = array_merge(json_decode($item->data, true), ["id" => $item->id]); + $data[] = array_merge(json_decode($item->data, true), ["id" => $item->id]); } if ($form->fields) { foreach ($form->fields as $field) { - if ($field->input_type_id === 6) { - $fillable = $formParams["meta"]["fillable"] ?? null; - $columnsToMod[] = $field->name; + if ($field->input_type_id === 6) { + $fillable = $formParams["meta"]["fillable"] ?? null; + $columnsToMod[] = $field->name; - } + } $columns[$field->name] = $field->label; @@ -137,24 +126,28 @@ class FormController extends BaseController $tableArr["data"] = $data; $tableRes = json_encode($tableArr); - $this->view->addFunction(new TwigFunction("create_table", function () use ($tableRes, $columnsToMod, $form) { + $this->view->addFunction(new TwigFunction("create_table", function () use ($tableRes, $columnsToMod, $form, $countItems) { $table = new ListJsonTable($tableRes); - $table->setBeforePrintCell(function ($column, $data) use ($columnsToMod, $form){ - if (in_array($column, $columnsToMod)){ + $table->setBeforePrintCell(function ($column, $data) use ($columnsToMod, $form) { + if (in_array($column, $columnsToMod)) { $res = InputValueModel::find($data); return $res->value ?? ""; } return $data; }); + $table->beforePrint(function () use($countItems){ + return "
Количество записей: " . $countItems . "
"; + + }); + $table->create(); $table->render(); - })); $this->view->addFunction(new TwigFunction("create_pagination", function () use ($perPage, $page, $countItems, $form) { @@ -168,15 +161,45 @@ class FormController extends BaseController } - public function deleteItem($id) + public function deleteAction($id): void { - $item = FormResModel::find($id)->update(["status" => FormResModel::STATUS_ARCHIVE]); - header( 'Location: ' . '' ); + $item = FormResModel::find($id); + $item->update(["status" => FormResModel::STATUS_ARCHIVE]); + + header('Location: ' . "/form-result/$item->form_id"); exit; + } + + public function editAction($id): void + { + $res = FormResModel::find($id); + if (!$res) { + throw new FormResultNotFoundException($id); + } + + $form = FormModel::find($res->form_id); + + if (!$form) { + throw new FormNotFoundException($id); + } + + $formArr = $this->createFormArr($form, $res); + $formArr["data"][] = ["type" => "hidden", "value" => $id, "name" => "form_res_id"]; + $formArr['data'][] = ['type' => "button", 'typeInput' => "submit", "value" => "Редактировать", "name" => "", "class" => "btn btn-primary"]; + + //Debug::dd($formArr); + + $this->view->addFunction(new TwigFunction("create_form", function () use ($formArr) { + $form = new JsonForm(json_encode($formArr)); + $form->convertHTML(); + $form->render(); + })); + + echo $this->view->render('form/form.html.twig', ['title' => $form->title]); } - public function getResultItem($id) + public function viewAction($id): void { $resultForm = FormResModel::find($id); $formID = $resultForm->form_id; @@ -189,7 +212,7 @@ class FormController extends BaseController if ($form->fields) { foreach ($form->fields as $field) { - if ($field->input_type_id === 6){ + if ($field->input_type_id === 6) { $columnsToMod[] = $field->name; } @@ -203,7 +226,7 @@ class FormController extends BaseController $meta['title'] = "ITEM ID: " . $id; $meta['columns'] = $columns; $meta['params'] = ["class" => "table table-bordered", "border" => "1"]; - + $meta["actions"] = ["view", "edit", "delete"]; $tableArr["meta"] = $meta; $tableArr["data"] = $resultForm; @@ -211,12 +234,10 @@ class FormController extends BaseController $tableRes = json_encode($tableArr); + $this->view->addFunction(new TwigFunction("create_get_action", function () use ($tableRes, $columnsToMod, $form, $resultForm) { - - $this->view->addFunction(new TwigFunction("create_get_action", function () use ($tableRes, $columnsToMod, $form) { - - $pagination = new ViewJsonTable($tableRes); - $pagination->setBeforePrintCell(function ($column, $data) use ($columnsToMod, $form) { + $table = new ViewJsonTable($tableRes); + $table->setBeforePrintCell(function ($column, $data) use ($columnsToMod, $form) { if (in_array($column, $columnsToMod)) { $res = InputValueModel::find($data); return $res->value ?? ""; @@ -224,11 +245,95 @@ class FormController extends BaseController return $data; }); - $pagination->create(); - $pagination->render(); + $table->beforeTable(function () use($form, $resultForm){ + $btn = (new ToListBtn(BASE_URL, $form->id))->fetch(); + $btn .= (new ToEditBtn(BASE_URL, $resultForm->id))->fetch(); + $btn .= (new ToDeleteBtn(BASE_URL, $resultForm->id))->fetch(); + return $btn; + }); + + $table->afterTable(function () use ($resultForm){ + + $timeCreate = "
Создано: " . $resultForm->created_at . "
"; + $timeUpdate = "
Обновлено: " . $resultForm->updated_at . "
";; + return $timeCreate . $timeUpdate; + + }); + + $table->create(); + $table->render(); })); + echo $this->view->render('form/resultItem.html.twig', ['title' => $tableArr["meta"]["title"]]); } + + + private function createFormArr(FormModel $form, FormResModel|false $formResult = false): array + { + // Инициализируем пустые массивы + $meta = []; + $formArr = []; + $formFieldsArr = []; + $resArr = []; + // Получение формы из БД и обработка мета данных формы + + if ($formResult) { + $resArr = json_decode($formResult->data, true); + } + + if (isset($form->params)) { + $allParams = json_decode($form->params, true); + $meta = array_merge($meta, $allParams['params']); + + } + $meta['action'] = "/form-save/" . $form->id; + $meta['method'] = "POST"; + $formArr['meta'] = $meta; + + $formResults = FormResModel::where("form_id", $form->id)->where("id",); + + // Обработка полей формы + if ($form->fields) { + $fields = $form->fields; + foreach ($fields as $field) { + $options = []; + $fieldArr = []; + $params = []; + if ($field->inputValue) { + foreach ($field->inputValue as $value) { + $options[$value['id']] = $value['value']; + } + } + + if ($field->params) { + $fieldArr = array_merge($fieldArr, json_decode($field->params, true)); + } + $fieldArr['name'] = $field->name ?? $fieldArr['name']; + + if ($field->input_type_id === 4) { + if ($resArr[$fieldArr['name']] === $fieldArr['value']) { + $fieldArr['checked'] = "true"; + } + } + if ($field->input_type_id === 1) { + if ($resArr[$fieldArr['name']] === $fieldArr['value']) { + $fieldArr['checked'] = "true"; + } + } + + if ($formResult && $field->input_type_id !== 4) { + $fieldArr['value'] = $resArr[$fieldArr['name']] ?? null; + } + $fieldArr['type'] = $field->inputType['type'] ? $field->inputType['type'] : "textInput"; + $fieldArr['options'] = $options; + $formArr['data'][] = $fieldArr; + } + } + + return $formArr; + } + + } \ No newline at end of file diff --git a/src/app/models/FormModel.php b/src/app/models/FormModel.php index a7b2022..54204bd 100644 --- a/src/app/models/FormModel.php +++ b/src/app/models/FormModel.php @@ -6,6 +6,8 @@ use Illuminate\Database\Eloquent\Model; class FormModel extends Model { + const STATUS_ACTIVE = 1; + const STATUS_ARCHIVE = 2; protected $table = "form"; protected $fillable = [ diff --git a/src/builders/HiddenBuilder.php b/src/builders/HiddenBuilder.php new file mode 100644 index 0000000..c919028 --- /dev/null +++ b/src/builders/HiddenBuilder.php @@ -0,0 +1,17 @@ +createContent($view, $data); + + echo $content; + } + + public function fetch(string $view, array $data = []): false|string + { + $content = $this->createContent($view, $data); + + return $content; + } + + private function createContent(string $view, array $data = []): false|string + { + ob_start(); + + foreach ($data as $key => $datum){ + ${"$key"} = $datum; + } + + include ($this->viewPath . $view); + + $content = ob_get_contents(); + ob_end_clean (); + + ob_start(); + $file_content = $content; + + if ($this->layout){ + if (file_exists($this->viewPath . $this->layout)){ + include ($this->viewPath . $this->layout); + $file_content = ob_get_contents(); + } + } + ob_end_clean (); + + return $file_content; + } + +} \ No newline at end of file diff --git a/src/exceptions/FormResultNotFoundException.php b/src/exceptions/FormResultNotFoundException.php new file mode 100644 index 0000000..0cf5cff --- /dev/null +++ b/src/exceptions/FormResultNotFoundException.php @@ -0,0 +1,11 @@ + message = "Ответ формы $id не найдена"; + } +} \ No newline at end of file diff --git a/src/inputs/Hidden.php b/src/inputs/Hidden.php new file mode 100644 index 0000000..2bf8a78 --- /dev/null +++ b/src/inputs/Hidden.php @@ -0,0 +1,60 @@ +name = $name; + $this->value = $value; + $this->paramsArray = $paramsArray; + $this->inputTemplate = new SimpleTemplate(); + } + + /** + * @return $this + */ + public function create(): self + { + $paramsString = $this->createParams($this->paramsArray); + $hidden = ""; + $label = ""; + + $this->createLabel(); + + $this->html = str_replace('{input}', $hidden, $this->inputTemplate->getInputTemplate()); + $this->html = str_replace('{label}', $this->labelString, $this->html); + + return $this; + } + + /** + * @param string $name + * @param string $value + * @param array $paramsArray + * @return void + */ + public static function build(string $name, string $value, array $paramsArray): void + { + $hidden = new self($name, $value, $paramsArray); + $hidden->create()->render(); + + } +} \ No newline at end of file diff --git a/src/mappers/JsonInputMapper.php b/src/mappers/JsonInputMapper.php index 9937897..38316a5 100755 --- a/src/mappers/JsonInputMapper.php +++ b/src/mappers/JsonInputMapper.php @@ -5,6 +5,7 @@ namespace itguild\forms\mappers; use itguild\forms\builders\Builder; use itguild\forms\builders\ButtonBuilder; use itguild\forms\builders\CheckBoxBuilder; +use itguild\forms\builders\HiddenBuilder; use itguild\forms\builders\LabelBuilder; use itguild\forms\builders\RadioButtonBuilder; use itguild\forms\builders\SelectBuilder; @@ -23,6 +24,7 @@ class JsonInputMapper "select" => SelectBuilder::class, "button" => ButtonBuilder::class, "checkbox" => CheckBoxBuilder::class, + "hidden" => HiddenBuilder::class, ]; } diff --git a/src/table/ActionColumn/ActionColumn.php b/src/table/ActionColumn/ActionColumn.php index e385990..e3b30f9 100644 --- a/src/table/ActionColumn/ActionColumn.php +++ b/src/table/ActionColumn/ActionColumn.php @@ -6,6 +6,7 @@ abstract class ActionColumn { protected string $baseUrl; protected string $prefix; + protected int $id; public function __construct(string $baseUrl, int $id) { diff --git a/src/table/ActionColumn/EditActionColumn.php b/src/table/ActionColumn/EditActionColumn.php new file mode 100644 index 0000000..25b2a69 --- /dev/null +++ b/src/table/ActionColumn/EditActionColumn.php @@ -0,0 +1,16 @@ +baseUrl . $this->prefix . $this->id; + return " Редактировать "; + } + +} \ No newline at end of file diff --git a/src/table/ListJsonTable.php b/src/table/ListJsonTable.php index 4557d5e..1693b01 100644 --- a/src/table/ListJsonTable.php +++ b/src/table/ListJsonTable.php @@ -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 = ""; + $hook = $this->beforePrint; + $this->html .= $hook(); + $this->html .= "
"; + } + + 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; } } } diff --git a/src/table/ViewJsonTable.php b/src/table/ViewJsonTable.php index 8e2f91f..fe9818e 100644 --- a/src/table/ViewJsonTable.php +++ b/src/table/ViewJsonTable.php @@ -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 = "
"; + $hook = $this->beforePrintTable; + $this->html = $hook(); + $this->html .= "
"; } - 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 .= "html .= "
"; + $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() { diff --git a/src/table/actionBtn/ActionBtn.php b/src/table/actionBtn/ActionBtn.php new file mode 100644 index 0000000..5b4256f --- /dev/null +++ b/src/table/actionBtn/ActionBtn.php @@ -0,0 +1,22 @@ +baseUrl = $baseUrl; + $this->id = $id; + + return $this; + } + + abstract public function fetch(); + +} \ No newline at end of file diff --git a/src/table/actionBtn/ToDeleteBtn.php b/src/table/actionBtn/ToDeleteBtn.php new file mode 100644 index 0000000..2cc332f --- /dev/null +++ b/src/table/actionBtn/ToDeleteBtn.php @@ -0,0 +1,13 @@ +baseUrl$this->prefix$this->id' style='margin: 3px'>Удалить"; + } +} \ No newline at end of file diff --git a/src/table/actionBtn/ToEditBtn.php b/src/table/actionBtn/ToEditBtn.php new file mode 100644 index 0000000..f75e4aa --- /dev/null +++ b/src/table/actionBtn/ToEditBtn.php @@ -0,0 +1,13 @@ +baseUrl$this->prefix$this->id' style='margin: 3px'>Редактировать"; + } +} \ No newline at end of file diff --git a/src/table/actionBtn/ToListBtn.php b/src/table/actionBtn/ToListBtn.php new file mode 100644 index 0000000..4228b30 --- /dev/null +++ b/src/table/actionBtn/ToListBtn.php @@ -0,0 +1,13 @@ +baseUrl$this->prefix$this->id' style='margin: 3px'>Список"; + } +} \ No newline at end of file diff --git a/src/traits/CreateOption.php b/src/traits/CreateOption.php index c915d57..0ba5071 100755 --- a/src/traits/CreateOption.php +++ b/src/traits/CreateOption.php @@ -13,7 +13,7 @@ trait CreateOption { $optionsString = ""; foreach ($options as $val => $title){ - $selected = $value === $val ? "selected" : ""; + $selected = (int)$value === $val ? "selected" : ""; $optionsString .= ""; } return $optionsString; diff --git a/views/admin/index.php b/views/admin/index.php new file mode 100644 index 0000000..6cd9811 --- /dev/null +++ b/views/admin/index.php @@ -0,0 +1,42 @@ + + +beginForm("/admin/save-form"); ?> +field(TextInput::class, name: "title", params: [ + 'class' => "form-control", + 'placeholder' => 'Название формы' +]) + ->setLabel("Название формы") + ->render(); +$form->field(TextArea::class, name: "params", params: [ + 'class' => "form-control", + 'placeholder' => 'Параметры формы' +]) + ->setLabel("Параметры формы") + ->render(); +$form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ + 'class' => "btn btn-primary ", + 'value' => 'Отправить', + 'typeInput' => 'submit' +]) + ->render(); +?> + +endForm(); ?> diff --git a/views/layouts/admin_layout.php b/views/layouts/admin_layout.php new file mode 100644 index 0000000..050562d --- /dev/null +++ b/views/layouts/admin_layout.php @@ -0,0 +1,25 @@ + + + + + + <?php echo $title ?> + + + + +
+
+
+ +
+
+
+ + \ No newline at end of file