diff --git a/compilation_cache/ea/ea1278337c261f39a1523ba336d5c786.php b/compilation_cache/ea/ea1278337c261f39a1523ba336d5c786.php
new file mode 100644
index 0000000..6353f70
--- /dev/null
+++ b/compilation_cache/ea/ea1278337c261f39a1523ba336d5c786.php
@@ -0,0 +1,96 @@
+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/result.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_table')->getCallable()(), "html", null, true);
+ echo "
+";
+ }
+
+ /**
+ * @codeCoverageIgnore
+ */
+ public function getTemplateName()
+ {
+ return "form/result.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/result.html.twig", "/home/kali/php/untitled/views/form/result.html.twig");
+ }
+}
diff --git a/index.php b/index.php
index 54b03df..4a2972e 100755
--- a/index.php
+++ b/index.php
@@ -24,6 +24,7 @@ $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-load/{id}", [\itguild\forms\app\controllers\FormController::class, "result"]);
$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/FormController.php b/src/app/controllers/FormController.php
index c8d8b96..f369f4e 100644
--- a/src/app/controllers/FormController.php
+++ b/src/app/controllers/FormController.php
@@ -6,9 +6,11 @@ use itguild\forms\app\core\BaseController;
use itguild\forms\app\models\FormModel;
use itguild\forms\app\models\FormResModel;
+use itguild\forms\app\models\User;
use itguild\forms\debug\Debug;
use itguild\forms\Form;
use itguild\forms\JsonForm;
+use itguild\forms\widgets\TableJsonWidget;
use Twig\TwigFunction;
@@ -35,8 +37,8 @@ class FormController extends BaseController
foreach ($fields as $field) {
$options = [];
$fieldArr = [];
- if ($field->inputValue){
- foreach ($field->inputValue as $value){
+ if ($field->inputValue) {
+ foreach ($field->inputValue as $value) {
$options[$value['id']] = $value['value'];
}
}
@@ -49,7 +51,7 @@ class FormController extends BaseController
$formArr['data'][] = $fieldArr;
}
- $formArr['data'][] = ['type' => "button", 'typeInput' => "submit","value" => "Отправить", "name" => "btn", "class" => "btn btn-primary"];
+ $formArr['data'][] = ['type' => "button", 'typeInput' => "submit", "value" => "Отправить", "name" => "", "class" => "btn btn-primary"];
//Debug::dd($fields);
@@ -73,4 +75,37 @@ class FormController extends BaseController
$form = Form::Create(['title' => "dsds", 'status' => 1, 'params' => "",]);
}
+ public function result($id)
+ {
+ $meta = [];
+ $data = [];
+ $tableArr = [];
+
+ $table = FormResModel::where("form_id", $id)->get();
+ foreach ($table as $key => $item){
+
+ $data[] = json_decode($item->data, true);
+
+ }
+
+ $meta['title'] = "Form ID: " . $id;
+ $meta['columns'] = ["email" => "Email", "description" => "Описание 1", "description2" => "Описание 2"];
+ $meta['params'] = ["class" => "table table-bordered", "border" => "1"];
+
+
+ $tableArr["meta"] = $meta;
+ $tableArr["data"] = $data;
+ $tableRes = json_encode($tableArr);
+
+ $this->view->addFunction(new TwigFunction("create_table", function () use ($tableRes) {
+
+ $table = new TableJsonWidget($tableRes);
+ $table->create();
+ $table->render();
+
+ }));
+
+ echo $this->view->render('form/result.html.twig', ['title' => $tableArr['meta']["title"]]);
+ }
+
}
\ No newline at end of file
diff --git a/src/widgets/BaseWidget.php b/src/widgets/BaseWidget.php
new file mode 100644
index 0000000..a7e2be5
--- /dev/null
+++ b/src/widgets/BaseWidget.php
@@ -0,0 +1,8 @@
+json = $json;
+ $this->data = json_decode($this->json, true);
+ }
+
+ public function beginTable(): void
+ {
+ $paramsStr = $this->createParams($this->data['meta']['params']);
+ $this->html = "";
+ }
+
+ public function createThead(): void
+ {
+ if (!isset($this->data['meta']['columns'])){
+ return;
+ }
+
+ $this->html .= "";
+ foreach ($this->data['meta']['columns'] as $key => $column){
+ $this->html .= "" . $column . " | ";
+ }
+ $this->html .= "
";
+ }
+
+ public function createTbody(): void
+ {
+ if ($this->data['data']){
+ foreach ($this->data['data'] as $col){
+ $this->html .= "";
+ foreach ($col as $key => $row){
+ if ($this->issetColumn($key)){
+ $this->html .= "" . $row . " | ";
+ }
+ }
+ $this->html .= "
";
+ }
+ }
+ }
+
+ private function issetColumn($column)
+ {
+ if (isset($this->data['meta']['columns'])){
+ foreach ($this->data['meta']['columns'] as $key => $currentColumn){
+ if ($key === $column){
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public function create()
+ {
+ $this->beginTable();
+ $this->createThead();
+ $this->createTbody();
+ $this->endTable();
+ }
+
+ public function tableAction($json): void
+ {
+
+ $tableJson = json_decode($json, true);
+
+ foreach ($tableJson as $key => $value) {
+ echo "";
+ echo "" . $key . " | ";
+ echo "" . $value . " | ";
+ echo "
";
+ }
+ }
+
+ public function endTable(): void
+ {
+ $this->html .= "
";
+ }
+
+ public function render(): void
+ {
+ echo $this->html;
+ }
+}
\ No newline at end of file
diff --git a/table.json b/table.json
new file mode 100644
index 0000000..824a44f
--- /dev/null
+++ b/table.json
@@ -0,0 +1,15 @@
+{
+ "meta": {
+ "title": "forma 1",
+ "columns": {
+ "email": "Email",
+ "description": "Описание 1",
+ "description2": "Описание 2"
+ },
+ "params": {"class": "table table-bordered", "border": "1"}
+ },
+ "data": [
+ {"email":"fas@mail.ru","description":"fafdgdfs","description2":"ffdghdas"},
+
+ ]
+}
\ No newline at end of file
diff --git a/views/form/result.html.twig b/views/form/result.html.twig
new file mode 100644
index 0000000..dfc2846
--- /dev/null
+++ b/views/form/result.html.twig
@@ -0,0 +1,8 @@
+{% extends "layouts/simple.html.twig" %}
+
+{% block title %}{{ title }}{% endblock %}
+
+{% block content %}
+ {{ title }}
+ {{ create_table() }}
+{% endblock %}
\ No newline at end of file