Compare commits

..

3 Commits

Author SHA1 Message Date
kali
432b2547cf bd 2024-03-29 17:47:46 +03:00
kali
74719c7250 bd 2024-03-27 17:24:47 +03:00
kali
e91e44ded9 bd 2024-03-25 18:07:54 +03:00
62 changed files with 2491 additions and 24 deletions

5
.env Executable file
View File

@ -0,0 +1,5 @@
DB_DRIVER=mysql
DB_HOST="127.0.0.1"
DB_NAME=forms
DB_USER=root
DB_PASSWORD=kali

0
.gitignore vendored Normal file → Executable file
View File

19
bootstrap/db.php Executable file
View File

@ -0,0 +1,19 @@
<?php
require "vendor/autoload.php";
use Dotenv\Dotenv;
use Illuminate\Database\Capsule\Manager as Capsule;
$dotenv = Dotenv::createImmutable(ROOT_PATH);
$dotenv->load();
$capsule = new Capsule;
$capsule->addConnection([
"driver" => "mysql",
"host" =>"127.0.0.1",
"database" => "forms",
"username" => "root",
"password" => "kali"
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();

0
checkPOST.php Normal file → Executable file
View File

6
composer.json Normal file → Executable file
View File

@ -14,6 +14,10 @@
"require": {
"twbs/bootstrap": "5.0.2",
"itguild/php-cg-select-v2": "^0.1.0",
"craft-group/phroute": "^2.1"
"craft-group/phroute": "^2.1",
"twig/twig": "^3.0",
"illuminate/database": "^11.0",
"vlucas/phpdotenv": "^5.6",
"illuminate/filesystem": "^11.1"
}
}

1928
composer.lock generated Normal file → Executable file

File diff suppressed because it is too large Load Diff

30
console.php Executable file
View File

@ -0,0 +1,30 @@
<?php
use itguild\forms\migrations\UserMigration;
use Illuminate\Filesystem\Filesystem;
const ROOT_PATH = __DIR__;
require_once "vendor/autoload.php";
require_once "bootstrap/db.php";
//$fileSystem = new Filesystem();
//
//$migration = new \Illuminate\Database\Migrations\MigrationCreator($fileSystem, "migrations/stubs");
//
////try {
//// $migration->create("some", "migrations", "my");
////} catch (Exception $e) {
//// var_dump($e->getMessage());
////}
//$rep = new \Illuminate\Database\Migrations\DatabaseMigrationRepository();
//$migrator = new \Illuminate\Database\Migrations\Migrator()
//UserMigration::up();
//\itguild\forms\migrations\FormsMigration::up();
//\itguild\forms\migrations\InputsTypeMigration::up();
//\itguild\forms\migrations\FormsInputMigration::up();
//\itguild\forms\migrations\FormsResMigration::up();
//\itguild\forms\migrations\InputsValueMigrations::up();
DB::forms('form_input')-> get();

0
example.php Normal file → Executable file
View File

0
example_json.php Normal file → Executable file
View File

0
form.json Normal file → Executable file
View File

19
index.php Normal file → Executable file
View File

@ -2,18 +2,31 @@
ini_set("display_errors", 1);
error_reporting(-1);
const ROOT_PATH = __DIR__;
const VIEW_PATH = __DIR__ . "/views";
const VIEW_CACHE_PATH = __DIR__ . "/compilation_cache";
require_once "vendor/autoload.php";
require_once "bootstrap/db.php";
use Phroute\Phroute\RouteCollector;
$router = new RouteCollector();
$router->get('/', [\itguild\forms\app\controllers\Main::class, 'indexAction']);
$router->get('/example', [\itguild\forms\app\controllers\Main::class, 'exampleAction']);
$router->get('/', [\itguild\forms\app\controllers\MainController::class, 'indexAction']);
$router->get('/example', [\itguild\forms\app\controllers\MainController::class, 'exampleAction']);
$router->get('/create-user', [\itguild\forms\app\controllers\UserController::class, 'createUserAction']);
$router->get('/get-user/{id}', [\itguild\forms\app\controllers\UserController::class, 'getUserAction']);
$router->get("/form/{id}", [\itguild\forms\app\controllers\FormController::class, "indexAction"]);
$router->get("/form-input/{id}", [\itguild\forms\app\controllers\FormInputController::class, "indexAction"]);
$router->get("/form-res/{id}", [\itguild\forms\app\controllers\FormResController::class, "indexAction"]);
$router->get("/input-type/{id}", [\itguild\forms\app\controllers\InputTypeController::class, "indexAction"]);
$router->get("/input-value/{id}", [\itguild\forms\app\controllers\InputValueController::class, "indexAction"]);
$dispatcher = new Phroute\Phroute\Dispatcher($router->getData());
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
// Print out the value returned from the dispatched function
echo $response;

0
old_index.php Normal file → Executable file
View File

2
routing.php Normal file → Executable file
View File

@ -8,4 +8,4 @@ use Phroute\Phroute\RouteCollector;
$router = new RouteCollector();
$router->get('/', [\itguild\forms\app\controllers\Main::class, 'indexAction']);
$router->get('/', [\itguild\forms\app\controllers\MainController::class, 'indexAction']);

0
src/ActiveForm.php Normal file → Executable file
View File

0
src/Form.php Normal file → Executable file
View File

5
src/JsonForm.php Normal file → Executable file
View File

@ -66,4 +66,9 @@ class JsonForm
echo $this->html;
}
public function fetch(): string
{
return $this->html;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace itguild\forms\app\controllers;
use itguild\forms\app\core\BaseController;
use itguild\forms\app\models\FormModel;
use itguild\forms\debug\Debug;
use itguild\forms\Form;
class FormController extends BaseController
{
public function indexAction($id)
{
$form = FormModel::find($id);
$fields = $form->fields;
Debug::dd($fields);
}
public function createFormAction()
{
$form = Form::Create([ 'title' => "dsds", 'status' => 1, 'params' => "", ]);
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace itguild\forms\app\controllers;
use itguild\forms\app\core\BaseController;
use itguild\forms\app\models\FormInputModel;
use itguild\forms\debug\Debug;
class FormInputController extends BaseController
{
public function indexAction($id)
{
Debug::prn(FormInputModel::find($id)->first());
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace itguild\forms\app\controllers;
use itguild\forms\app\core\BaseController;
use itguild\forms\app\models\FormResModel;
use itguild\forms\debug\Debug;
class FormResController extends BaseController
{
public function indexAction($id)
{
Debug::prn(FormResModel::find($id)->first());
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace itguild\forms\app\controllers;
use itguild\forms\app\core\BaseController;
use itguild\forms\app\models\InputTypeModel;
use itguild\forms\debug\Debug;
class InputTypeController extends BaseController
{
public function indexAction($id)
{
Debug::prn(InputTypeModel::find($id)->first());
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace itguild\forms\app\controllers;
use itguild\forms\app\core\BaseController;
use itguild\forms\app\models\InputValueModel;
use itguild\forms\debug\Debug;
class InputValueController extends BaseController
{
public function indexAction($id)
{
Debug::prn(InputValueModel::find($id)->first());
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace itguild\forms\app\controllers;
class Main
{
public function indexAction(): void
{
echo 123;
}
public function exampleAction()
{
echo "example";
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace itguild\forms\app\controllers;
use itguild\forms\app\core\BaseController;
use itguild\forms\debug\Debug;
use itguild\forms\JsonForm;
use Twig\TwigFunction;
class MainController extends BaseController
{
private $html;
public function indexAction(): void
{
$this->view->addFunction(new TwigFunction("create_form", function (){
$form = new JsonForm(file_get_contents("form.json"));
$form->convertHTML();
$form->render();
}));
echo $this->view->render('main/index.html.twig', ['title' => 'Заголовок', 'content' => ""]);
}
public function exampleAction()
{
echo "example";
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace itguild\forms\app\controllers;
use itguild\forms\app\core\BaseController;
use itguild\forms\app\models\User;
use itguild\forms\debug\Debug;
class UserController extends BaseController
{
public function createUserAction()
{
$user = User::Create([ 'name' => "Ahmed Khan", 'email' => "ahmed.khan@lbs.com", 'password' => password_hash("ahmedkhan",PASSWORD_BCRYPT), ]);
}
public function getUserAction($id)
{
Debug::prn(User::find(1)->first()->email);
}
}

17
src/app/core/BaseController.php Executable file
View File

@ -0,0 +1,17 @@
<?php
namespace itguild\forms\app\core;
class BaseController
{
protected $view;
public function __construct()
{
$loader = new \Twig\Loader\FilesystemLoader(VIEW_PATH);
$this->view = new \Twig\Environment($loader, [
'cache' => VIEW_CACHE_PATH,
]);
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace itguild\forms\app\models;
use Illuminate\Database\Eloquent\Model;
class FormInputModel extends Model
{
protected $table = "form_input";
protected $fillable = [
'form_id', 'input_type_id', 'params'
];
protected $hidden = [
];
public function inputType()
{
return $this->hasOne(InputTypeModel::class, "id");
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace itguild\forms\app\models;
use Illuminate\Database\Eloquent\Model;
class FormModel extends Model
{
protected $table = "form";
protected $fillable = [
'title', 'status', 'params'
];
protected $hidden = [
];
public function fields()
{
return $this->hasMany(FormInputModel::class, "form_id");
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace itguild\forms\app\models;
use Illuminate\Database\Eloquent\Model;
class FormResModel extends Model
{
protected $table = "form_res";
protected $fillable = [
'form_id', 'data'
];
protected $hidden = [
];
}

View File

@ -0,0 +1,18 @@
<?php
namespace itguild\forms\app\models;
use Illuminate\Database\Eloquent\Model;
class InputTypeModel extends Model
{
protected $table = "input_type";
protected $fillable = [
'type', 'name', 'status'
];
protected $hidden = [
];
}

View File

@ -0,0 +1,18 @@
<?php
namespace itguild\forms\app\models;
use Illuminate\Database\Eloquent\Model;
class InputValueModel extends Model
{
protected $table = "input_value";
protected $fillable = [
'form_input_id', 'value'
];
protected $hidden = [
];
}

19
src/app/models/User.php Executable file
View File

@ -0,0 +1,19 @@
<?php
namespace itguild\forms\app\models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $table = "user";
protected $fillable = [
'name', 'email', 'password','userimage'
];
protected $hidden = [
'password', 'remember_token',
];
}

0
src/builders/Builder.php Normal file → Executable file
View File

0
src/builders/ButtonBuilder.php Normal file → Executable file
View File

0
src/builders/CheckBoxBuilder.php Normal file → Executable file
View File

0
src/builders/LabelBuilder.php Normal file → Executable file
View File

0
src/builders/RadioButtonBuilder.php Normal file → Executable file
View File

0
src/builders/SelectBuilder.php Normal file → Executable file
View File

0
src/builders/TextAreaBuilder.php Normal file → Executable file
View File

0
src/builders/TextInputBuilder.php Normal file → Executable file
View File

0
src/debug/Debug.php Normal file → Executable file
View File

0
src/inputs/BaseInput.php Normal file → Executable file
View File

0
src/inputs/Button.php Normal file → Executable file
View File

0
src/inputs/Checkbox.php Normal file → Executable file
View File

0
src/inputs/Label.php Normal file → Executable file
View File

0
src/inputs/RadioButton.php Normal file → Executable file
View File

0
src/inputs/Select.php Normal file → Executable file
View File

0
src/inputs/TextArea.php Normal file → Executable file
View File

0
src/inputs/TextInput.php Normal file → Executable file
View File

0
src/mappers/JsonInputMapper.php Normal file → Executable file
View File

View File

@ -0,0 +1,33 @@
<?php
namespace itguild\forms\migrations;
use Illuminate;
use Illuminate\Database\Schema\Blueprint;
class FormsInputMigration extends Illuminate\Database\Migrations\Migration
{
public static function up(): void
{
Illuminate\Database\Capsule\Manager::schema()->create("form_input", function (Blueprint $table) {
$table->id("id");
$table->unsignedBigInteger('form_id');
$table->unsignedBigInteger('input_type_id');
$table->text('params');
$table->timestamps();
$table->index('form_id');
$table->index('input_type_id');
$table->foreign('form_id', 'fk_form_input_form')->references('id')->on('form');
$table->foreign('input_type_id', 'fk_form_input_input_type')->references('id')->on('input_type');
});
}
public static function down(): void
{
Illuminate\Database\Capsule\Manager::schema()->drop("form_input");
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace itguild\forms\migrations;
use Illuminate;
class FormsMigration
{
public static function up(): void
{
Illuminate\Database\Capsule\Manager::schema()->create("form", function ($table) {
$table->id('id');
$table->string('title');
$table->integer('status');
$table->text('params')->nullable();
$table->timestamps();
});
}
public static function get()
{
return DB::forms('form_input')-> get();
}
public static function down(): void
{
Illuminate\Database\Capsule\Manager::schema()->drop("form");
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace itguild\forms\migrations;
use Illuminate;
class FormsResMigration
{
public static function up(): void
{
Illuminate\Database\Capsule\Manager::schema()->create("form_res", function ($table) {
$table->id('id');
$table->unsignedBigInteger('form_id');
$table->json('data');
$table->timestamps();
$table->foreign('form_id', 'fk_form_form')->references('id')->on('form');
});
}
public static function down(): void
{
Illuminate\Database\Capsule\Manager::schema()->drop("form_res");
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace itguild\forms\migrations;
use Illuminate;
class InputsTypeMigration
{
public static function up(): void
{
Illuminate\Database\Capsule\Manager::schema()->create("input_type", function ($table) {
$table->id('id');
$table->string('type');
$table->string('name');
$table->integer('status');
});
}
public static function down(): void
{
Illuminate\Database\Capsule\Manager::schema()->drop("input_type");
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace itguild\forms\migrations;
use Illuminate;
class InputsValueMigrations
{
public static function up(): void
{
Illuminate\Database\Capsule\Manager::schema()->create("input_value", function ($table) {
$table->id('id');
$table->unsignedBigInteger('form_input_id');
$table->string('value');
$table->timestamps();
$table->foreign('form_input_id', 'fk_form_input')->references('id')->on('form_input');
});
}
public static function down(): void
{
Illuminate\Database\Capsule\Manager::schema()->drop("input_value");
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace itguild\forms\migrations;
use Illuminate;
class UserMigration
{
public static function up(): void
{
Illuminate\Database\Capsule\Manager::schema()->create("user", function ($table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->string('userimage')->nullable();
$table->string('api_key')->nullable()->unique();
$table->rememberToken();
$table->timestamps();
});
}
public static function down(): void
{
Illuminate\Database\Capsule\Manager::schema()->drop("user");
}
}

0
src/templates/Simple/SimpleTemplate.php Normal file → Executable file
View File

0
src/templates/Template.php Normal file → Executable file
View File

0
src/templates/bootstrap5/Bootstrap5Template.php Normal file → Executable file
View File

0
src/traits/CreateOption.php Normal file → Executable file
View File

0
src/traits/CreateParams.php Normal file → Executable file
View File

22
views/layouts/simple.html.twig Executable file
View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}{% endblock %} </title>
<link rel="stylesheet" href="vendor/twbs/bootstrap/dist/css/bootstrap.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous" />
</head>
<body>
<div class="container">
<div class="row">
<div class="col-12">
{% block content %}{% endblock %}
</div>
</div>
</div>
</body>
</html>

8
views/main/index.html.twig Executable file
View File

@ -0,0 +1,8 @@
{% extends "layouts/simple.html.twig" %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
{{ create_form() }}
{{ content }}
{% endblock %}