Compare commits
258 Commits
e588866a92
...
master
Author | SHA1 | Date | |
---|---|---|---|
a64ed080bb | |||
6242304843 | |||
2655a793f5 | |||
de0354f9cb | |||
4a4d5b083f | |||
68b5741f46 | |||
fc70051761 | |||
b1dacff877 | |||
e904cedf40 | |||
64a6cc4340 | |||
b79483dafd | |||
7ab241daa2 | |||
c69314b531 | |||
e448ffa6b6 | |||
3c025a4cbc | |||
6a7cde15e9 | |||
2b2c99cd17 | |||
b6ba8f8718 | |||
11c99be0f6 | |||
f421e0c649 | |||
3120795eab | |||
50c6ca98d8 | |||
dac4db96af | |||
c228a70468 | |||
3e178f6633 | |||
64dad0aaf9 | |||
32d1e93e73 | |||
dd231b0c07 | |||
88114ae9f2 | |||
6a07e5cdde | |||
7489e999ef | |||
1a54003030 | |||
28c8e24847 | |||
b5b7befd34 | |||
2790105a7d | |||
f0bda2ee24 | |||
04bd134e3e | |||
c23b84bcea | |||
de690dfd39 | |||
093b04c2c9 | |||
b24fac512a | |||
a71102eb05 | |||
7a7241746a | |||
95c3c0755b | |||
1cf2dc3d86 | |||
57d2f20255 | |||
5d671d03d2 | |||
d74a30f33e | |||
798c687547 | |||
bcf8b6621b | |||
0d98ec7cde | |||
a0a99de862 | |||
ea83698070 | |||
aa913293ef | |||
e152e0f193 | |||
bbc7eafc3d | |||
e6455165b3 | |||
2e4fc0496b | |||
045bd837b7 | |||
c4b3f46111 | |||
625089acd1 | |||
cebae3491b | |||
1d7ed112a7 | |||
fc188482d0 | |||
11cb001cfd | |||
6c1bd4a8e6 | |||
73a64ff717 | |||
378f27970e | |||
11420fbb2b | |||
17f31874ea | |||
967bcc28b5 | |||
b00c005b09 | |||
57c715807a | |||
9c77403a71 | |||
63d96eb461 | |||
f7253bafe9 | |||
1e566481f7 | |||
a9951102c0 | |||
3c0b78ea56 | |||
fb39da53a6 | |||
9419626485 | |||
38b6aa8860 | |||
cfbcb3609f | |||
62ed358a4b | |||
8778c4d725 | |||
e41f3faa42 | |||
03d3fa43f0 | |||
bc6c35167e | |||
9e446563b2 | |||
8df13569e2 | |||
1b486eb788 | |||
d318c99ba5 | |||
15c801f579 | |||
0671346ce8 | |||
0a76920800 | |||
60f8797173 | |||
3ef7f2946b | |||
dd491a7277 | |||
b00f30fe30 | |||
6c124e9bb7 | |||
aff394ae72 | |||
c0bedcb5ee | |||
159b3933fb | |||
13978449a2 | |||
a1bed2d9f2 | |||
567ab8544d | |||
b981ff0c44 | |||
0ed97877fd | |||
3ef1e7d7e0 | |||
e7a20d9b97 | |||
921569b950 | |||
44e61a2030 | |||
2133fae2cc | |||
bba35c7b14 | |||
6d9d19ce36 | |||
8a9f156235 | |||
4920d3b08e | |||
745707ee09 | |||
1bc7662be0 | |||
62eff81213 | |||
860ea1a82d | |||
65b332811f | |||
b465020111 | |||
ee9d93f137 | |||
19d668418c | |||
a3f97456bc | |||
9cb82deaf8 | |||
6ac5de06e6 | |||
0bfeabce33 | |||
6c2798c123 | |||
7a90980772 | |||
0f47f73dda | |||
772ad48961 | |||
202d265cab | |||
f4b0f006aa | |||
faf0217b52 | |||
d2028e926b | |||
44c94689c6 | |||
6cf35d5638 | |||
9a152885d8 | |||
825d3df776 | |||
6f7debc25b | |||
a02c55e16e | |||
9d243b5b35 | |||
8eae977357 | |||
42aca3c1c0 | |||
0ca330a9f0 | |||
5ec081022d | |||
c2dfe632e7 | |||
e12bf58baf | |||
76d090febf | |||
a00f6566b2 | |||
ffa659ea1d | |||
e3d1722f2c | |||
c9fe2f160a | |||
ae91334045 | |||
7ccf0957bf | |||
215d2b1290 | |||
68615d1f8d | |||
bda9b03a9f | |||
4355651695 | |||
c3c377a4e2 | |||
d3d5e3a8e5 | |||
7cf3708e4d | |||
5b9386f970 | |||
d9c4cecd48 | |||
94496910d7 | |||
fb96676bb2 | |||
0a3b523e00 | |||
2711c0258d | |||
e29108f21d | |||
f8e02dc19c | |||
9abfdd2fd9 | |||
fa2676ddb2 | |||
77933cdd9e | |||
381c6c059e | |||
720d75ee51 | |||
9823a6ad8e | |||
4c75c9469b | |||
a3f7a90e39 | |||
c7e113e325 | |||
04da662275 | |||
5fe6bd9629 | |||
a26eeb9441 | |||
5944dac053 | |||
160c381abc | |||
571782368c | |||
7ff9d45fe7 | |||
d49416a7d2 | |||
810ca49de4 | |||
959d708daf | |||
349c2992dc | |||
cb2c719b1b | |||
a48088581f | |||
0f05bc2391 | |||
f4971f1c7d | |||
9e2f7cd9e3 | |||
0f26b05443 | |||
f20ba63277 | |||
f48d6753e2 | |||
456d5afec3 | |||
fc80a63a6d | |||
95e80ab87b | |||
2105c7bc61 | |||
492796d5a8 | |||
7758dd2925 | |||
d7851a4160 | |||
42b28df07d | |||
69b27d4975 | |||
89b6f1ac8c | |||
fa8fb69f19 | |||
09d8427293 | |||
763255e727 | |||
fc2e969d77 | |||
da77807b81 | |||
4e031c7c8b | |||
9f132e7bc4 | |||
68bf73e764 | |||
1f34860cfd | |||
c54bf22942 | |||
2ae5c4ac73 | |||
c325b156bd | |||
5b4676a4c0 | |||
4c90d86509 | |||
8844463d77 | |||
65cd4ee79a | |||
66be4801f9 | |||
b71b5884d0 | |||
51e3613e40 | |||
be8fea187b | |||
0459ed561c | |||
9fb72b7840 | |||
f24ce58b85 | |||
200763725e | |||
95f56a04d3 | |||
89b127fd72 | |||
53eb536213 | |||
2d8f945cad | |||
f5f546ba95 | |||
25e585655c | |||
653bf674c9 | |||
4d922096a9 | |||
f005cb357b | |||
01ea22d089 | |||
0e13d2c418 | |||
043a699c6d | |||
094e047a5c | |||
910bf56766 | |||
d75bc6defe | |||
e07448550c | |||
0d077fb641 | |||
91dc9194e0 | |||
6d38f62e8d | |||
4273b8d490 | |||
ab0db2b320 | |||
3df81597b6 | |||
70b2f7e5cc | |||
1c31a4e5c3 |
23
.env.example
Normal file
23
.env.example
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
APP_NAME="It Guild Micro Framework"
|
||||||
|
|
||||||
|
DB_HOST=localhost
|
||||||
|
DB_USER={db_user}
|
||||||
|
DB_DRIVER=mysql
|
||||||
|
DB_PASSWORD={db_password}
|
||||||
|
DB_NAME={db_name}
|
||||||
|
DB_CHARSET=utf8mb4
|
||||||
|
DB_COLLATION=utf8mb4_unicode_ci
|
||||||
|
DB_PREFIX=''
|
||||||
|
|
||||||
|
VIEWS_PATH=/views
|
||||||
|
VIEWS_CACHE_PATH=/views_cache
|
||||||
|
|
||||||
|
MAIL_SMTP_HOST=smtp.mail.ru
|
||||||
|
MAIL_SMTP_PORT=587
|
||||||
|
MAIL_SMTP_USERNAME=username@mail.ru
|
||||||
|
MAIL_SMTP_PASSWORD=somepassword
|
||||||
|
|
||||||
|
MODULE_SHOP_URL='http://igfs.loc'
|
||||||
|
MODULE_SHOP_TOKEN='your token'
|
||||||
|
|
||||||
|
SECRET_KEY=''
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,2 +1,7 @@
|
|||||||
.idea
|
.idea
|
||||||
vendor
|
vendor
|
||||||
|
.env
|
||||||
|
views_cache
|
||||||
|
resources/upload
|
||||||
|
resources/tmp
|
||||||
|
composer.lock
|
25
README.md
Normal file
25
README.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
## Начало работы
|
||||||
|
***
|
||||||
|
|
||||||
|
Загрузка зависимостей.
|
||||||
|
### `composer install`
|
||||||
|
***
|
||||||
|
|
||||||
|
Создание переменных окружения. В файле `.env` прописать необходимые настройки приложения,
|
||||||
|
например доступы к базе данных.
|
||||||
|
### `cp .env.example .env`
|
||||||
|
***
|
||||||
|
|
||||||
|
Инициализация миграций БД приложения.
|
||||||
|
### `php console.php migration/init`
|
||||||
|
***
|
||||||
|
|
||||||
|
Развертывание админпанели приложения. Доступы по умолчанию login: `admin`, password `ChangeMe`.
|
||||||
|
**Не забудьте потом изменить пароль пользователя.**
|
||||||
|
### `php console.php admin/init`
|
||||||
|
***
|
||||||
|
|
||||||
|
Создание ключа безопасности.
|
||||||
|
### `php console.php secure/create-secret-key`
|
||||||
|
***
|
||||||
|
|
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
\kernel\App::$db->schema->table('user', function (Blueprint $table) {
|
||||||
|
$table->integer('status')->default(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
\kernel\App::$db->schema->table('user', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['status']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
34
_migrations/2024_08_30_083939_create_menu_table.php
Normal file
34
_migrations/2024_08_30_083939_create_menu_table.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Capsule\Manager;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
\kernel\App::$db->schema->create('menu', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->integer('parent_id')->default(0);
|
||||||
|
$table->string('icon_file', 255)->nullable();
|
||||||
|
$table->string('icon_font', 255)->nullable();
|
||||||
|
$table->string('label', 255);
|
||||||
|
$table->string('url', 255);
|
||||||
|
$table->integer('status')->default(1);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
\kernel\App::$db->schema->dropIfExists('menu');
|
||||||
|
}
|
||||||
|
};
|
31
_migrations/2024_09_02_155116_create_option_table.php
Normal file
31
_migrations/2024_09_02_155116_create_option_table.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
\kernel\App::$db->schema->create('option', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->string('key', 255);
|
||||||
|
$table->text('value')->nullable();
|
||||||
|
$table->string('label', 255)->nullable();
|
||||||
|
$table->integer('status')->default(1);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
\kernel\App::$db->schema->dropIfExists('option');
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
\kernel\App::$db->schema->table('menu', function (Blueprint $table) {
|
||||||
|
$table->string('slug')->unique();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
\kernel\App::$db->schema->table('menu', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['slug']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
29
_migrations/2024_09_23_092858_create_post_table.php
Normal file
29
_migrations/2024_09_23_092858_create_post_table.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
\kernel\App::$db->schema->create('post', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->text('content')->nullable(false);
|
||||||
|
$table->integer('user_id');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
\kernel\App::$db->schema->dropIfExists('post');
|
||||||
|
}
|
||||||
|
};
|
36
_migrations/PostMigration.php
Normal file
36
_migrations/PostMigration.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace _migrations;
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Capsule\Manager;
|
||||||
|
|
||||||
|
class PostMigration extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function up(): void
|
||||||
|
{
|
||||||
|
Manager::schema()->create('post', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->text('content')->nullable(false);
|
||||||
|
$table->integer('user_id');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function down(): void
|
||||||
|
{
|
||||||
|
Manager::schema()->dropIfExists('user');
|
||||||
|
}
|
||||||
|
}
|
37
_migrations/UserMigration.php
Normal file
37
_migrations/UserMigration.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
namespace _migrations;
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Capsule\Manager;
|
||||||
|
|
||||||
|
class UserMigration extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function up(): void
|
||||||
|
{
|
||||||
|
Manager::schema()->create('user', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->string('username', 255)->nullable(false);
|
||||||
|
$table->string('email', 255);
|
||||||
|
$table->string('password_hash', 255);
|
||||||
|
$table->integer('role')->default(1);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function down(): void
|
||||||
|
{
|
||||||
|
Manager::schema()->dropIfExists('user');
|
||||||
|
}
|
||||||
|
}
|
34
_migrations/menuMigration.php
Normal file
34
_migrations/menuMigration.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace _migrations;
|
||||||
|
|
||||||
|
use Illuminate\Database\Capsule\Manager;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
|
||||||
|
class menuMigration extends Migration
|
||||||
|
{
|
||||||
|
public static function up(): void
|
||||||
|
{
|
||||||
|
Manager::schema()->create('menu', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->integer('parent_id')->default(1);
|
||||||
|
$table->string('icon_file', 255)->nullable(false);
|
||||||
|
$table->string('icon_font', 255);
|
||||||
|
$table->string('label', 255);
|
||||||
|
$table->string('url', 255);
|
||||||
|
$table->integer('status')->default(1);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function down(): void
|
||||||
|
{
|
||||||
|
Manager::schema()->dropIfExists('menu');
|
||||||
|
}
|
||||||
|
}
|
28
_migrations/stubs/blank.stub
Executable file
28
_migrations/stubs/blank.stub
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class DummyClass extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
32
_migrations/stubs/create.stub
Executable file
32
_migrations/stubs/create.stub
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use core\App;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class DummyClass extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
App::$db->schema->create('DummyTable', function (Blueprint $table) {
|
||||||
|
$table->bigIncrements('id');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
App::$db->schema->dropIfExists('DummyTable');
|
||||||
|
}
|
||||||
|
}
|
33
_migrations/stubs/update.stub
Executable file
33
_migrations/stubs/update.stub
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use core\App;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class DummyClass extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
App::$db->schema->table('DummyTable', function (Blueprint $table) {
|
||||||
|
//
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
App::$db->schema->table('DummyTable', function (Blueprint $table) {
|
||||||
|
//
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
15
app/action_btn/CreateUserBtn.php
Normal file
15
app/action_btn/CreateUserBtn.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\action_btn;
|
||||||
|
|
||||||
|
use Itguild\Tables\actionBtn\ActionBtn;
|
||||||
|
|
||||||
|
class CreateUserBtn extends ActionBtn
|
||||||
|
{
|
||||||
|
protected string $prefix = "/admin/user/create";
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
return "<a class='btn btn-primary' href='$this->baseUrl$this->prefix' style='margin: 3px'>Создать</a>";
|
||||||
|
}
|
||||||
|
}
|
75
app/admin_themes/custom/layout/main.php
Executable file
75
app/admin_themes/custom/layout/main.php
Executable file
@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var $content
|
||||||
|
* @var string $resources
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Custom</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900" rel="stylesheet">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
|
||||||
|
<link rel="stylesheet" href="<?=$resources?>/css/style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="wrapper d-flex align-items-stretch">
|
||||||
|
<nav id="sidebar">
|
||||||
|
<div class="p-4 pt-5">
|
||||||
|
<a href="#" class="img logo rounded-circle mb-5" style="background-image: url(/resources/admin_theme/images/logo.jpg);"></a>
|
||||||
|
<?php \kernel\widgets\MenuWidget::create()->run(); ?>
|
||||||
|
<div class="footer">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- Page Content -->
|
||||||
|
<div id="content" class="p-4 p-md-5">
|
||||||
|
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
|
<div class="container-fluid">
|
||||||
|
|
||||||
|
<button type="button" id="sidebarCollapse" class="btn btn-primary">
|
||||||
|
<i class="fa fa-bars"></i>
|
||||||
|
<span class="sr-only">Toggle Menu</span>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-dark d-inline-block d-lg-none ml-auto" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<i class="fa fa-bars"></i>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||||
|
<ul class="nav navbar-nav ml-auto">
|
||||||
|
<li class="nav-item active">
|
||||||
|
<a class="nav-link" href="#">Главня</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">О нас</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">Портфолио</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">Контакты</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<?= $content ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="<?=$resources?>/js/jquery.min.js"></script>
|
||||||
|
<script src="<?=$resources?>/js/popper.js"></script>
|
||||||
|
<script src="<?=$resources?>/js/bootstrap.min.js"></script>
|
||||||
|
<script src="<?=$resources?>/js/main.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
14
app/admin_themes/custom/manifest.json
Executable file
14
app/admin_themes/custom/manifest.json
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "Custom",
|
||||||
|
"version": "0.1",
|
||||||
|
"author": "Kavalar",
|
||||||
|
"slug": "custom",
|
||||||
|
"type": "admin_theme",
|
||||||
|
"description": "Custom admin theme",
|
||||||
|
"preview": "nrnv2024_640x360.jpg",
|
||||||
|
"resource": "/resources/admin_themes/custom",
|
||||||
|
"resource_path": "{RESOURCES}/admin_themes/custom",
|
||||||
|
"layout": "main.php",
|
||||||
|
"theme_path": "{APP}/admin_themes/{slug}",
|
||||||
|
"layout_path": "{APP}/admin_themes/{slug}/layout"
|
||||||
|
}
|
@ -1,32 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace app\controllers;
|
|
||||||
|
|
||||||
|
|
||||||
use app\models\Answer;
|
|
||||||
use app\models\Upvote;
|
|
||||||
|
|
||||||
class AnswerController {
|
|
||||||
public function actionAddAnswer($answer,$question_id,$user_id)
|
|
||||||
{
|
|
||||||
return Answer::create(['answer'=>$answer,'question_id'=>$question_id,'user_id'=>$user_id]);
|
|
||||||
}
|
|
||||||
public static function actionUpvoteAnswer($answer_id,$user_id)
|
|
||||||
{
|
|
||||||
return Upvote::create(['answer_id'=>$answer_id,'user_id'=>$user_id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function actionUpdateAnswer($answer_id,$new_answer)
|
|
||||||
{
|
|
||||||
$answer = Answer::find($answer_id);
|
|
||||||
$answer->answer = $new_answer;
|
|
||||||
return $answer->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function actionViewAllAnswers(): void
|
|
||||||
{
|
|
||||||
foreach (Answer::all() as $answer)
|
|
||||||
{
|
|
||||||
echo $answer->answer . "<br>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace app\controllers;
|
|
||||||
|
|
||||||
|
|
||||||
use app\helpers\Debug;
|
|
||||||
use app\models\Post;
|
|
||||||
|
|
||||||
class PostController
|
|
||||||
{
|
|
||||||
public function actionCreatePost($post, $user_id)
|
|
||||||
{
|
|
||||||
return Post::create(['post'=>$post, 'user_id'=>$user_id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function actionIndex(): void
|
|
||||||
{
|
|
||||||
Debug::dd("Post list");
|
|
||||||
foreach (Post::all() as $post)
|
|
||||||
{
|
|
||||||
echo $post->post . "<br>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace app\controllers;
|
|
||||||
|
|
||||||
use app\models\Question;
|
|
||||||
|
|
||||||
class QuestionController{
|
|
||||||
public function actionCreateQuestion($question,$user_id)
|
|
||||||
{
|
|
||||||
return Question::create(['question'=>$question,'user_id'=>$user_id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function actionGetQuestionsWithAnswers()
|
|
||||||
{
|
|
||||||
return Question::with('AnswerController')->get()->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function actionGetQuestionsWithUsers()
|
|
||||||
{
|
|
||||||
return Question::with('user')->get()->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function actionGetQuestionAnswersUpvotes($question_id)
|
|
||||||
{
|
|
||||||
return Question::find($question_id)->answers()->with('upvotes')->get()->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function actionViewAllQuestions()
|
|
||||||
{
|
|
||||||
foreach (Question::all() as $question)
|
|
||||||
{
|
|
||||||
echo $question->question. "<br>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace app\controllers;
|
|
||||||
|
|
||||||
|
|
||||||
use app\helpers\Debug;
|
|
||||||
use app\models\Question;
|
|
||||||
use app\models\User;
|
|
||||||
use http\Encoding\Stream\Debrotli;
|
|
||||||
use Illuminate\Contracts\View\View;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
||||||
|
|
||||||
class UserController {
|
|
||||||
public function actionCreate(): void
|
|
||||||
{
|
|
||||||
require "app/views/userCreate.php";
|
|
||||||
}
|
|
||||||
|
|
||||||
public function actionAdd(): void
|
|
||||||
{
|
|
||||||
User::create($_REQUEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function actionQuestionCount($user_id)
|
|
||||||
{
|
|
||||||
return Question::where('user_id', $user_id)->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function actionIndex(): void
|
|
||||||
{
|
|
||||||
foreach (User::all() as $user)
|
|
||||||
{
|
|
||||||
echo $user->username . "<br>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function actionView($id): void
|
|
||||||
{
|
|
||||||
echo User::where('id', '=', $id)->get();
|
|
||||||
echo User::where('id', '=', $id)->first() . "<br><br>";
|
|
||||||
|
|
||||||
$user = User::find($id);
|
|
||||||
echo $user->id . "<br>";
|
|
||||||
echo $user->username . "<br>";
|
|
||||||
echo $user->email . "<br>";
|
|
||||||
echo $user->password . "<br>";
|
|
||||||
echo $user->created_at . "<br>";
|
|
||||||
echo $user->updated_at . "<br>";
|
|
||||||
}
|
|
||||||
|
|
||||||
public function actionUpdate(): void
|
|
||||||
{
|
|
||||||
Debug::prn("Update");
|
|
||||||
require "app/views/userUpdate.php";
|
|
||||||
}
|
|
||||||
|
|
||||||
public function actionEdit(): void
|
|
||||||
{
|
|
||||||
$user = User::find($_REQUEST['id']);
|
|
||||||
$user->username = $_REQUEST['username'];
|
|
||||||
$user->email = $_REQUEST['email'];
|
|
||||||
$user->password = $_REQUEST['password'];
|
|
||||||
$user->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function actionDelete($id): void
|
|
||||||
{
|
|
||||||
User::find($id)->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace app\models;
|
|
||||||
|
|
||||||
use \Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class Answer extends Model {
|
|
||||||
protected $table = 'AnswerController';
|
|
||||||
protected $fillable = ['answer','user_id','question_id'];
|
|
||||||
|
|
||||||
public function upvotes()
|
|
||||||
{
|
|
||||||
return $this->hasMany('\Models\Upvote');
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace app\models;
|
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
||||||
|
|
||||||
class Database {
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$capsule = new Capsule;
|
|
||||||
$capsule->addConnection([
|
|
||||||
'driver' => DBDRIVER,
|
|
||||||
'host' => DBHOST,
|
|
||||||
'database' => DBNAME,
|
|
||||||
'username' => DBUSER,
|
|
||||||
'password' => DBPASS,
|
|
||||||
'charset' => 'utf8',
|
|
||||||
'collation' => 'utf8_unicode_ci',
|
|
||||||
'prefix' => '',
|
|
||||||
]);
|
|
||||||
// Setup the Eloquent ORM…
|
|
||||||
$capsule->bootEloquent();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace app\models;
|
|
||||||
use \Illuminate\Database\Eloquent\Model;
|
|
||||||
class Post extends Model
|
|
||||||
{
|
|
||||||
protected $table = 'Posts';
|
|
||||||
protected $fillable = ['post', 'user_id'];
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace app\models;
|
|
||||||
|
|
||||||
use \Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class Question extends Model {
|
|
||||||
protected $table = 'Questions';
|
|
||||||
protected $fillable = ['question','user_id'];
|
|
||||||
|
|
||||||
public function answers()
|
|
||||||
{
|
|
||||||
return $this->hasMany('\Models\Answer');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function user()
|
|
||||||
{
|
|
||||||
return $this->belongsTo('\Models\User');
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace app\models;
|
|
||||||
|
|
||||||
use \Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class Upvote extends Model {
|
|
||||||
protected $table = 'Upvotes';
|
|
||||||
protected $fillable = ['answer_id', 'user_id'];
|
|
||||||
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace app\models;
|
|
||||||
use \Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class User extends Model {
|
|
||||||
protected $table = 'Users';
|
|
||||||
protected $fillable = ['username', 'email', 'password'];
|
|
||||||
protected $dates = ['deleted at'];
|
|
||||||
}
|
|
8
app/modules/photo/PhotoModule.php
Normal file
8
app/modules/photo/PhotoModule.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\modules\photo;
|
||||||
|
|
||||||
|
class PhotoModule extends \kernel\app_modules\photo\PhotoModule
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
8
app/modules/photo/controllers/PhotoController.php
Normal file
8
app/modules/photo/controllers/PhotoController.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\modules\photo\controllers;
|
||||||
|
|
||||||
|
class PhotoController extends \kernel\app_modules\photo\controllers\PhotoController
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
13
app/modules/photo/manifest.json
Normal file
13
app/modules/photo/manifest.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "Photo",
|
||||||
|
"version": "0.2",
|
||||||
|
"author": "ITGuild",
|
||||||
|
"slug": "photo",
|
||||||
|
"type": "additional_property",
|
||||||
|
"description": "Photo module",
|
||||||
|
"app_module_path": "{APP}/modules/{slug}",
|
||||||
|
"module_class": "app\\modules\\photo\\PhotoModule",
|
||||||
|
"module_class_file": "{APP}/modules/photo/PhotoModule.php",
|
||||||
|
"routs": "routs/photo.php",
|
||||||
|
"dependence": "menu"
|
||||||
|
}
|
2
app/modules/photo/routs/photo.php
Normal file
2
app/modules/photo/routs/photo.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<?php
|
||||||
|
include KERNEL_APP_MODULES_DIR . "/photo/routs/photo.php";
|
8
app/modules/tag/TagModule.php
Normal file
8
app/modules/tag/TagModule.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\modules\tag;
|
||||||
|
|
||||||
|
class TagModule extends \kernel\app_modules\tag\TagModule
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
8
app/modules/tag/controllers/TagController.php
Normal file
8
app/modules/tag/controllers/TagController.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\modules\tag\controllers;
|
||||||
|
|
||||||
|
class TagController extends \kernel\app_modules\tag\controllers\TagController
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
13
app/modules/tag/manifest.json
Normal file
13
app/modules/tag/manifest.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "Tags",
|
||||||
|
"version": "0.1.1",
|
||||||
|
"author": "ITGuild",
|
||||||
|
"slug": "tag",
|
||||||
|
"type": "additional_property",
|
||||||
|
"description": "Tags module",
|
||||||
|
"app_module_path": "{APP}/modules/{slug}",
|
||||||
|
"module_class": "app\\modules\\tag\\TagModule",
|
||||||
|
"module_class_file": "{APP}/modules/tag/TagModule.php",
|
||||||
|
"routs": "routs/tag.php",
|
||||||
|
"dependence": "menu"
|
||||||
|
}
|
2
app/modules/tag/routs/tag.php
Normal file
2
app/modules/tag/routs/tag.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<?php
|
||||||
|
include KERNEL_APP_MODULES_DIR . "/tag/routs/tag.php";
|
8
app/themes/custom/CustomTheme.php
Normal file
8
app/themes/custom/CustomTheme.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\themes\custom;
|
||||||
|
|
||||||
|
class CustomTheme extends \kernel\app_themes\custom\CustomTheme
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
18
app/themes/custom/assets/CustomThemesAssets.php
Normal file
18
app/themes/custom/assets/CustomThemesAssets.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\themes\custom\assets;
|
||||||
|
|
||||||
|
use kernel\Assets;
|
||||||
|
|
||||||
|
class CustomThemesAssets extends Assets
|
||||||
|
{
|
||||||
|
protected function createCSS(): void
|
||||||
|
{
|
||||||
|
$this->registerCSS(slug: "main", resource: "/css/styles.css");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createJS(): void
|
||||||
|
{
|
||||||
|
$this->registerJS(slug: "webpack", resource: "/js/scripts.js");
|
||||||
|
}
|
||||||
|
}
|
28
app/themes/custom/controllers/MainController.php
Normal file
28
app/themes/custom/controllers/MainController.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\themes\custom\controllers;
|
||||||
|
|
||||||
|
use kernel\Controller;
|
||||||
|
|
||||||
|
class MainController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function init(): void
|
||||||
|
{
|
||||||
|
parent::init();
|
||||||
|
$this->cgView->viewPath = APP_DIR . "/themes/custom/views/main/";
|
||||||
|
$this->cgView->layout = "main.php";
|
||||||
|
$this->cgView->layoutPath = APP_DIR . "/themes/custom/views/layout/";
|
||||||
|
$this->cgView->addVarToLayout("resources", "/resources/themes/custom");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionIndex(): void
|
||||||
|
{
|
||||||
|
$this->cgView->render("index.php");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionAbout(): void
|
||||||
|
{
|
||||||
|
$this->cgView->render("about.php");
|
||||||
|
}
|
||||||
|
}
|
15
app/themes/custom/manifest.json
Normal file
15
app/themes/custom/manifest.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "Custom",
|
||||||
|
"version": "0.1",
|
||||||
|
"author": "ItGuild",
|
||||||
|
"slug": "custom",
|
||||||
|
"type": "theme",
|
||||||
|
"description": "Custom theme",
|
||||||
|
"preview": "preview.png",
|
||||||
|
"resource": "/resources/themes/custom",
|
||||||
|
"resource_path": "{RESOURCES}/themes/custom",
|
||||||
|
"theme_class": "app\\themes\\custom\\CustomTheme",
|
||||||
|
"theme_class_file": "{APP}/themes/custom/CustomTheme.php",
|
||||||
|
"routs": "routs/custom.php",
|
||||||
|
"dependence": "photo,tag"
|
||||||
|
}
|
12
app/themes/custom/routs/custom.php
Normal file
12
app/themes/custom/routs/custom.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use kernel\App;
|
||||||
|
|
||||||
|
|
||||||
|
App::$collector->get('/', [\app\themes\custom\controllers\MainController::class, 'actionIndex']);
|
||||||
|
App::$collector->get('/about', [\app\themes\custom\controllers\MainController::class, 'actionAbout']);
|
||||||
|
//App::$collector->get('/page/{page_number}', [\app\modules\tag\controllers\TagController::class, 'actionIndex']);
|
||||||
|
//App::$collector->get('/create', [\app\modules\tag\controllers\TagController::class, 'actionCreate']);
|
||||||
|
|
||||||
|
|
||||||
|
|
92
app/themes/custom/views/layout/main.php
Normal file
92
app/themes/custom/views/layout/main.php
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var string $content
|
||||||
|
* @var string $resources
|
||||||
|
* @var string $title
|
||||||
|
* @var \kernel\CgView $view
|
||||||
|
*/
|
||||||
|
$assets = new \app\themes\custom\assets\CustomThemesAssets($resources);
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
|
||||||
|
<?php $assets->getCSSAsSTR(); ?>
|
||||||
|
<meta name="description" content=""/>
|
||||||
|
<meta name="author" content=""/>
|
||||||
|
<title><?= $title ?></title>
|
||||||
|
<?= $view->getMeta() ?>
|
||||||
|
<link rel="icon" type="image/x-icon" href="<?= $resources ?>/assets/favicon.ico"/>
|
||||||
|
<!-- Font Awesome icons (free version)-->
|
||||||
|
<script src="https://use.fontawesome.com/releases/v6.3.0/js/all.js" crossorigin="anonymous"></script>
|
||||||
|
<!-- Google fonts-->
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" rel="stylesheet"
|
||||||
|
type="text/css"/>
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800"
|
||||||
|
rel="stylesheet" type="text/css"/>
|
||||||
|
<!-- Core theme CSS (includes Bootstrap)-->
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!-- Navigation-->
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light" id="mainNav">
|
||||||
|
<div class="container px-4 px-lg-5">
|
||||||
|
<a class="navbar-brand" href="/">Custom theme</a>
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarResponsive"
|
||||||
|
aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
Menu
|
||||||
|
<i class="fas fa-bars"></i>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarResponsive">
|
||||||
|
<ul class="navbar-nav ms-auto py-4 py-lg-0">
|
||||||
|
<li class="nav-item"><a class="nav-link px-lg-3 py-3 py-lg-4" href="/">На главную</a></li>
|
||||||
|
<li class="nav-item"><a class="nav-link px-lg-3 py-3 py-lg-4" href="/about">О нас</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<?= $content ?>
|
||||||
|
|
||||||
|
<!-- Footer-->
|
||||||
|
<footer class="border-top">
|
||||||
|
<div class="container px-4 px-lg-5">
|
||||||
|
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||||
|
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||||
|
<ul class="list-inline text-center">
|
||||||
|
<li class="list-inline-item">
|
||||||
|
<a href="#!">
|
||||||
|
<span class="fa-stack fa-lg">
|
||||||
|
<i class="fas fa-circle fa-stack-2x"></i>
|
||||||
|
<i class="fab fa-twitter fa-stack-1x fa-inverse"></i>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="list-inline-item">
|
||||||
|
<a href="#!">
|
||||||
|
<span class="fa-stack fa-lg">
|
||||||
|
<i class="fas fa-circle fa-stack-2x"></i>
|
||||||
|
<i class="fab fa-facebook-f fa-stack-1x fa-inverse"></i>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="list-inline-item">
|
||||||
|
<a href="#!">
|
||||||
|
<span class="fa-stack fa-lg">
|
||||||
|
<i class="fas fa-circle fa-stack-2x"></i>
|
||||||
|
<i class="fab fa-github fa-stack-1x fa-inverse"></i>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<div class="small text-center text-muted fst-italic">Copyright © IT Guild Micro Framework</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
<!-- Bootstrap core JS-->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<!-- Core theme JS-->
|
||||||
|
<?php $assets->getJSAsStr(); ?>
|
||||||
|
</body>
|
||||||
|
</html>
|
36
app/themes/custom/views/main/about.php
Normal file
36
app/themes/custom/views/main/about.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var string $resources;
|
||||||
|
* @var \kernel\CgView $view
|
||||||
|
*/
|
||||||
|
|
||||||
|
$view->setTitle("Старт Bootstrap");
|
||||||
|
$view->setMeta([
|
||||||
|
'description' => 'Дефолтная bootstrap тема'
|
||||||
|
]);
|
||||||
|
?>
|
||||||
|
<!-- Page Header-->
|
||||||
|
<header class="masthead" style="background-image: url('<?= $resources ?>/assets/img/about-bg.jpeg')">
|
||||||
|
<div class="container position-relative px-4 px-lg-5">
|
||||||
|
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||||
|
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||||
|
<div class="page-heading">
|
||||||
|
<h1>About Me</h1>
|
||||||
|
<span class="subheading">This is what I do.</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<!-- Main Content-->
|
||||||
|
<main class="mb-4">
|
||||||
|
<div class="container px-4 px-lg-5">
|
||||||
|
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||||
|
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||||
|
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Saepe nostrum ullam eveniet pariatur voluptates odit, fuga atque ea nobis sit soluta odio, adipisci quas excepturi maxime quae totam ducimus consectetur?</p>
|
||||||
|
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eius praesentium recusandae illo eaque architecto error, repellendus iusto reprehenderit, doloribus, minus sunt. Numquam at quae voluptatum in officia voluptas voluptatibus, minus!</p>
|
||||||
|
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut consequuntur magnam, excepturi aliquid ex itaque esse est vero natus quae optio aperiam soluta voluptatibus corporis atque iste neque sit tempora!</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
86
app/themes/custom/views/main/index.php
Normal file
86
app/themes/custom/views/main/index.php
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var string $resources;
|
||||||
|
* @var \kernel\CgView $view
|
||||||
|
*/
|
||||||
|
|
||||||
|
$view->setTitle("IT Guild Micro Framework");
|
||||||
|
$view->setMeta([
|
||||||
|
'description' => 'Default IT Guild Micro Framework theme'
|
||||||
|
]);
|
||||||
|
?>
|
||||||
|
<!-- Page Header-->
|
||||||
|
<header class="masthead" style="background-image: url('<?= $resources ?>/assets/img/home-bg.jpeg')">
|
||||||
|
<div class="container position-relative px-4 px-lg-5">
|
||||||
|
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||||
|
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||||
|
<div class="site-heading">
|
||||||
|
<h1>Clean Blog</h1>
|
||||||
|
<span class="subheading">A Blog Theme by IT Guild Micro Framework</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<!-- Main Content-->
|
||||||
|
<div class="container px-4 px-lg-5">
|
||||||
|
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||||
|
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||||
|
<!-- Post preview-->
|
||||||
|
<div class="post-preview">
|
||||||
|
<a href="#!">
|
||||||
|
<h2 class="post-title">Man must explore, and this is exploration at its greatest</h2>
|
||||||
|
<h3 class="post-subtitle">Problems look mighty small from 150 miles up</h3>
|
||||||
|
</a>
|
||||||
|
<p class="post-meta">
|
||||||
|
Posted by
|
||||||
|
<a href="#!">Start Bootstrap</a>
|
||||||
|
on September 24, 2023
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<!-- Divider-->
|
||||||
|
<hr class="my-4" />
|
||||||
|
<!-- Post preview-->
|
||||||
|
<div class="post-preview">
|
||||||
|
<a href="#!"><h2 class="post-title">I believe every human has a finite number of heartbeats. I don't intend to waste any of mine.</h2></a>
|
||||||
|
<p class="post-meta">
|
||||||
|
Posted by
|
||||||
|
<a href="#!">Start Bootstrap</a>
|
||||||
|
on September 18, 2023
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<!-- Divider-->
|
||||||
|
<hr class="my-4" />
|
||||||
|
<!-- Post preview-->
|
||||||
|
<div class="post-preview">
|
||||||
|
<a href="#!">
|
||||||
|
<h2 class="post-title">Science has not yet mastered prophecy</h2>
|
||||||
|
<h3 class="post-subtitle">We predict too much for the next year and yet far too little for the next ten.</h3>
|
||||||
|
</a>
|
||||||
|
<p class="post-meta">
|
||||||
|
Posted by
|
||||||
|
<a href="#!">Start Bootstrap</a>
|
||||||
|
on August 24, 2023
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<!-- Divider-->
|
||||||
|
<hr class="my-4" />
|
||||||
|
<!-- Post preview-->
|
||||||
|
<div class="post-preview">
|
||||||
|
<a href="#!">
|
||||||
|
<h2 class="post-title">Failure is not an option</h2>
|
||||||
|
<h3 class="post-subtitle">Many say exploration is part of our destiny, but it’s actually our duty to future generations.</h3>
|
||||||
|
</a>
|
||||||
|
<p class="post-meta">
|
||||||
|
Posted by
|
||||||
|
<a href="#!">Start Bootstrap</a>
|
||||||
|
on July 8, 2023
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<!-- Divider-->
|
||||||
|
<hr class="my-4" />
|
||||||
|
<!-- Pager-->
|
||||||
|
<div class="d-flex justify-content-end mb-4"><a class="btn btn-primary text-uppercase" href="#!">Older Posts →</a></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -1,19 +0,0 @@
|
|||||||
<form action="/admin/user/" method="post">
|
|
||||||
Логин:<br>
|
|
||||||
<label>
|
|
||||||
<input type = "text" name = "username" required size="50" autofocus placeholder="Логин">
|
|
||||||
</label> <br> <br>
|
|
||||||
|
|
||||||
Пароль:<br>
|
|
||||||
<label>
|
|
||||||
<input type = "text" name = "password" required size="50" placeholder="Пароль">
|
|
||||||
</label> <br> <br>
|
|
||||||
|
|
||||||
Email адрес: <br>
|
|
||||||
<label>
|
|
||||||
<input type="Email" name="email" required>
|
|
||||||
</label> <br><br>
|
|
||||||
|
|
||||||
<input type = "submit" value="Подтвердить">
|
|
||||||
<input type="reset">
|
|
||||||
</form>
|
|
@ -1,24 +0,0 @@
|
|||||||
<form action="/admin/user/edit" method="post">
|
|
||||||
id пользователя:<br>
|
|
||||||
<label>
|
|
||||||
<input type = "text" name = "id" required size="50" autofocus placeholder="id">
|
|
||||||
</label> <br> <br>
|
|
||||||
|
|
||||||
Логин:<br>
|
|
||||||
<label>
|
|
||||||
<input type = "text" name = "username" required size="50" autofocus placeholder="Логин">
|
|
||||||
</label> <br> <br>
|
|
||||||
|
|
||||||
Пароль:<br>
|
|
||||||
<label>
|
|
||||||
<input type = "text" name = "password" required size="50" placeholder="Пароль">
|
|
||||||
</label> <br> <br>
|
|
||||||
|
|
||||||
Email адрес: <br>
|
|
||||||
<label>
|
|
||||||
<input type="Email" name="email" required>
|
|
||||||
</label> <br><br>
|
|
||||||
|
|
||||||
<input type = "submit" value="Подтвердить">
|
|
||||||
<input type="reset">
|
|
||||||
</form>
|
|
@ -1,8 +1,47 @@
|
|||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . "/vendor/autoload.php";
|
||||||
|
|
||||||
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
||||||
|
$dotenv->load();
|
||||||
|
|
||||||
|
include_once __DIR__ . "/bootstrap/db.php";
|
||||||
|
include_once __DIR__ . "/bootstrap/header.php";
|
||||||
|
include_once __DIR__ . "/bootstrap/secure.php";
|
||||||
|
const ROOT_DIR = __DIR__;
|
||||||
|
const KERNEL_DIR = __DIR__ . "/kernel";
|
||||||
|
const KERNEL_MODULES_DIR = __DIR__ . "/kernel/modules";
|
||||||
|
const KERNEL_ADMIN_THEMES_DIR = __DIR__ . "/kernel/admin_themes";
|
||||||
|
const CONSOLE_DIR = __DIR__ . "/kernel/console";
|
||||||
|
const RESOURCES_DIR = __DIR__ . "/resources";
|
||||||
|
const KERNEL_TEMPLATES_DIR = __DIR__ . "/kernel/templates";
|
||||||
|
const KERNEL_APP_MODULES_DIR = KERNEL_DIR . "/app_modules";
|
||||||
|
|
||||||
|
const APP_DIR = ROOT_DIR . "/app";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getConst($text): array|false|string
|
||||||
|
{
|
||||||
|
$constStr = [
|
||||||
|
"{ROOT}" => ROOT_DIR,
|
||||||
|
"{RESOURCES}" => RESOURCES_DIR,
|
||||||
|
"{KERNEL_ADMIN_THEMES}" => KERNEL_ADMIN_THEMES_DIR,
|
||||||
|
"{KERNEL}" => KERNEL_DIR,
|
||||||
|
"{KERNEL_MODULES}" => KERNEL_MODULES_DIR,
|
||||||
|
"{KERNEL_APP_MODULES}" => KERNEL_APP_MODULES_DIR,
|
||||||
|
"{KERNEL_TEMPLATES}" => KERNEL_TEMPLATES_DIR,
|
||||||
|
"{CONSOLE}" => CONSOLE_DIR,
|
||||||
|
"{APP}" => APP_DIR,
|
||||||
|
];
|
||||||
|
|
||||||
|
$str = $text;
|
||||||
|
|
||||||
|
foreach($constStr as $key => $value)
|
||||||
|
{
|
||||||
|
$str = str_replace($key, $value, $str);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
use app\models\Database;
|
|
||||||
|
|
||||||
require './config.php';
|
|
||||||
require './vendor/autoload.php';
|
|
||||||
// initialize Illuminate database connection
|
|
||||||
new Database();
|
|
3
bootstrap/db.php
Normal file
3
bootstrap/db.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
\kernel\App::$db = new \kernel\Database();
|
3
bootstrap/header.php
Normal file
3
bootstrap/header.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
\kernel\App::$header = new \kernel\Header();
|
9
bootstrap/secure.php
Normal file
9
bootstrap/secure.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$secure_config = [
|
||||||
|
'web_auth_type' => 'login_password', // login_password, email_code
|
||||||
|
'token_type' => 'hash', // random_bytes, md5, crypt, hash, JWT
|
||||||
|
'token_expired_time' => "+30 days", // +1 day
|
||||||
|
];
|
||||||
|
|
||||||
|
\kernel\App::$secure = $secure_config;
|
@ -3,13 +3,31 @@
|
|||||||
"description": "Implementation of Database Queries with illuminate and Eloquent",
|
"description": "Implementation of Database Queries with illuminate and Eloquent",
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"require": {
|
"require": {
|
||||||
"illuminate/database": "^11.14",
|
"illuminate/database": "11.21",
|
||||||
|
"illuminate/filesystem": "11.21",
|
||||||
"craft-group/phroute": "^2.1",
|
"craft-group/phroute": "^2.1",
|
||||||
"ext-http": "*"
|
"vlucas/phpdotenv": "^5.6",
|
||||||
|
"twig/twig": "^3.0",
|
||||||
|
"twbs/bootstrap": "5.0.2",
|
||||||
|
"itguild/tables": "^1.0",
|
||||||
|
"madesimple/php-form-validator": "^2.9",
|
||||||
|
"itguild/forms": "^0.1.1",
|
||||||
|
"samejack/php-argv": "dev-master",
|
||||||
|
"itguild/eloquent-table": "^0.4.1",
|
||||||
|
"ext-zip": "*",
|
||||||
|
"josantonius/session": "^2.0",
|
||||||
|
"firebase/php-jwt": "^6.10",
|
||||||
|
"k-adam/env-editor": "^2.0",
|
||||||
|
"guzzlehttp/guzzle": "^7.9",
|
||||||
|
"phpmailer/phpmailer": "^6.9",
|
||||||
|
"zircote/swagger-php": "^4.11",
|
||||||
|
"doctrine/annotations": "^2.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"app\\": "app/"
|
"app\\": "app/",
|
||||||
|
"migrations\\": "migrations/",
|
||||||
|
"kernel\\": "kernel/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1408
composer.lock
generated
1408
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +0,0 @@
|
|||||||
<?php
|
|
||||||
defined('DBDRIVER') or define('DBDRIVER','mysql');
|
|
||||||
defined('DBHOST') or define('DBHOST','localhost');
|
|
||||||
defined('DBNAME') or define('DBNAME','Test');
|
|
||||||
defined('DBUSER') or define('DBUSER','test');
|
|
||||||
defined('DBPASS') or define('DBPASS','root');
|
|
6
console.php
Normal file
6
console.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once "vendor/autoload.php";
|
||||||
|
require 'bootstrap.php';
|
||||||
|
|
||||||
|
\kernel\console\ConsoleApp::create()->setArgv($argv)->load()->run();
|
40
index.php
40
index.php
@ -6,42 +6,4 @@ ini_set("display_errors", true);
|
|||||||
require_once "vendor/autoload.php";
|
require_once "vendor/autoload.php";
|
||||||
require 'bootstrap.php';
|
require 'bootstrap.php';
|
||||||
|
|
||||||
use app\controllers\MainController;
|
\kernel\App::create()->load()->run();
|
||||||
use app\controllers\UserController;
|
|
||||||
use app\controllers\QuestionController;
|
|
||||||
use app\controllers\AnswerController;
|
|
||||||
use app\controllers\PostController;
|
|
||||||
use app\helpers\Debug;
|
|
||||||
use Phroute\Phroute\RouteCollector;
|
|
||||||
|
|
||||||
|
|
||||||
$router = new RouteCollector();
|
|
||||||
$router->get('/', [MainController::class, 'actionIndex']);
|
|
||||||
$router->get('/example', [MainController::class, 'actionExample']);
|
|
||||||
$router->group(["prefix" => "admin"], function (RouteCollector $router){
|
|
||||||
$router->group(["prefix" => "user"], function (RouteCollector $router){
|
|
||||||
$router->get('/create', [\app\controllers\UserController::class, 'actionCreate']);
|
|
||||||
$router->get('/update', [\app\controllers\UserController::class, 'actionUpdate']);
|
|
||||||
$router->get('/delete/{id}', [\app\controllers\UserController::class, 'actionDelete']);
|
|
||||||
$router->get('/', [\app\controllers\UserController::class, 'actionIndex']);
|
|
||||||
$router->get('/{id}', [\app\controllers\UserController::class, 'actionView']);
|
|
||||||
$router->post("/", [\app\controllers\UserController::class, 'actionAdd']);
|
|
||||||
$router->post("/edit", [\app\controllers\UserController::class, 'actionEdit']);
|
|
||||||
});
|
|
||||||
$router->group(["prefix" => "post"], function (RouteCollector $router){
|
|
||||||
$router->get('/', [\app\controllers\PostController::class, 'actionIndex']);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$router->get('/allQuestions', [QuestionController::class, 'actionViewAllQuestions']);
|
|
||||||
|
|
||||||
$router->get('/allAnswers', [AnswerController::class, 'actionViewAllAnswers']);
|
|
||||||
|
|
||||||
|
|
||||||
$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;
|
|
26
kernel/AdminController.php
Normal file
26
kernel/AdminController.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
use kernel\Controller;
|
||||||
|
use kernel\helpers\Debug;
|
||||||
|
use kernel\services\AdminThemeService;
|
||||||
|
use kernel\services\ThemeService;
|
||||||
|
|
||||||
|
class AdminController extends Controller
|
||||||
|
{
|
||||||
|
protected AdminThemeService $adminThemeService;
|
||||||
|
protected ThemeService $themeService;
|
||||||
|
|
||||||
|
protected function init(): void
|
||||||
|
{
|
||||||
|
$this->adminThemeService = new AdminThemeService();
|
||||||
|
$this->themeService = new ThemeService();
|
||||||
|
$active_theme = $this->adminThemeService->getActiveAdminThemeInfo();
|
||||||
|
$this->cgView->layoutPath = getConst($active_theme['layout_path']);
|
||||||
|
$this->cgView->layout = "/" . $active_theme['layout'];
|
||||||
|
|
||||||
|
$this->cgView->addVarToLayout("resources", $active_theme['resource']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
72
kernel/App.php
Normal file
72
kernel/App.php
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
use kernel\helpers\Debug;
|
||||||
|
use kernel\modules\user\models\User;
|
||||||
|
use kernel\services\ModuleService;
|
||||||
|
use kernel\services\ThemeService;
|
||||||
|
use Phroute\Phroute\Dispatcher;
|
||||||
|
|
||||||
|
class App
|
||||||
|
{
|
||||||
|
|
||||||
|
static string $responseType = ResponseType::TEXT_HTML;
|
||||||
|
|
||||||
|
static CgRouteCollector $collector;
|
||||||
|
|
||||||
|
static Header $header;
|
||||||
|
|
||||||
|
static User $user;
|
||||||
|
|
||||||
|
static array $secure;
|
||||||
|
|
||||||
|
public ModuleService $moduleService;
|
||||||
|
|
||||||
|
public ThemeService $themeService;
|
||||||
|
|
||||||
|
public static Database $db;
|
||||||
|
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
$dispatcher = new Dispatcher(App::$collector->getData());
|
||||||
|
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
|
||||||
|
App::$header->set();
|
||||||
|
|
||||||
|
//header('Content-Type: ' . App::$responseType);
|
||||||
|
echo $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function load(): static
|
||||||
|
{
|
||||||
|
$this->moduleService = new ModuleService();
|
||||||
|
App::$collector = new CgRouteCollector();
|
||||||
|
$this->setRouting();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRouting(): void
|
||||||
|
{
|
||||||
|
include KERNEL_DIR . "/routs/admin.php";
|
||||||
|
include ROOT_DIR . "/rout.php";
|
||||||
|
$modules_routs = $this->moduleService->getModulesRouts();
|
||||||
|
foreach ($modules_routs as $rout){
|
||||||
|
include "$rout";
|
||||||
|
}
|
||||||
|
|
||||||
|
$themeService = new ThemeService();
|
||||||
|
$activeTheme = getConst($themeService->getActiveTheme());
|
||||||
|
if (!empty($activeTheme)){
|
||||||
|
include $activeTheme . "/" . $themeService->getThemeRout($activeTheme);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function create(): App
|
||||||
|
{
|
||||||
|
return new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
66
kernel/Assets.php
Normal file
66
kernel/Assets.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
class Assets
|
||||||
|
{
|
||||||
|
protected array $jsHeader = [];
|
||||||
|
protected array $jsBody = [];
|
||||||
|
|
||||||
|
protected array $css = [];
|
||||||
|
|
||||||
|
protected string $resourceURI = "/resource";
|
||||||
|
|
||||||
|
public function __construct(string $resourceURI)
|
||||||
|
{
|
||||||
|
$this->setResourceURI($resourceURI);
|
||||||
|
$this->createCSS();
|
||||||
|
$this->createJS();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createCSS(){}
|
||||||
|
protected function createJS(){}
|
||||||
|
|
||||||
|
public function setResourceURI(string $resourceURI): void
|
||||||
|
{
|
||||||
|
$this->resourceURI = $resourceURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerJS(string $slug, string $resource, bool $body = true, bool $addResourceURI = true): void
|
||||||
|
{
|
||||||
|
$resource = $addResourceURI ? $this->resourceURI . $resource : $resource;
|
||||||
|
if ($body) {
|
||||||
|
$this->jsBody[$slug] = $resource;
|
||||||
|
} else {
|
||||||
|
$this->jsHeader[$slug] = $resource;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerCSS(string $slug, string $resource, bool $addResourceURI = true): void
|
||||||
|
{
|
||||||
|
$resource = $addResourceURI ? $this->resourceURI . $resource : $resource;
|
||||||
|
$this->css[$slug] = $resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getJSAsStr(bool $body = true): void
|
||||||
|
{
|
||||||
|
if ($body) {
|
||||||
|
foreach ($this->jsBody as $key => $item){
|
||||||
|
echo "<script src='$item'></script>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
foreach ($this->jsHeader as $key => $item){
|
||||||
|
echo "<script src='$item'></script>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCSSAsSTR(): void
|
||||||
|
{
|
||||||
|
foreach ($this->css as $key => $item){
|
||||||
|
echo "<link rel='stylesheet' href='$item'>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
61
kernel/CgRouteCollector.php
Normal file
61
kernel/CgRouteCollector.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
|
||||||
|
use Phroute\Phroute\Route;
|
||||||
|
use Phroute\Phroute\RouteCollector;
|
||||||
|
|
||||||
|
class CgRouteCollector extends RouteCollector
|
||||||
|
{
|
||||||
|
public function crud($route, $handler, array $filters = []): CgRouteCollector
|
||||||
|
{
|
||||||
|
$this->addRoute(Route::GET, $route, array_merge($handler, ['actionIndex']), $filters);
|
||||||
|
$this->addRoute(Route::GET, $route . '/{id}', array_merge($handler, ['actionView']), $filters);
|
||||||
|
$this->addRoute(Route::POST, $route, array_merge($handler, ['actionStore']), $filters);
|
||||||
|
$this->addRoute(Route::DELETE, $route, array_merge($handler, ['actionDelete']), $filters);
|
||||||
|
return $this->addRoute(Route::ANY, $route . '/update/{id}', array_merge($handler, ['actionEdit']), $filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function gridView($route, $handler, array $filters = []): CgRouteCollector
|
||||||
|
{
|
||||||
|
$this->addRoute(Route::GET, $route, array_merge($handler, ['actionIndex']), $filters);
|
||||||
|
$this->addRoute(Route::GET, $route . '/{id}', array_merge($handler, ['actionView']), $filters);
|
||||||
|
$this->addRoute(Route::ANY, $route . '/create', array_merge($handler, ['actionStore']), $filters);
|
||||||
|
$this->addRoute(Route::POST, $route . '/delete', array_merge($handler, ['actionDelete']), $filters);
|
||||||
|
return $this->addRoute(Route::ANY, $route . '/update/{id}', array_merge($handler, ['actionEdit']), $filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rest($route, $handler, array $filters = []): CgRouteCollector
|
||||||
|
{
|
||||||
|
$this->addRoute(Route::GET, $route, array_merge($handler, ['actionIndex']), $filters);
|
||||||
|
$this->addRoute(Route::GET, $route . '/{id}', array_merge($handler, ['actionView']), $filters);
|
||||||
|
$this->addRoute(Route::POST, $route . '/', array_merge($handler, ['actionStore']), $filters);
|
||||||
|
$this->addRoute(Route::DELETE, $route . '/delete', array_merge($handler, ['actionDelete']), $filters);
|
||||||
|
return $this->addRoute(Route::ANY, $route . '/update/{id}', array_merge($handler, ['actionEdit']), $filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function authorization($route, $handler, array $filters = [])
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
public function exclude($action)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $route
|
||||||
|
* @param $handler
|
||||||
|
* @param array $filters
|
||||||
|
* @param array $additionalInfo
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function console($route, $handler, array $filters = [], array $additionalInfo = []): void
|
||||||
|
{
|
||||||
|
$additionalInfo['type'] = "console";
|
||||||
|
$this->addRoute(Route::GET, $route, $handler, $filters, $additionalInfo);
|
||||||
|
}
|
||||||
|
}
|
115
kernel/CgView.php
Normal file
115
kernel/CgView.php
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
use kernel\helpers\Debug;
|
||||||
|
|
||||||
|
class CgView
|
||||||
|
{
|
||||||
|
public string $viewPath = '';
|
||||||
|
|
||||||
|
public string $layoutPath = '';
|
||||||
|
public array $varToLayout = [];
|
||||||
|
public bool|string $layout = false;
|
||||||
|
|
||||||
|
protected array $metaArr = [];
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render(string $view, array $data = []): void
|
||||||
|
{
|
||||||
|
$content = $this->createContent($view, $data);
|
||||||
|
|
||||||
|
echo $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fetch(string $view, array $data = []): false|string
|
||||||
|
{
|
||||||
|
$content = $this->createContent($view, $data);
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addVarToLayout($key, $value): void
|
||||||
|
{
|
||||||
|
$this->varToLayout[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTitle(string $title): void
|
||||||
|
{
|
||||||
|
$this->addVarToLayout('title', $title);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMeta(array $meta): void
|
||||||
|
{
|
||||||
|
foreach ($meta as $key => $value){
|
||||||
|
$this->metaArr[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMeta(): string
|
||||||
|
{
|
||||||
|
$meta = "";
|
||||||
|
foreach ($this->metaArr as $key => $value){
|
||||||
|
$meta .= "<meta name='$key' content='$value'>";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createContent(string $viewFile, array $data = []): false|string
|
||||||
|
{
|
||||||
|
ob_start();
|
||||||
|
|
||||||
|
if ($this->varToLayout){
|
||||||
|
foreach ($this->varToLayout as $key => $datum) {
|
||||||
|
${"$key"} = $datum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$view = $this;
|
||||||
|
foreach ($data as $key => $datum) {
|
||||||
|
${"$key"} = $datum;
|
||||||
|
}
|
||||||
|
|
||||||
|
include($this->viewPath . $viewFile);
|
||||||
|
|
||||||
|
$content = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
|
||||||
|
$file_content = $content;
|
||||||
|
|
||||||
|
if (!isset($title)){
|
||||||
|
$title = "No Title";
|
||||||
|
}
|
||||||
|
|
||||||
|
$layoutPath = $this->viewPath;
|
||||||
|
|
||||||
|
if ($this->layout) {
|
||||||
|
|
||||||
|
if ($this->layoutPath !== '') {
|
||||||
|
|
||||||
|
$layoutPath = $this->layoutPath;
|
||||||
|
}
|
||||||
|
if (file_exists($layoutPath . $this->layout)) {
|
||||||
|
if ($this->varToLayout){
|
||||||
|
foreach ($this->varToLayout as $key => $datum) {
|
||||||
|
${"$key"} = $datum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
include($layoutPath . $this->layout);
|
||||||
|
$file_content = ob_get_contents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
return $file_content;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
31
kernel/Controller.php
Normal file
31
kernel/Controller.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
|
|
||||||
|
class Controller
|
||||||
|
{
|
||||||
|
protected \Twig\Loader\FilesystemLoader $loader;
|
||||||
|
protected \Twig\Environment $twig;
|
||||||
|
protected CgView $cgView;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->loader = new \Twig\Loader\FilesystemLoader(ROOT_DIR . $_ENV['VIEWS_PATH']);
|
||||||
|
$this->twig = new \Twig\Environment($this->loader, ['cache' => ROOT_DIR . $_ENV['VIEWS_CACHE_PATH']]);
|
||||||
|
|
||||||
|
$this->cgView = new CgView();
|
||||||
|
$this->cgView->viewPath = ROOT_DIR . "/views";
|
||||||
|
|
||||||
|
$this->init();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] protected function redirect(string $url, int $code = 301): void
|
||||||
|
{
|
||||||
|
header('Location: ' . $url, true, $code);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function init(){}
|
||||||
|
}
|
52
kernel/Database.php
Normal file
52
kernel/Database.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: kirill
|
||||||
|
* Date: 03.08.19
|
||||||
|
* Time: 23:51
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
|
use Illuminate\Database\Schema\Builder;
|
||||||
|
use Illuminate\Container\Container;
|
||||||
|
use Phroute\Phroute\Dispatcher;
|
||||||
|
|
||||||
|
class Database
|
||||||
|
{
|
||||||
|
/** @var Builder $capsule */
|
||||||
|
public Builder $schema;
|
||||||
|
|
||||||
|
/** @var Capsule $capsule */
|
||||||
|
public Capsule $capsule;
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
$this->capsule = new Capsule;
|
||||||
|
$this->capsule->addConnection([
|
||||||
|
'driver' => $_ENV['DB_DRIVER'],
|
||||||
|
'host' => $_ENV['DB_HOST'],
|
||||||
|
'database' => $_ENV['DB_NAME'],
|
||||||
|
'username' => $_ENV['DB_USER'],
|
||||||
|
'password' => $_ENV['DB_PASSWORD'],
|
||||||
|
'charset' => $_ENV['DB_CHARSET'],
|
||||||
|
'collation' => $_ENV['DB_COLLATION'],
|
||||||
|
'prefix' => $_ENV['DB_PREFIX'],
|
||||||
|
]);
|
||||||
|
// Setup the Eloquent ORM…
|
||||||
|
|
||||||
|
$this->capsule->setAsGlobal();
|
||||||
|
|
||||||
|
$this->capsule->bootEloquent();
|
||||||
|
|
||||||
|
$this->schema = $this->capsule->schema();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createBuilder(string $table_name): \Illuminate\Database\Query\Builder
|
||||||
|
{
|
||||||
|
$builder = new \Illuminate\Database\Query\Builder($this->schema->getConnection());
|
||||||
|
$builder->from($table_name);
|
||||||
|
return $builder;
|
||||||
|
}
|
||||||
|
}
|
279
kernel/EntityRelation.php
Normal file
279
kernel/EntityRelation.php
Normal file
@ -0,0 +1,279 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use kernel\helpers\Debug;
|
||||||
|
use kernel\models\Option;
|
||||||
|
use kernel\modules\option\service\OptionService;
|
||||||
|
use kernel\services\ModuleService;
|
||||||
|
|
||||||
|
class EntityRelation
|
||||||
|
{
|
||||||
|
protected ModuleService $moduleService;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->moduleService = new ModuleService();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function getEntityList(): array
|
||||||
|
{
|
||||||
|
$list = [];
|
||||||
|
$moduleService = new ModuleService();
|
||||||
|
$activeModules = $moduleService->getActiveModules();
|
||||||
|
foreach ($activeModules as $module) {
|
||||||
|
if (isset($module['type']) and $module['type'] === "entity") {
|
||||||
|
$list[$module['slug']] = $module['slug'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAdditionalPropertyList(): array
|
||||||
|
{
|
||||||
|
$list = [];
|
||||||
|
$activeModules = $this->moduleService->getActiveModules();
|
||||||
|
foreach ($activeModules as $module) {
|
||||||
|
if (isset($module['type']) and $module['type'] === "additional_property") {
|
||||||
|
$list[] = $module['slug'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getEntitiesRelations(): array|bool
|
||||||
|
{
|
||||||
|
$entity_relations = OptionService::getItem("entity_relations");
|
||||||
|
if ($entity_relations) {
|
||||||
|
return json_decode($entity_relations, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function removePropertyFromEntityRelations(string $entity, string $property): bool
|
||||||
|
{
|
||||||
|
$entity_relations_info = Option::where("key", "entity_relations")->first();
|
||||||
|
if ($entity_relations_info) {
|
||||||
|
$entity_relations = json_decode($entity_relations_info->value, true);
|
||||||
|
if ($entity_relations[$entity]) {
|
||||||
|
$propertyKey = array_search($property, $entity_relations[$entity]);
|
||||||
|
if ($entity_relations[$entity][$propertyKey] === $property) {
|
||||||
|
unset($entity_relations[$entity][$propertyKey]);
|
||||||
|
$entity_relations[$entity] = array_values($entity_relations[$entity]);
|
||||||
|
if (empty($entity_relations[$entity])) {
|
||||||
|
unset($entity_relations[$entity]);
|
||||||
|
}
|
||||||
|
$entity_relations_info->value = json_encode($entity_relations, JSON_UNESCAPED_UNICODE);
|
||||||
|
$entity_relations_info->save();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function removePropertyRelation(string $property): bool
|
||||||
|
{
|
||||||
|
$entity_relations_info = Option::where("key", "entity_relations")->first();
|
||||||
|
if ($entity_relations_info) {
|
||||||
|
$entity_relations = json_decode($entity_relations_info->value, true);
|
||||||
|
foreach ($entity_relations as $entity => $entity_relation) {
|
||||||
|
if (in_array($property, $entity_relation)) {
|
||||||
|
$index = array_search($property, $entity_relation);
|
||||||
|
unset($entity_relations[$entity][$index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$entity_relations_info->value = json_encode($entity_relations, JSON_UNESCAPED_UNICODE);
|
||||||
|
$entity_relations_info->save();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function removeEntityRelation(string $entity): bool
|
||||||
|
{
|
||||||
|
$entity_relations_info = Option::where("key", "entity_relations")->first();
|
||||||
|
if ($entity_relations_info) {
|
||||||
|
$entity_relations = json_decode($entity_relations_info->value, true);
|
||||||
|
if (isset($entity_relations[$entity])) {
|
||||||
|
unset($entity_relations[$entity]);
|
||||||
|
$entity_relations_info->value = json_encode($entity_relations, JSON_UNESCAPED_UNICODE);
|
||||||
|
$entity_relations_info->save();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEntityRelationsBySlug(string $slug)
|
||||||
|
{
|
||||||
|
$entityRelations = $this->getEntitiesRelations();
|
||||||
|
if ($entityRelations) {
|
||||||
|
if (isset($entityRelations[$slug])) {
|
||||||
|
return $entityRelations[$slug];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addEntityRelation(string $entity, string $property): bool
|
||||||
|
{
|
||||||
|
$entity_relations_info = Option::where("key", "entity_relations")->first();
|
||||||
|
if ($entity_relations_info) {
|
||||||
|
$entity_relations = json_decode($entity_relations_info->value, true);
|
||||||
|
if (isset($entity_relations[$entity])) {
|
||||||
|
$entity_relations[$entity][] = $property;
|
||||||
|
} else {
|
||||||
|
$entity_relations[$entity][] = $property;
|
||||||
|
}
|
||||||
|
$entity_relations_info->value = json_encode($entity_relations, JSON_UNESCAPED_UNICODE);
|
||||||
|
$entity_relations_info->save();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAdditionalPropertyClassBySlug(string $slug)
|
||||||
|
{
|
||||||
|
$module = $this->moduleService->getModuleInfoBySlug($slug);
|
||||||
|
if (isset($module['module_class'])) {
|
||||||
|
return new $module['module_class']();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderFormInputsBySlug(string $entity, string $slug, Model $model): void
|
||||||
|
{
|
||||||
|
$moduleClass = $this->getAdditionalPropertyClassBySlug($slug);
|
||||||
|
if ($moduleClass and method_exists($moduleClass, "formInputs")) {
|
||||||
|
$moduleClass->formInputs($entity, $model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderEntityAdditionalPropertyFormBySlug(string $entity, Model $model = null): void
|
||||||
|
{
|
||||||
|
$relations = $this->getEntityRelationsBySlug($entity);
|
||||||
|
if ($relations) {
|
||||||
|
foreach ($relations as $relation) {
|
||||||
|
$this->renderFormInputsBySlug($entity, $relation, $model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveEntityRelationBySlug(string $slug, string $entity, Model $model, Request $request): void
|
||||||
|
{
|
||||||
|
$moduleClass = $this->getAdditionalPropertyClassBySlug($slug);
|
||||||
|
if ($moduleClass and method_exists($moduleClass, "saveInputs")) {
|
||||||
|
$moduleClass->saveInputs($entity, $model, $request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveEntityRelation(string $entity, Model $model, Request $request): void
|
||||||
|
{
|
||||||
|
$relations = $this->getEntityRelationsBySlug($entity);
|
||||||
|
if ($relations) {
|
||||||
|
foreach ($relations as $relation) {
|
||||||
|
$this->saveEntityRelationBySlug($relation, $entity, $model, $request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEntityAdditionalProperty(string $entity, Model $model): array
|
||||||
|
{
|
||||||
|
$relations = $this->getEntityRelationsBySlug($entity);
|
||||||
|
if ($relations) {
|
||||||
|
$relationsArr = [];
|
||||||
|
foreach ($relations as $relation) {
|
||||||
|
$moduleClass = $this->getAdditionalPropertyClassBySlug($relation);
|
||||||
|
if ($moduleClass and method_exists($moduleClass, "getItems")) {
|
||||||
|
$relationsArr[$relation] = $moduleClass->getItems($entity, $model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $relationsArr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAdditionalPropertyByEntityId(string $entity, string $entity_id, string $additionalPropertySlug): string
|
||||||
|
{
|
||||||
|
$moduleClass = $this->getAdditionalPropertyClassBySlug($additionalPropertySlug);
|
||||||
|
if ($moduleClass and method_exists($moduleClass, "getItem")) {
|
||||||
|
return $moduleClass->getItem($entity, $entity_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteEntityRelationBySlug(string $slug, string $entity, Model $model): void
|
||||||
|
{
|
||||||
|
$moduleClass = $this->getAdditionalPropertyClassBySlug($slug);
|
||||||
|
if ($moduleClass and method_exists($moduleClass, "deleteItems")) {
|
||||||
|
$moduleClass->deleteItems($entity, $model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteEntityRelation(string $entity, Model $model): void
|
||||||
|
{
|
||||||
|
$relations = $this->getEntityRelationsBySlug($entity);
|
||||||
|
if ($relations) {
|
||||||
|
foreach ($relations as $relation) {
|
||||||
|
$this->deleteEntityRelationBySlug($relation, $entity, $model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getEntityByProperty(string $data): array
|
||||||
|
{
|
||||||
|
$entityRelations = self::getEntitiesRelations();
|
||||||
|
$entities = [];
|
||||||
|
foreach ($entityRelations as $entity => $property) {
|
||||||
|
if (in_array($data, $property)) {
|
||||||
|
$entities[] = $entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $entities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function configurationEntitiesByProperty(array|null $entities, string $property): void
|
||||||
|
{
|
||||||
|
$entityRelations = self::getEntitiesRelations();
|
||||||
|
if (isset($entities)) {
|
||||||
|
foreach ($entities as $entity) {
|
||||||
|
if (!isset($entityRelations[$entity])) {
|
||||||
|
EntityRelation::addEntityRelation($entity, $property);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($entityRelations as $entity => $additionalProperty) {
|
||||||
|
if (in_array($entity, $entities)) {
|
||||||
|
if (!in_array($property, $additionalProperty)) {
|
||||||
|
EntityRelation::addEntityRelation($entity, $property);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (in_array($property, $additionalProperty)) {
|
||||||
|
EntityRelation::removePropertyFromEntityRelations($entity, $property);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach ($entityRelations as $entity => $additionalProperty) {
|
||||||
|
EntityRelation::removePropertyFromEntityRelations($entity, $property);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
103
kernel/FileUpload.php
Normal file
103
kernel/FileUpload.php
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
class FileUpload
|
||||||
|
{
|
||||||
|
protected string $fileTmpPath;
|
||||||
|
|
||||||
|
protected string $destPath;
|
||||||
|
|
||||||
|
protected string $uploadDir;
|
||||||
|
protected string $uploadFile;
|
||||||
|
protected string $fileName;
|
||||||
|
protected string $fileSize;
|
||||||
|
protected string $fileType;
|
||||||
|
protected array $fileNameCmps;
|
||||||
|
protected string $fileExtension;
|
||||||
|
public array $allowedFileExtensions;
|
||||||
|
protected bool $hashing = true;
|
||||||
|
|
||||||
|
public function __construct(array $file, array $extensions, bool $hashing = true)
|
||||||
|
{
|
||||||
|
$this->fileTmpPath = $file['tmp_name'];
|
||||||
|
$this->fileName = $file['name'];
|
||||||
|
$this->fileSize = $file['size'];
|
||||||
|
$this->fileType = $file['type'];
|
||||||
|
$this->fileNameCmps = explode('.', $this->fileName);
|
||||||
|
$this->fileExtension = strtolower(end($this->fileNameCmps));
|
||||||
|
$this->allowedFileExtensions = $extensions;
|
||||||
|
$this->hashing = $hashing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function upload($uploadDir = "/resources/upload/"): bool
|
||||||
|
{
|
||||||
|
if ($this->hashing) {
|
||||||
|
$newFileName = md5(time() . $this->fileName) . '.' . $this->fileExtension;
|
||||||
|
if (in_array($this->fileExtension, $this->allowedFileExtensions)) {
|
||||||
|
$this->uploadDir = $uploadDir . mb_substr($newFileName, 0, 2) . '/' . mb_substr($newFileName, 2, 2) . '/';
|
||||||
|
$oldMask = umask(0);
|
||||||
|
mkdir(ROOT_DIR . $this->uploadDir, 0775, true);
|
||||||
|
umask($oldMask);
|
||||||
|
$uploadFileDir = ROOT_DIR . $this->uploadDir;
|
||||||
|
$this->destPath = $uploadFileDir . $newFileName;
|
||||||
|
$this->uploadFile = $this->uploadDir . $newFileName;
|
||||||
|
move_uploaded_file($this->fileTmpPath, $this->destPath);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (in_array($this->fileExtension, $this->allowedFileExtensions)) {
|
||||||
|
$this->uploadDir = $uploadDir;
|
||||||
|
$oldMask = umask(0);
|
||||||
|
mkdir(ROOT_DIR . $this->uploadDir, 0775, true);
|
||||||
|
umask($oldMask);
|
||||||
|
$uploadFileDir = ROOT_DIR . $this->uploadDir;
|
||||||
|
$this->destPath = $uploadFileDir . $this->fileName;
|
||||||
|
$this->uploadFile = $this->uploadDir . $this->fileName;
|
||||||
|
move_uploaded_file($this->fileTmpPath, $this->destPath);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAllowedFileExtensions(array $allowedFileExtensions): void
|
||||||
|
{
|
||||||
|
$this->allowedFileExtensions = $allowedFileExtensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFullUploadedPath(): string
|
||||||
|
{
|
||||||
|
return $this->destPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDestPath(string $destPath): void
|
||||||
|
{
|
||||||
|
$this->destPath = $destPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUploadDir(string $uploadDir): void
|
||||||
|
{
|
||||||
|
$this->uploadDir = $uploadDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUploadFile(string $uploadFile): void
|
||||||
|
{
|
||||||
|
$this->uploadFile = $uploadFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUploadDir(): string
|
||||||
|
{
|
||||||
|
return $this->uploadDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUploadFile(): string
|
||||||
|
{
|
||||||
|
return $this->uploadFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
39
kernel/Flash.php
Normal file
39
kernel/Flash.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
use Josantonius\Session\Facades\Session;
|
||||||
|
|
||||||
|
class Flash
|
||||||
|
{
|
||||||
|
|
||||||
|
public static function setMessage(string $type, string $msg): void
|
||||||
|
{
|
||||||
|
self::start();
|
||||||
|
Session::set($type, $msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getMessage(string $type): string
|
||||||
|
{
|
||||||
|
self::start();
|
||||||
|
$msg = Session::get($type, false);
|
||||||
|
Session::remove($type);
|
||||||
|
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function hasMessage(string $type): bool
|
||||||
|
{
|
||||||
|
self::start();
|
||||||
|
|
||||||
|
return Session::has($type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function start()
|
||||||
|
{
|
||||||
|
if (!Session::isStarted()){
|
||||||
|
Session::start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
92
kernel/FormModel.php
Normal file
92
kernel/FormModel.php
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
use MadeSimple\Validator\Validator;
|
||||||
|
|
||||||
|
class FormModel
|
||||||
|
{
|
||||||
|
protected Validator $validator;
|
||||||
|
|
||||||
|
protected array $data = [];
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->validator = new Validator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function load(array $array): void
|
||||||
|
{
|
||||||
|
$rules = $this->rules();
|
||||||
|
foreach ($array as $key => $item) {
|
||||||
|
if (isset($rules[$key])) {
|
||||||
|
$this->data[$key] = $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getData(): array
|
||||||
|
{
|
||||||
|
return $this->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setItem(string $name, string|int $value): void
|
||||||
|
{
|
||||||
|
$this->data[$name] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getItem(string $name)
|
||||||
|
{
|
||||||
|
if (isset($this->data[$name])) {
|
||||||
|
return $this->data[$name];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validate(): bool
|
||||||
|
{
|
||||||
|
$res = $this->validator->validate($this->data, $this->rules());
|
||||||
|
if (!$res) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateForUpdate(): bool
|
||||||
|
{
|
||||||
|
$res = $this->validator->validate($this->data, $this->rulesForUpdate());
|
||||||
|
if (!$res) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getErrors(): array
|
||||||
|
{
|
||||||
|
return $this->validator->getProcessedErrors();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getErrorsStr(): string
|
||||||
|
{
|
||||||
|
$errorsArr = $this->getErrors();
|
||||||
|
$str = '';
|
||||||
|
if ($errorsArr['errors']) {
|
||||||
|
foreach ($errorsArr['errors'] as $key => $errorArr) {
|
||||||
|
foreach ($errorsArr['errors'][$key] as $error){
|
||||||
|
$str .= "$error <br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
28
kernel/Header.php
Normal file
28
kernel/Header.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: kirill
|
||||||
|
* Date: 16.06.19
|
||||||
|
* Time: 0:22
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
|
||||||
|
class Header
|
||||||
|
{
|
||||||
|
protected array $list = [];
|
||||||
|
|
||||||
|
public function add($key, $value): void
|
||||||
|
{
|
||||||
|
$this->list[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set(): void
|
||||||
|
{
|
||||||
|
foreach ($this->list as $key=>$v){
|
||||||
|
header($key . ": " . $v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
15
kernel/IGTabel/action_column/DeleteActionColumn.php
Normal file
15
kernel/IGTabel/action_column/DeleteActionColumn.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\IGTabel\action_column;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
|
||||||
|
class DeleteActionColumn extends ActionColumn
|
||||||
|
{
|
||||||
|
protected string $prefix = '/delete/';
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
|
||||||
|
}
|
||||||
|
}
|
16
kernel/IGTabel/action_column/EditActionColumn.php
Normal file
16
kernel/IGTabel/action_column/EditActionColumn.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\IGTabel\action_column;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
|
||||||
|
class EditActionColumn extends ActionColumn
|
||||||
|
{
|
||||||
|
protected string $prefix = "/update/";
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
|
||||||
|
}
|
||||||
|
}
|
17
kernel/IGTabel/action_column/InstallActionColumn.php
Normal file
17
kernel/IGTabel/action_column/InstallActionColumn.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\IGTabel\action_column;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
|
||||||
|
class InstallActionColumn extends ActionColumn
|
||||||
|
{
|
||||||
|
|
||||||
|
protected string $prefix = '/install/';
|
||||||
|
|
||||||
|
public function fetch()
|
||||||
|
{
|
||||||
|
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-warning'>Установить</a> ";
|
||||||
|
}
|
||||||
|
}
|
17
kernel/IGTabel/action_column/ViewActionColumn.php
Normal file
17
kernel/IGTabel/action_column/ViewActionColumn.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\IGTabel\action_column;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
use kernel\helpers\Debug;
|
||||||
|
|
||||||
|
class ViewActionColumn extends ActionColumn
|
||||||
|
{
|
||||||
|
protected string $prefix = '/view/';
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-primary'>Просмотр</a> ";
|
||||||
|
}
|
||||||
|
}
|
24
kernel/IGTabel/btn/DangerBtn.php
Normal file
24
kernel/IGTabel/btn/DangerBtn.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\IGTabel\btn;
|
||||||
|
|
||||||
|
class DangerBtn
|
||||||
|
{
|
||||||
|
protected string $btn = '';
|
||||||
|
|
||||||
|
public function __construct(string $title, string $url)
|
||||||
|
{
|
||||||
|
$this->btn = "<a class='btn btn-danger' href='$url' style='margin: 3px; width: 150px;' >$title</a>";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
return $this->btn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function create(string $title, string $url): DangerBtn
|
||||||
|
{
|
||||||
|
return new self($title, $url);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
24
kernel/IGTabel/btn/PrimaryBtn.php
Normal file
24
kernel/IGTabel/btn/PrimaryBtn.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\IGTabel\btn;
|
||||||
|
|
||||||
|
class PrimaryBtn
|
||||||
|
{
|
||||||
|
protected string $btn = '';
|
||||||
|
|
||||||
|
public function __construct(string $title, string $url, $width)
|
||||||
|
{
|
||||||
|
$this->btn = "<a class='btn btn-primary' href='$url' style='margin: 3px; width: '$width >$title</a>";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
return $this->btn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function create(string $title, string $url, $width = '150px'): PrimaryBtn
|
||||||
|
{
|
||||||
|
return new self($title, $url, $width);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
24
kernel/IGTabel/btn/SuccessBtn.php
Normal file
24
kernel/IGTabel/btn/SuccessBtn.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\IGTabel\btn;
|
||||||
|
|
||||||
|
class SuccessBtn
|
||||||
|
{
|
||||||
|
protected string $btn = '';
|
||||||
|
|
||||||
|
public function __construct(string $title, string $url)
|
||||||
|
{
|
||||||
|
$this->btn = "<a class='btn btn-success' href='$url' style='margin: 3px; width: 150px;' >$title</a>";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
return $this->btn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function create(string $title, string $url): SuccessBtn
|
||||||
|
{
|
||||||
|
return new self($title, $url);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
50
kernel/Mailing.php
Normal file
50
kernel/Mailing.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
use kernel\helpers\Debug;
|
||||||
|
use kernel\helpers\SMTP;
|
||||||
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
|
||||||
|
class Mailing
|
||||||
|
{
|
||||||
|
protected SMTP $SMTP;
|
||||||
|
|
||||||
|
protected CgView $cgView;
|
||||||
|
protected array $data;
|
||||||
|
|
||||||
|
public function __construct(array $data = [])
|
||||||
|
{
|
||||||
|
$this->cgView = new CgView();
|
||||||
|
$this->cgView->viewPath = KERNEL_DIR . "/views/mailing/";
|
||||||
|
|
||||||
|
$this->data = $data;
|
||||||
|
|
||||||
|
$this->SMTP = new SMTP();
|
||||||
|
|
||||||
|
$this->init();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function send_html(string $tpl, array $tplParams, array $mailParams): ?false
|
||||||
|
{
|
||||||
|
$mailParams['body'] = $this->cgView->fetch($tpl, $tplParams);
|
||||||
|
return $this->SMTP->send_html($mailParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function create(array $data = []): static
|
||||||
|
{
|
||||||
|
return new static($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function init()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
10
kernel/Middleware.php
Normal file
10
kernel/Middleware.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
abstract class Middleware
|
||||||
|
{
|
||||||
|
|
||||||
|
abstract function handler();
|
||||||
|
|
||||||
|
}
|
10
kernel/Module.php
Normal file
10
kernel/Module.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
|
||||||
|
abstract class Module
|
||||||
|
{
|
||||||
|
abstract public function init();
|
||||||
|
abstract public function deactivate();
|
||||||
|
}
|
233
kernel/Request.php
Normal file
233
kernel/Request.php
Normal file
@ -0,0 +1,233 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
use Rakit\Validation\Validator;
|
||||||
|
|
||||||
|
#[\AllowDynamicProperties]
|
||||||
|
class Request
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string $host Абсолютный адрес сервера
|
||||||
|
*/
|
||||||
|
public string $host;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array $headers Заголовки запроса
|
||||||
|
*/
|
||||||
|
public array $headers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public array $data = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public array $errors = [];
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->headers = $this->getRequestHeaders();
|
||||||
|
$this->load();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Возвращает абсолютный адрес сервера.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getHost(): string
|
||||||
|
{
|
||||||
|
if ($this->host !== null) {
|
||||||
|
return $this->host;
|
||||||
|
}
|
||||||
|
|
||||||
|
$http = $this->getIsSecure() ? 'https' : 'http';
|
||||||
|
|
||||||
|
if ($this->headerExist('Host')) {
|
||||||
|
$this->host = $http . '://' . $this->getHeader('Host');
|
||||||
|
} elseif (isset($_SERVER['SERVER_NAME'])) {
|
||||||
|
$this->host = $http . '://' . $_SERVER['SERVER_NAME'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->host;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return false|array|int|string|null
|
||||||
|
*/
|
||||||
|
public static function getUrlPath(): false|array|int|string|null
|
||||||
|
{
|
||||||
|
return parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Возвращает true если шифрование https, иначе false.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getIsSecure(): bool
|
||||||
|
{
|
||||||
|
if (isset($_SERVER['HTTPS']) && (strcasecmp($_SERVER['HTTPS'], 'on') === 0 || $_SERVER['HTTPS'] == 1)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Проверяет был ли передан заголовок запроса.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function headerExist($header): bool
|
||||||
|
{
|
||||||
|
return isset($this->headers[$header]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Возвращает заголовок запроса
|
||||||
|
* @param string $header Заголовок.
|
||||||
|
* @param mixed $defaultValue Значение если, параметр не передан.
|
||||||
|
* @return mixed|null
|
||||||
|
*/
|
||||||
|
public function getHeader($header, $defaultValue = null): mixed
|
||||||
|
{
|
||||||
|
return $this->headers[$header] ?? $defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Возвращает GET - параметр.
|
||||||
|
* @param string|null $param Параметр.
|
||||||
|
* @param mixed|null $defaultValue Значение если, параметр не передан.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function get(string $param = null, mixed $defaultValue = null): mixed
|
||||||
|
{
|
||||||
|
if (is_null($param)) {
|
||||||
|
return $_GET;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $_GET[$param] ?? $defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Возвращает POST - параметр.
|
||||||
|
* @param string $param Параметр.
|
||||||
|
* @param mixed $defaultValue Значение если, параметр не передан.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function post($param = null, $defaultValue = null): mixed
|
||||||
|
{
|
||||||
|
if (is_null($param)) {
|
||||||
|
return $_POST;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $_POST[$param] ?? $defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Был ли POST - запрос.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isPost(): bool
|
||||||
|
{
|
||||||
|
return ($_SERVER['REQUEST_METHOD'] === 'POST');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Был ли GET - запрос.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isGet(): bool
|
||||||
|
{
|
||||||
|
return ($_SERVER['REQUEST_METHOD'] === 'GET');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Загружаем свойсва
|
||||||
|
*/
|
||||||
|
public function load(): void
|
||||||
|
{
|
||||||
|
if (!empty($_REQUEST)) {
|
||||||
|
foreach ($_REQUEST as $key => $item) {
|
||||||
|
$this->{$key} = $item;
|
||||||
|
$this->data[$key] = $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function validate(): bool
|
||||||
|
{
|
||||||
|
if (!empty($this->data)) {
|
||||||
|
$valid = new Validator();
|
||||||
|
$validation = $valid->make($this->data, $this->rules());
|
||||||
|
$validation->setMessages($this->messages());
|
||||||
|
$validation->validate();
|
||||||
|
if ($validation->fails()) {
|
||||||
|
$this->errors = $validation->errors();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getMessagesArray(): array
|
||||||
|
{
|
||||||
|
$msgs = [];
|
||||||
|
if($this->errors){
|
||||||
|
foreach ($this->errors->toArray() as $item){
|
||||||
|
$msgs[] = array_values($item)[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $msgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getRequestHeaders(): array
|
||||||
|
{
|
||||||
|
$headers = array();
|
||||||
|
foreach ($_SERVER as $key => $value) {
|
||||||
|
if (substr($key, 0, 5) <> 'HTTP_') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
|
||||||
|
$headers[$header] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $headers;
|
||||||
|
}
|
||||||
|
}
|
19
kernel/ResponseType.php
Normal file
19
kernel/ResponseType.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: kirill
|
||||||
|
* Date: 15.06.19
|
||||||
|
* Time: 0:44
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
|
||||||
|
class ResponseType
|
||||||
|
{
|
||||||
|
|
||||||
|
const TEXT_HTML = 'text/html';
|
||||||
|
const APPLICATION_JSON = 'application/json';
|
||||||
|
const MULTIPART_FORM_DATA = 'multipart/form-data';
|
||||||
|
|
||||||
|
}
|
139
kernel/RestController.php
Normal file
139
kernel/RestController.php
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
|
use kernel\helpers\Debug;
|
||||||
|
|
||||||
|
class RestController
|
||||||
|
{
|
||||||
|
|
||||||
|
protected Model $model;
|
||||||
|
|
||||||
|
|
||||||
|
protected function expand(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function filters(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] public function actionIndex(): void
|
||||||
|
{
|
||||||
|
$request = new Request();
|
||||||
|
$get = $request->get();
|
||||||
|
$page = $request->get('page') ?? 1;
|
||||||
|
$perPage = $request->get('per_page') ?? 10;
|
||||||
|
$query = $this->model->query();
|
||||||
|
|
||||||
|
if ($this->filters()) {
|
||||||
|
foreach ($this->filters() as $filter){
|
||||||
|
if (key_exists($filter, $get)){
|
||||||
|
if (is_numeric($get[$filter])){
|
||||||
|
$query->where($filter, $get[$filter]);
|
||||||
|
}
|
||||||
|
elseif (is_string($get[$filter])){
|
||||||
|
$query->where($filter,'like', '%' . $get[$filter] . '%');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($page > 1) {
|
||||||
|
$query->skip(($page - 1) * $perPage)->take($perPage);
|
||||||
|
} else {
|
||||||
|
$query->take($perPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
$expand = $this->expand();
|
||||||
|
$expandParams = explode(",", $request->get('expand') ?? "");
|
||||||
|
$finalExpand = array_intersect($expandParams, $expand);
|
||||||
|
if ($finalExpand) {
|
||||||
|
$res = $query->get()->load($finalExpand)->toArray();
|
||||||
|
} else {
|
||||||
|
$res = $query->get()->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->renderApi($res);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] public function actionView($id): void
|
||||||
|
{
|
||||||
|
$expand = $this->expand();
|
||||||
|
$request = new Request();
|
||||||
|
$expandParams = explode(",", $request->get('expand') ?? "");
|
||||||
|
$model = $this->model->where("id", $id)->first();
|
||||||
|
$finalExpand = array_intersect($expandParams, $expand);
|
||||||
|
if ($finalExpand) {
|
||||||
|
$model->load($finalExpand);
|
||||||
|
}
|
||||||
|
$res = [];
|
||||||
|
if ($model) {
|
||||||
|
$res = $model->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->renderApi($res);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] public function actionDelete($id): void
|
||||||
|
{
|
||||||
|
$model = $this->model->where("id", $id)->first();
|
||||||
|
$res = [];
|
||||||
|
if ($model) {
|
||||||
|
$res = $model->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
$model->delete();
|
||||||
|
|
||||||
|
$this->renderApi($res);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] public function actionStore(): void
|
||||||
|
{
|
||||||
|
$request = new Request();
|
||||||
|
$data = $request->post();
|
||||||
|
foreach ($this->model->getFillable() as $item) {
|
||||||
|
$this->model->{$item} = $data[$item] ?? null;
|
||||||
|
}
|
||||||
|
$this->model->save();
|
||||||
|
|
||||||
|
$this->renderApi($this->model->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] public function actionEdit(int $id): void
|
||||||
|
{
|
||||||
|
$request = new Request();
|
||||||
|
$data = $request->post();
|
||||||
|
|
||||||
|
$model = $this->model->where('id', $id)->first();
|
||||||
|
|
||||||
|
foreach ($model->getFillable() as $item) {
|
||||||
|
if (!empty($data[$item])) {
|
||||||
|
$model->{$item} = $data[$item] ?? null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$model->save();
|
||||||
|
$this->renderApi($model->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] public function returnError(int $code): void
|
||||||
|
{
|
||||||
|
http_response_code($code);
|
||||||
|
die('Forbidden');
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] protected function renderApi(array $data): void
|
||||||
|
{
|
||||||
|
header("Content-Type: application/json");
|
||||||
|
echo json_encode($data);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
34
kernel/Widget.php
Normal file
34
kernel/Widget.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel;
|
||||||
|
|
||||||
|
class Widget
|
||||||
|
{
|
||||||
|
|
||||||
|
protected CgView $cgView;
|
||||||
|
protected array $data;
|
||||||
|
|
||||||
|
public function __construct(array $data = [])
|
||||||
|
{
|
||||||
|
$this->cgView = new CgView();
|
||||||
|
$this->cgView->viewPath = KERNEL_DIR . "/views/widgets";
|
||||||
|
|
||||||
|
$this->data = $data;
|
||||||
|
|
||||||
|
$this->init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function create(array $data = []): Widget
|
||||||
|
{
|
||||||
|
return new static($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function init()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
25
kernel/admin_themes/default/DefaultAdminThemeAssets.php
Normal file
25
kernel/admin_themes/default/DefaultAdminThemeAssets.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\admin_themes\default;
|
||||||
|
|
||||||
|
use kernel\Assets;
|
||||||
|
|
||||||
|
class DefaultAdminThemeAssets extends Assets
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function createJS(): void
|
||||||
|
{
|
||||||
|
$this->registerJS(slug: "jquery", resource: "/js/jquery.min.js");
|
||||||
|
$this->registerJS(slug: "popper", resource: "/js/popper.js");
|
||||||
|
$this->registerJS(slug: "bootstrap", resource: "/js/bootstrap.min.js");
|
||||||
|
$this->registerJS(slug: "main", resource: "/js/main.js");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createCSS()
|
||||||
|
{
|
||||||
|
$this->registerCSS(slug: "font-awesome", resource: "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css", addResourceURI: false);
|
||||||
|
$this->registerCSS(slug: "bootstrap", resource: "/css/bootstrap.min.css");
|
||||||
|
$this->registerCSS(slug: "style", resource: "/css/style.css");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
45
kernel/admin_themes/default/layout/login.php
Normal file
45
kernel/admin_themes/default/layout/login.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var $content
|
||||||
|
* @var string $resources
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Sidebar 01</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900" rel="stylesheet">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||||
|
<link rel="stylesheet" href="<?= $resources ?>/css/bootstrap.min.css">
|
||||||
|
<link rel="stylesheet" href="<?= $resources ?>/css/style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="wrapper d-flex align-items-stretch">
|
||||||
|
<?php if (\kernel\Flash::hasMessage("error")): ?>
|
||||||
|
<div class="alert alert-danger alert-dismissible mainAlert">
|
||||||
|
<?= \kernel\Flash::getMessage("error"); ?>
|
||||||
|
<button type="button" class="btn-close closeAlertBtn"></button>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (\kernel\Flash::hasMessage("success")): ?>
|
||||||
|
<div class="alert alert-success alert-dismissible">
|
||||||
|
<?= \kernel\Flash::getMessage("success"); ?>
|
||||||
|
<button type="button" class="btn-close closeAlertBtn" ></button>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<!-- Page Content -->
|
||||||
|
<div id="content" class="p-4 p-md-5">
|
||||||
|
<?= $content ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="<?=$resources?>/js/jquery.min.js"></script>
|
||||||
|
<script src="<?=$resources?>/js/popper.js"></script>
|
||||||
|
<script src="<?=$resources?>/js/bootstrap.min.js"></script>
|
||||||
|
<script src="<?=$resources?>/js/main.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
97
kernel/admin_themes/default/layout/main.php
Normal file
97
kernel/admin_themes/default/layout/main.php
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var $content
|
||||||
|
* @var string $resources
|
||||||
|
* @var string $title
|
||||||
|
* @var \kernel\CgView $view
|
||||||
|
*/
|
||||||
|
\Josantonius\Session\Facades\Session::start();
|
||||||
|
$assets = new \kernel\admin_themes\default\DefaultAdminThemeAssets($resources)
|
||||||
|
?>
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title><?= $title ?></title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
<?= $view->getMeta() ?>
|
||||||
|
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900" rel="stylesheet">
|
||||||
|
|
||||||
|
<?php $assets->getCSSAsSTR(); ?>
|
||||||
|
<?php $assets->getJSAsStr(body: false); ?>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="wrapper d-flex align-items-stretch">
|
||||||
|
<nav id="sidebar">
|
||||||
|
<div class="p-4 pt-5">
|
||||||
|
<a href="<?= '/admin/user/profile' ?>" class="img logo rounded-circle mb-5"
|
||||||
|
style="background-image: url(<?= \kernel\modules\user\service\UserService::getAuthUserPhoto() ?? '/resources/default_user_photo/noPhoto.png' ?>);">
|
||||||
|
</a>
|
||||||
|
<p>
|
||||||
|
<a href="<?= '/admin/user/profile' ?>">
|
||||||
|
<?= \kernel\modules\user\service\UserService::getAuthUsername() ?>
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<?php \kernel\widgets\MenuWidget::create()->run(); ?>
|
||||||
|
<div class="footer">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- Page Content -->
|
||||||
|
<div id="content" class="p-4 p-md-5">
|
||||||
|
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
|
<div class="container-fluid">
|
||||||
|
|
||||||
|
<button type="button" id="sidebarCollapse" class="btn btn-primary">
|
||||||
|
<i class="fa fa-bars"></i>
|
||||||
|
<span class="sr-only">Toggle Menu</span>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-dark d-inline-block d-lg-none ml-auto" type="button" data-toggle="collapse"
|
||||||
|
data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
|
||||||
|
aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<i class="fa fa-bars"></i>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||||
|
<ul class="nav navbar-nav ml-auto">
|
||||||
|
<li class="nav-item active">
|
||||||
|
<a class="nav-link" href="/admin/logout">Выход</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">About</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">Portfolio</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">Contact</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
<?php if (\kernel\Flash::hasMessage("error")): ?>
|
||||||
|
<div class="alert alert-danger alert-dismissible mainAlert">
|
||||||
|
<?= \kernel\Flash::getMessage("error"); ?>
|
||||||
|
<button type="button" class="btn-close closeAlertBtn"></button>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (\kernel\Flash::hasMessage("success")): ?>
|
||||||
|
<div class="alert alert-success alert-dismissible">
|
||||||
|
<?= \kernel\Flash::getMessage("success"); ?>
|
||||||
|
<button type="button" class="btn-close closeAlertBtn"></button>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?= $content ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php $assets->getJSAsStr(); ?>
|
||||||
|
</body>
|
||||||
|
</html>
|
13
kernel/admin_themes/default/manifest.json
Normal file
13
kernel/admin_themes/default/manifest.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "Default",
|
||||||
|
"version": "0.1",
|
||||||
|
"author": "ItGuild",
|
||||||
|
"slug": "default",
|
||||||
|
"type": "admin_theme",
|
||||||
|
"description": "Default admin theme",
|
||||||
|
"preview": "preview.png",
|
||||||
|
"resource": "/resources/admin_themes/default",
|
||||||
|
"resource_path": "{RESOURCES}/admin_themes/default",
|
||||||
|
"layout": "main.php",
|
||||||
|
"layout_path": "{KERNEL_ADMIN_THEMES}/default/layout"
|
||||||
|
}
|
72
kernel/admin_themes/simple/layout/main.php
Normal file
72
kernel/admin_themes/simple/layout/main.php
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var $content
|
||||||
|
* @var string $resources
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Sidebar 01</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900" rel="stylesheet">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
|
||||||
|
<link rel="stylesheet" href="<?=$resources?>/css/style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="wrapper d-flex align-items-stretch">
|
||||||
|
<nav id="sidebar">
|
||||||
|
<div class="p-4 pt-5">
|
||||||
|
<a href="#" class="img logo rounded-circle mb-5" style="background-image: url(<?=$resources?>/images/33.png);"></a>
|
||||||
|
<?php \kernel\widgets\MenuWidget::create()->run(); ?>
|
||||||
|
<div class="footer">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- Page Content -->
|
||||||
|
<div id="content" class="p-4 p-md-5">
|
||||||
|
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
|
<div class="container-fluid">
|
||||||
|
|
||||||
|
<button type="button" id="sidebarCollapse" class="btn btn-primary">
|
||||||
|
<i class="fa fa-bars"></i>
|
||||||
|
<span class="sr-only">Toggle Menu</span>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-dark d-inline-block d-lg-none ml-auto" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<i class="fa fa-bars"></i>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||||
|
<ul class="nav navbar-nav ml-auto">
|
||||||
|
<li class="nav-item active">
|
||||||
|
<a class="nav-link" href="#">Home</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">About</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">Portfolio</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<?= $content ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="<?=$resources?>/js/jquery.min.js"></script>
|
||||||
|
<script src="<?=$resources?>/js/popper.js"></script>
|
||||||
|
<script src="<?=$resources?>/js/bootstrap.min.js"></script>
|
||||||
|
<script src="<?=$resources?>/js/main.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
12
kernel/admin_themes/simple/manifest.json
Normal file
12
kernel/admin_themes/simple/manifest.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "Simple",
|
||||||
|
"version": "0.1",
|
||||||
|
"author": "ItGuild",
|
||||||
|
"slug": "simple",
|
||||||
|
"description": "Simple admin theme",
|
||||||
|
"preview": "preview.png",
|
||||||
|
"resource": "/resources/admin_themes/simple",
|
||||||
|
"resource_path": "{RESOURCES}/admin_themes/simple",
|
||||||
|
"layout": "main.php",
|
||||||
|
"layout_path": "{KERNEL_ADMIN_THEMES}/simple/layout"
|
||||||
|
}
|
112
kernel/app_modules/photo/PhotoModule.php
Normal file
112
kernel/app_modules/photo/PhotoModule.php
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\app_modules\photo;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use itguild\forms\builders\FileBuilder;
|
||||||
|
use kernel\app_modules\photo\models\Photo;
|
||||||
|
use kernel\app_modules\photo\service\PhotoService;
|
||||||
|
use kernel\FileUpload;
|
||||||
|
use kernel\helpers\Html;
|
||||||
|
use kernel\Module;
|
||||||
|
use kernel\modules\menu\service\MenuService;
|
||||||
|
use kernel\Request;
|
||||||
|
use kernel\services\MigrationService;
|
||||||
|
|
||||||
|
class PhotoModule extends Module
|
||||||
|
{
|
||||||
|
|
||||||
|
public MenuService $menuService;
|
||||||
|
public MigrationService $migrationService;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->menuService = new MenuService();
|
||||||
|
$this->migrationService = new MigrationService();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function init(): void
|
||||||
|
{
|
||||||
|
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/photo/migrations");
|
||||||
|
|
||||||
|
$this->menuService->createItem([
|
||||||
|
"label" => "Фото",
|
||||||
|
"url" => "/admin/photo",
|
||||||
|
"slug" => "photo",
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->menuService->createItem([
|
||||||
|
"label" => "Фото",
|
||||||
|
"url" => "/admin/settings/photo",
|
||||||
|
"slug" => "photo_settings",
|
||||||
|
"parent_slug" => "settings"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deactivate(): void
|
||||||
|
{
|
||||||
|
$this->menuService->removeItemBySlug("photo");
|
||||||
|
$this->menuService->removeItemBySlug("photo_settings");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function formInputs(string $entity, Model $model = null): void
|
||||||
|
{
|
||||||
|
if (isset($model->id)) {
|
||||||
|
$value = PhotoService::getByEntity($entity, $model->id);
|
||||||
|
echo Html::img($value, ['width' => '200px']);
|
||||||
|
}
|
||||||
|
$input = FileBuilder::build("image", [
|
||||||
|
'class' => 'form-control',
|
||||||
|
'value' => $value ?? '',
|
||||||
|
]);
|
||||||
|
$input->setLabel("Фото");
|
||||||
|
$input->create()->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveInputs(string $entity, Model $model, Request $request): void
|
||||||
|
{
|
||||||
|
Photo::where("entity", $entity)->where("entity_id", $model->id)->delete();
|
||||||
|
|
||||||
|
if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) {
|
||||||
|
$file = new FileUpload($_FILES['image'], ['jpg', 'jpeg', 'png']);
|
||||||
|
$file->upload();
|
||||||
|
$image = $file->getUploadFile();
|
||||||
|
$photo = new Photo();
|
||||||
|
$photo->entity = $entity;
|
||||||
|
$photo->entity_id = $model->id;
|
||||||
|
$photo->image = $image;
|
||||||
|
$photo->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getItems(string $entity, Model $model): array|string
|
||||||
|
{
|
||||||
|
$photos = Photo::where("entity", $entity)->where("entity_id", $model->id)->get();
|
||||||
|
$photoStr = "";
|
||||||
|
foreach ($photos as $photo) {
|
||||||
|
$photoStr .= "<img src='$photo->image' width='150px'>" . " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
return substr($photoStr, 0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getItem(string $entity, string $entity_id): string
|
||||||
|
{
|
||||||
|
$photos = Photo::where("entity", $entity)->where("entity_id", $entity_id)->get();
|
||||||
|
$photoStr = "";
|
||||||
|
foreach ($photos as $photo) {
|
||||||
|
$photoStr .= "<img src='$photo->image' width='150px'>" . " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
return substr($photoStr, 0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteItems(string $entity, Model $model): void
|
||||||
|
{
|
||||||
|
Photo::where("entity", $entity)->where("entity_id", $model->id)->delete();
|
||||||
|
}
|
||||||
|
}
|
77
kernel/app_modules/photo/controllers/PhotoController.php
Executable file
77
kernel/app_modules/photo/controllers/PhotoController.php
Executable file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\app_modules\photo\controllers;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
|
use kernel\AdminController;
|
||||||
|
use kernel\app_modules\photo\models\form\CreatePhotoForm;
|
||||||
|
use kernel\app_modules\photo\models\Photo;
|
||||||
|
use kernel\app_modules\photo\service\PhotoService;
|
||||||
|
use kernel\EntityRelation;
|
||||||
|
use kernel\Flash;
|
||||||
|
use kernel\helpers\Debug;
|
||||||
|
use kernel\Request;
|
||||||
|
|
||||||
|
class PhotoController extends AdminController
|
||||||
|
{
|
||||||
|
private PhotoService $photoService;
|
||||||
|
protected function init(): void
|
||||||
|
{
|
||||||
|
parent::init();
|
||||||
|
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/photo/views/";
|
||||||
|
$this->photoService = new PhotoService();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionCreate(): void
|
||||||
|
{
|
||||||
|
$this->cgView->render("form.php");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] public function actionAdd(): void
|
||||||
|
{
|
||||||
|
$photoForm = new CreatePhotoForm();
|
||||||
|
$photoForm->load($_REQUEST);
|
||||||
|
if ($photoForm->validate()){
|
||||||
|
$photo = $this->photoService->create($photoForm);
|
||||||
|
if ($photo){
|
||||||
|
$this->redirect("/admin/photo/view/" . $photo->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->redirect("/admin/photo/create");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionIndex($page_number = 1): void
|
||||||
|
{
|
||||||
|
$this->cgView->render("index.php", ['page_number' => $page_number]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function actionView($id): void
|
||||||
|
{
|
||||||
|
$photo = Photo::find($id);
|
||||||
|
|
||||||
|
if (!$photo){
|
||||||
|
throw new Exception(message: "The photo not found");
|
||||||
|
}
|
||||||
|
$this->cgView->render("view.php", ['photo' => $photo]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionSettings(): void
|
||||||
|
{
|
||||||
|
$this->cgView->render('settingsForm.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] public function actionSaveSettings(): void
|
||||||
|
{
|
||||||
|
$request = new Request();
|
||||||
|
$entities = $request->post('entity');
|
||||||
|
EntityRelation::configurationEntitiesByProperty($entities, 'photo');
|
||||||
|
|
||||||
|
Flash::setMessage("success", "Настройка прошла успешно");
|
||||||
|
$this->redirect("/admin/settings/photo", 302);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public string $migration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
\kernel\App::$db->schema->create('photo', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->string('image', 255)->nullable(false);
|
||||||
|
$table->string('entity', 255)->nullable(false);
|
||||||
|
$table->integer('entity_id')->default(1);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
\kernel\App::$db->schema->dropIfExists('photo');
|
||||||
|
}
|
||||||
|
};
|
44
kernel/app_modules/photo/models/Photo.php
Executable file
44
kernel/app_modules/photo/models/Photo.php
Executable file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\app_modules\photo\models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $id
|
||||||
|
* @property string $image
|
||||||
|
* @property string $entity
|
||||||
|
* @property int $entity_id
|
||||||
|
*/
|
||||||
|
class Photo extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'photo';
|
||||||
|
|
||||||
|
protected $fillable = ['image', 'entity', 'entity_id'];
|
||||||
|
|
||||||
|
public static function labels(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'image' => 'Фото',
|
||||||
|
'entity' => 'Сущность',
|
||||||
|
'entity_id' => 'Идентификатор сущности',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPhotoListByEntity(string $entity): array
|
||||||
|
{
|
||||||
|
return self::where("entity", $entity)->get()->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPhotoByEntity(string $entity): array
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
$photos = self::getPhotoListByEntity($entity);
|
||||||
|
foreach ($photos as $photo) {
|
||||||
|
$result[$photo['id']] = $photo['label'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
19
kernel/app_modules/photo/models/form/CreatePhotoForm.php
Executable file
19
kernel/app_modules/photo/models/form/CreatePhotoForm.php
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\app_modules\photo\models\form;
|
||||||
|
|
||||||
|
use kernel\FormModel;
|
||||||
|
|
||||||
|
class CreatePhotoForm extends FormModel
|
||||||
|
{
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'image' => 'required',
|
||||||
|
'entity' => 'required|string',
|
||||||
|
'entity_id' => 'required|integer|min:1',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
24
kernel/app_modules/photo/routs/photo.php
Executable file
24
kernel/app_modules/photo/routs/photo.php
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use kernel\App;
|
||||||
|
use kernel\CgRouteCollector;
|
||||||
|
use Phroute\Phroute\RouteCollector;
|
||||||
|
|
||||||
|
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
|
||||||
|
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
|
||||||
|
App::$collector->group(["prefix" => "photo"], function (CGRouteCollector $router) {
|
||||||
|
App::$collector->get('/', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionIndex']);
|
||||||
|
App::$collector->get('/page/{page_number}', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionIndex']);
|
||||||
|
App::$collector->get('/create', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionCreate']);
|
||||||
|
App::$collector->post("/", [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionAdd']);
|
||||||
|
App::$collector->get('/view/{id}', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionView']);
|
||||||
|
App::$collector->any('/update/{id}', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionUpdate']);
|
||||||
|
App::$collector->any("/edit/{id}", [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionEdit']);
|
||||||
|
App::$collector->get('/delete/{id}', [\kernel\app_modules\photo\controllers\PhotoController::class]);
|
||||||
|
});
|
||||||
|
App::$collector->group(["prefix" => "settings"], function (CGRouteCollector $router) {
|
||||||
|
App::$collector->get('/photo', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionSettings']);
|
||||||
|
App::$collector->post('/photo/update', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionSaveSettings']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
40
kernel/app_modules/photo/service/PhotoService.php
Executable file
40
kernel/app_modules/photo/service/PhotoService.php
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\app_modules\photo\service;
|
||||||
|
|
||||||
|
use kernel\app_modules\photo\models\Photo;
|
||||||
|
use kernel\FormModel;
|
||||||
|
use kernel\helpers\Debug;
|
||||||
|
|
||||||
|
class PhotoService
|
||||||
|
{
|
||||||
|
public function create(FormModel $form_model): false|Photo
|
||||||
|
{
|
||||||
|
$model = new Photo();
|
||||||
|
$model->image = $form_model->getItem('image');
|
||||||
|
$model->entity = $form_model->getItem('entity');
|
||||||
|
$model->entity_id = $form_model->getItem('entity_id');
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(FormModel $form_model, Photo $photo): false|Photo
|
||||||
|
{
|
||||||
|
$photo->image = $form_model->getItem('image');
|
||||||
|
$photo->entity = $form_model->getItem('entity');
|
||||||
|
$photo->entity_id = $form_model->getItem('entity_id');
|
||||||
|
|
||||||
|
if ($photo->save()){
|
||||||
|
return $photo;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByEntity(string $entity, int $entity_id): string
|
||||||
|
{
|
||||||
|
$photo = Photo::where("entity", $entity)->where("entity_id", $entity_id)->first();
|
||||||
|
return $photo->image ?? "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
41
kernel/app_modules/photo/views/index.php
Executable file
41
kernel/app_modules/photo/views/index.php
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var int $page_number
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Itguild\EloquentTable\EloquentDataProvider;
|
||||||
|
use Itguild\EloquentTable\ListEloquentTable;
|
||||||
|
use kernel\app_modules\photo\models\Photo;
|
||||||
|
use kernel\widgets\IconBtn\IconBtnCreateWidget;
|
||||||
|
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||||
|
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||||
|
use kernel\widgets\IconBtn\IconBtnViewWidget;
|
||||||
|
|
||||||
|
$table = new ListEloquentTable(new EloquentDataProvider(Photo::class, [
|
||||||
|
'currentPage' => $page_number,
|
||||||
|
'perPage' => 8,
|
||||||
|
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||||
|
'baseUrl' => "/admin/photo",
|
||||||
|
]));
|
||||||
|
|
||||||
|
//$table->beforePrint(function () {
|
||||||
|
// return IconBtnCreateWidget::create(['url' => '/admin/photo/create'])->run();
|
||||||
|
//});
|
||||||
|
|
||||||
|
$table->columns([
|
||||||
|
'image' => function ($data) {
|
||||||
|
return $data ? "<img src='$data' width='150px'>" : "";
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
$table->addAction(function($row) {
|
||||||
|
return IconBtnViewWidget::create(['url' => '/admin/photo/view/' . $row['id']])->run();
|
||||||
|
});
|
||||||
|
//$table->addAction(function($row) {
|
||||||
|
// return IconBtnEditWidget::create(['url' => '/admin/photo/update/' . $row['id']])->run();
|
||||||
|
//});
|
||||||
|
//$table->addAction(function($row) {
|
||||||
|
// return IconBtnDeleteWidget::create(['url' => '/admin/photo/delete/' . $row['id']])->run();
|
||||||
|
//});
|
||||||
|
$table->create();
|
||||||
|
$table->render();
|
46
kernel/app_modules/photo/views/settingsForm.php
Normal file
46
kernel/app_modules/photo/views/settingsForm.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$form = new \itguild\forms\ActiveForm();
|
||||||
|
$form->beginForm("/admin/settings/photo/update");
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<h5>Выберите сущности, к которым хотите прикрепить фото</h5>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$form->field(\itguild\forms\inputs\Select::class, "entity[]", [
|
||||||
|
'class' => "form-control",
|
||||||
|
'value' => \kernel\EntityRelation::getEntityByProperty('photo') ?? '',
|
||||||
|
'multiple' => "multiple",
|
||||||
|
|
||||||
|
])
|
||||||
|
->setLabel("Сущности")
|
||||||
|
->setOptions(\kernel\EntityRelation::getEntityList())
|
||||||
|
->render();
|
||||||
|
?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-2">
|
||||||
|
<?php
|
||||||
|
$form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [
|
||||||
|
'class' => "btn btn-primary ",
|
||||||
|
'value' => 'Отправить',
|
||||||
|
'typeInput' => 'submit'
|
||||||
|
])
|
||||||
|
->render();
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-2">
|
||||||
|
<?php
|
||||||
|
$form->field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [
|
||||||
|
'class' => "btn btn-warning",
|
||||||
|
'value' => 'Сбросить',
|
||||||
|
'typeInput' => 'reset'
|
||||||
|
])
|
||||||
|
->render();
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
$form->endForm();
|
34
kernel/app_modules/photo/views/view.php
Executable file
34
kernel/app_modules/photo/views/view.php
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Illuminate\Database\Eloquent\Collection $photo
|
||||||
|
*/
|
||||||
|
|
||||||
|
use kernel\modules\user\models\User;
|
||||||
|
use Itguild\EloquentTable\ViewEloquentTable;
|
||||||
|
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||||||
|
use kernel\IGTabel\btn\DangerBtn;
|
||||||
|
use kernel\IGTabel\btn\PrimaryBtn;
|
||||||
|
use kernel\IGTabel\btn\SuccessBtn;
|
||||||
|
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||||
|
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||||
|
use kernel\widgets\IconBtn\IconBtnListWidget;
|
||||||
|
|
||||||
|
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($photo, [
|
||||||
|
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||||
|
'baseUrl' => "/admin/photo",
|
||||||
|
]));
|
||||||
|
$table->beforePrint(function () use ($photo) {
|
||||||
|
$btn = IconBtnListWidget::create(['url' => '/admin/photo'])->run();
|
||||||
|
// $btn .= IconBtnEditWidget::create(['url' => '/admin/photo/update/' . $photo->id])->run();
|
||||||
|
// $btn .= IconBtnDeleteWidget::create(['url' => '/admin/photo/delete/' . $photo->id])->run();
|
||||||
|
return $btn;
|
||||||
|
});
|
||||||
|
|
||||||
|
$table->rows([
|
||||||
|
'image' => function ($data) {
|
||||||
|
return $data ? "<img src='$data' width='300px'>" : "";
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
$table->create();
|
||||||
|
$table->render();
|
124
kernel/app_modules/tag/TagModule.php
Normal file
124
kernel/app_modules/tag/TagModule.php
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\app_modules\tag;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use itguild\forms\builders\SelectBuilder;
|
||||||
|
use kernel\app_modules\tag\models\Tag;
|
||||||
|
use kernel\app_modules\tag\models\TagEntity;
|
||||||
|
use kernel\app_modules\tag\service\TagEntityService;
|
||||||
|
use kernel\Module;
|
||||||
|
use kernel\modules\menu\service\MenuService;
|
||||||
|
use kernel\modules\option\service\OptionService;
|
||||||
|
use kernel\Request;
|
||||||
|
use kernel\services\MigrationService;
|
||||||
|
|
||||||
|
class TagModule extends Module
|
||||||
|
{
|
||||||
|
|
||||||
|
public MenuService $menuService;
|
||||||
|
public MigrationService $migrationService;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->menuService = new MenuService();
|
||||||
|
$this->migrationService = new MigrationService();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function init(): void
|
||||||
|
{
|
||||||
|
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations");
|
||||||
|
|
||||||
|
$this->menuService->createItem([
|
||||||
|
"label" => "Тэги",
|
||||||
|
"url" => "/admin/tag",
|
||||||
|
"slug" => "tag",
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->menuService->createItem([
|
||||||
|
"label" => "Тэги",
|
||||||
|
"url" => "/admin/settings/tag",
|
||||||
|
"slug" => "tag_settings",
|
||||||
|
"parent_slug" => "settings"
|
||||||
|
]);
|
||||||
|
|
||||||
|
OptionService::createFromParams("entity_tag_list", "{}", "Список тегов");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function deactivate(): void
|
||||||
|
{
|
||||||
|
$this->menuService->removeItemBySlug("tag");
|
||||||
|
$this->menuService->removeItemBySlug("tag_settings");
|
||||||
|
|
||||||
|
OptionService::removeOptionByKey("entity_tag_list");
|
||||||
|
|
||||||
|
$this->migrationService->rollbackAtPath("{KERNEL_APP_MODULES}/tag/migrations");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function formInputs(string $entity, Model $model = null): void
|
||||||
|
{
|
||||||
|
if (isset($model->id)) {
|
||||||
|
$value = TagEntityService::getTagsByEntity($entity, $model->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$input = SelectBuilder::build("tag[]", [
|
||||||
|
'class' => 'form-control',
|
||||||
|
'placeholder' => 'Теги',
|
||||||
|
'value' => $value ?? '',
|
||||||
|
'multiple' => "multiple",
|
||||||
|
'options' => Tag::getTagLabelByEntity($entity)
|
||||||
|
]);
|
||||||
|
$input->setLabel("Теги");
|
||||||
|
$input->create()->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveInputs(string $entity, Model $model, Request $request): void
|
||||||
|
{
|
||||||
|
TagEntity::where("entity", $entity)->where("entity_id", $model->id)->delete();
|
||||||
|
|
||||||
|
$tags = $request->post("tag");
|
||||||
|
if (is_array($tags)) {
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$tagEntity = new TagEntity();
|
||||||
|
$tagEntity->entity = $entity;
|
||||||
|
$tagEntity->entity_id = $model->id;
|
||||||
|
$tagEntity->tag_id = $tag;
|
||||||
|
$tagEntity->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getItems(string $entity, Model $model): array|string
|
||||||
|
{
|
||||||
|
$tags = TagEntity::where("entity", $entity)->where("entity_id", $model->id)->with("tag")->get();
|
||||||
|
$tagsStr = "";
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$tagsStr .= $tag->tag->label . ", ";
|
||||||
|
}
|
||||||
|
|
||||||
|
return substr($tagsStr, 0, -2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getItem(string $entity, string $entity_id): string
|
||||||
|
{
|
||||||
|
$tags = TagEntity::where("entity", $entity)->where("entity_id", $entity_id)->get();
|
||||||
|
$tagsStr = "";
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$tagsStr .= $tag->tag->label . ", ";
|
||||||
|
}
|
||||||
|
|
||||||
|
return substr($tagsStr, 0, -2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteItems(string $entity, Model $model): void
|
||||||
|
{
|
||||||
|
TagEntity::where("entity", $entity)->where("entity_id", $model->id)->delete();
|
||||||
|
}
|
||||||
|
}
|
120
kernel/app_modules/tag/controllers/TagController.php
Normal file
120
kernel/app_modules/tag/controllers/TagController.php
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\app_modules\tag\controllers;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
|
use kernel\AdminController;
|
||||||
|
use kernel\app_modules\tag\models\forms\CreateTagForm;
|
||||||
|
use kernel\app_modules\tag\models\Tag;
|
||||||
|
use kernel\app_modules\tag\service\TagService;
|
||||||
|
use kernel\EntityRelation;
|
||||||
|
use kernel\Flash;
|
||||||
|
use kernel\helpers\Debug;
|
||||||
|
use kernel\models\Option;
|
||||||
|
use kernel\modules\menu\service\MenuService;
|
||||||
|
use kernel\Request;
|
||||||
|
|
||||||
|
class TagController extends AdminController
|
||||||
|
{
|
||||||
|
private TagService $tagService;
|
||||||
|
protected function init(): void
|
||||||
|
{
|
||||||
|
parent::init();
|
||||||
|
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/tag/";
|
||||||
|
$this->tagService = new TagService();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionCreate(): void
|
||||||
|
{
|
||||||
|
$this->cgView->render("form.php");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] public function actionAdd(): void
|
||||||
|
{
|
||||||
|
$tagForm = new CreateTagForm();
|
||||||
|
$tagForm->load($_REQUEST);
|
||||||
|
if ($tagForm->validate()){
|
||||||
|
$tag = $this->tagService->create($tagForm);
|
||||||
|
if ($tag){
|
||||||
|
$this->redirect("/admin/tag/view/" . $tag->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->redirect("/admin/tag/create");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionIndex($page_number = 1): void
|
||||||
|
{
|
||||||
|
$this->cgView->render("index.php", ['page_number' => $page_number]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function actionView($id): void
|
||||||
|
{
|
||||||
|
$tag = Tag::find($id);
|
||||||
|
|
||||||
|
if (!$tag){
|
||||||
|
throw new Exception(message: "The tag not found");
|
||||||
|
}
|
||||||
|
$this->cgView->render("view.php", ['tag' => $tag]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function actionUpdate($id): void
|
||||||
|
{
|
||||||
|
$model = Tag::find($id);
|
||||||
|
if (!$model){
|
||||||
|
throw new Exception(message: "The tag not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->cgView->render("form.php", ['model' => $model]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function actionEdit($id): void
|
||||||
|
{
|
||||||
|
$tag = Tag::find($id);
|
||||||
|
if (!$tag){
|
||||||
|
throw new Exception(message: "The tag not found");
|
||||||
|
}
|
||||||
|
$tagForm = new CreateTagForm();
|
||||||
|
$tagService = new TagService();
|
||||||
|
$tagForm->load($_REQUEST);
|
||||||
|
if ($tagForm->validate()) {
|
||||||
|
$tag = $tagService->update($tagForm, $tag);
|
||||||
|
if ($tag) {
|
||||||
|
$this->redirect("/admin/tag/view/" . $tag->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->redirect("/admin/tag/update/" . $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] public function actionDelete($id): void
|
||||||
|
{
|
||||||
|
$post = Tag::find($id)->first();
|
||||||
|
$post->delete();
|
||||||
|
$this->redirect("/admin/tag/");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionSettings(): void
|
||||||
|
{
|
||||||
|
$this->cgView->render('settingsForm.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] public function actionSaveSettings(): void
|
||||||
|
{
|
||||||
|
$request = new Request();
|
||||||
|
$entities = $request->post('entity');
|
||||||
|
EntityRelation::configurationEntitiesByProperty($entities, 'tag');
|
||||||
|
|
||||||
|
Flash::setMessage("success", "Настройка прошла успешно");
|
||||||
|
$this->redirect("/admin/settings/tag", 302);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
49
kernel/app_modules/tag/controllers/TagEntityController.php
Normal file
49
kernel/app_modules/tag/controllers/TagEntityController.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\app_modules\tag\controllers;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
|
use kernel\AdminController;
|
||||||
|
use kernel\app_modules\tag\models\forms\CreateTagForm;
|
||||||
|
use kernel\app_modules\tag\models\Tag;
|
||||||
|
use kernel\app_modules\tag\models\TagEntity;
|
||||||
|
use kernel\app_modules\tag\service\TagEntityService;
|
||||||
|
use kernel\app_modules\tag\service\TagService;
|
||||||
|
use kernel\helpers\Debug;
|
||||||
|
use kernel\modules\menu\service\MenuService;
|
||||||
|
|
||||||
|
class TagEntityController extends AdminController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function init(): void
|
||||||
|
{
|
||||||
|
parent::init();
|
||||||
|
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/tag_entity/";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $page_number
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function actionIndex($page_number = 1): void
|
||||||
|
{
|
||||||
|
$this->cgView->render("index.php", ['page_number' => $page_number]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function actionView($id): void
|
||||||
|
{
|
||||||
|
$tagEntity = TagEntity::find($id);
|
||||||
|
|
||||||
|
if (!$tagEntity){
|
||||||
|
throw new Exception(message: "The tag entity not found");
|
||||||
|
}
|
||||||
|
$this->cgView->render("view.php", ['tagEntity' => $tagEntity]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public string $migration;
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
\kernel\App::$db->schema->create('tag', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->string('label', 255)->nullable(false);
|
||||||
|
$table->string('entity', 255)->nullable(false);
|
||||||
|
$table->string('slug', 255)->unique();
|
||||||
|
$table->integer('status')->default(1);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
\kernel\App::$db->schema->dropIfExists('tag');
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user