Compare commits

...

195 Commits

Author SHA1 Message Date
a64ed080bb v0.1.7 2025-01-28 16:44:34 +03:00
6242304843 flash msg fix 2025-01-28 12:47:44 +03:00
2655a793f5 some fix 2025-01-24 16:47:37 +03:00
de0354f9cb add dependencies to view module shop client 2025-01-24 16:26:11 +03:00
4a4d5b083f some fix 2025-01-24 16:20:15 +03:00
68b5741f46 some fix 2025-01-24 15:14:36 +03:00
fc70051761 theme service fix 2025-01-24 15:00:22 +03:00
b1dacff877 Merge branch 'master' of https://git.itguild.info/ItGuild/igmf 2025-01-24 14:30:49 +03:00
e904cedf40 some 2025-01-24 14:28:07 +03:00
64a6cc4340 Merge branch 'master' of https://git.itguild.info/ItGuild/igmf 2025-01-24 13:59:55 +03:00
b79483dafd some 2025-01-24 13:59:03 +03:00
7ab241daa2 app_themes ad to kernel 2025-01-24 13:53:05 +03:00
c69314b531 Merge branch 'master' of https://git.itguild.info/ItGuild/igmf 2025-01-24 12:15:48 +03:00
e448ffa6b6 manifest kernel version update 2025-01-24 12:15:18 +03:00
3c025a4cbc Merge branch 'master' of https://git.itguild.info/ItGuild/igmf 2025-01-24 11:56:47 +03:00
6a7cde15e9 some fix 2025-01-24 11:56:29 +03:00
2b2c99cd17 some fix 2025-01-24 11:29:04 +03:00
b6ba8f8718 recusive activate dependencies 2025-01-23 16:57:03 +03:00
11c99be0f6 theme dependence 2025-01-21 16:41:48 +03:00
f421e0c649 theme dependences 2025-01-21 14:14:26 +03:00
3120795eab theme fix 2025-01-20 13:52:29 +03:00
50c6ca98d8 Theme module and them to igfs add 2025-01-19 21:23:53 +03:00
dac4db96af default theme 2025-01-16 16:14:43 +03:00
c228a70468 add default theme 2025-01-15 16:57:03 +03:00
3e178f6633 kernel version 0.1.4 2025-01-15 15:00:30 +03:00
64dad0aaf9 assets class 2025-01-09 17:13:22 +03:00
32d1e93e73 Merge branch 'master' of https://git.itguild.info/stasbilay02/MicroFrameWork 2025-01-09 16:27:54 +03:00
dd231b0c07 rest and post 2025-01-09 16:27:34 +03:00
88114ae9f2 fix profile edit route 2025-01-09 14:51:15 +03:00
6a07e5cdde admin themes to ms 2025-01-09 12:17:32 +03:00
7489e999ef add profile routs 2024-12-27 15:16:21 +03:00
1a54003030 some fix 2024-12-27 13:50:37 +03:00
28c8e24847 some 2024-12-26 14:04:35 +03:00
b5b7befd34 user photo add 2024-12-25 16:32:23 +03:00
2790105a7d custom select fix 2024-12-25 11:40:33 +03:00
f0bda2ee24 post filters 2024-12-24 16:38:28 +03:00
04bd134e3e some 2024-12-23 16:41:47 +03:00
c23b84bcea some 2024-12-23 15:47:03 +03:00
de690dfd39 admin theme pack 2024-12-23 14:14:59 +03:00
093b04c2c9 module filters 2024-12-19 15:10:29 +03:00
b24fac512a Merge branch 'master' of https://git.itguild.info/stasbilay02/MicroFrameWork 2024-12-19 14:45:57 +03:00
a71102eb05 fix module install, add filters to msc, fix primary btn 2024-12-19 12:59:27 +03:00
7a7241746a Merge branch 'master' of https://git.itguild.info/stasbilay02/MicroFrameWork 2024-12-19 11:01:55 +03:00
95c3c0755b bootstrap 2024-12-19 11:01:44 +03:00
1cf2dc3d86 fix kernel update 2024-12-18 16:52:09 +03:00
57d2f20255 some 2024-12-18 16:48:32 +03:00
5d671d03d2 some 2024-12-18 16:43:53 +03:00
d74a30f33e some 2024-12-18 16:43:32 +03:00
798c687547 fix 2024-12-18 16:38:08 +03:00
bcf8b6621b some fix 2024-12-18 16:32:51 +03:00
0d98ec7cde copy folder fix 2024-12-18 16:15:03 +03:00
a0a99de862 version fix 2024-12-18 15:24:25 +03:00
ea83698070 Merge branch 'master' of https://git.itguild.info/stasbilay02/MicroFrameWork 2024-12-18 12:29:14 +03:00
aa913293ef admine theme 2024-12-18 12:27:29 +03:00
e152e0f193 some 2024-12-17 13:02:25 +03:00
bbc7eafc3d fix 2024-12-17 12:47:45 +03:00
e6455165b3 some fix 2024-12-17 12:41:30 +03:00
2e4fc0496b kernel update with igfs 2024-12-17 12:23:45 +03:00
045bd837b7 kernel pack 2024-12-16 14:21:37 +03:00
c4b3f46111 Merge branch 'master' of https://git.itguild.info/stasbilay02/MicroFrameWork 2024-12-16 13:14:35 +03:00
625089acd1 rest controller 2024-12-16 13:14:28 +03:00
cebae3491b swagger to composer 2024-12-16 13:04:18 +03:00
1d7ed112a7 secure fix 2024-12-13 17:29:36 +03:00
fc188482d0 additional info to routs add 2024-12-13 16:48:53 +03:00
11cb001cfd gitignore 2024-12-13 14:31:13 +03:00
6c1bd4a8e6 rm composer lock 2024-12-13 14:30:25 +03:00
73a64ff717 migration rollback at path, additional info routs 2024-12-13 14:27:46 +03:00
378f27970e rename methods in console service 2024-12-12 16:51:16 +03:00
11420fbb2b console service add method run command 2024-12-12 16:18:50 +03:00
17f31874ea console service 2024-12-12 16:12:14 +03:00
967bcc28b5 cg view title 2024-12-12 15:11:31 +03:00
b00c005b09 some fix 2024-12-12 15:04:45 +03:00
57c715807a Merge branch 'master' of https://git.itguild.info/stasbilay02/MicroFrameWork 2024-12-12 14:14:55 +03:00
9c77403a71 cg view title, meta 2024-12-12 14:06:47 +03:00
63d96eb461 create module update 2024-12-12 14:06:25 +03:00
f7253bafe9 index template 2024-12-12 12:41:45 +03:00
1e566481f7 module construct, add some templates 2024-12-12 11:58:55 +03:00
a9951102c0 construct module 2024-12-10 17:01:25 +03:00
3c0b78ea56 templates controllers and module create in terminal 2024-12-10 15:28:34 +03:00
fb39da53a6 add email input to email login 2024-12-10 12:33:45 +03:00
9419626485 app modules classes move to kerel app modules 2024-12-09 16:35:43 +03:00
38b6aa8860 module shop client 2024-12-09 16:14:43 +03:00
cfbcb3609f auth email api 2024-12-09 14:45:44 +03:00
62ed358a4b api auth email 2024-12-09 13:46:10 +03:00
8778c4d725 fix email register 2024-12-05 16:50:58 +03:00
e41f3faa42 update .env.example 2024-12-05 15:52:42 +03:00
03d3fa43f0 update .env.example 2024-12-05 15:40:02 +03:00
bc6c35167e fix register email 2024-12-05 15:16:39 +03:00
9e446563b2 some fix 2024-12-05 14:38:36 +03:00
8df13569e2 email login 2024-12-05 14:31:04 +03:00
1b486eb788 some 2024-12-04 18:45:17 +03:00
d318c99ba5 SMTP 2024-12-04 16:37:11 +03:00
15c801f579 smtp 2024-12-04 16:28:05 +03:00
0671346ce8 module shop 2024-12-04 15:36:11 +03:00
0a76920800 update login and register form 2024-12-04 13:00:12 +03:00
60f8797173 registration 2024-12-04 12:42:53 +03:00
3ef7f2946b env example update, some fix 2024-12-04 11:20:20 +03:00
dd491a7277 Merge branch 'master' of https://git.itguild.info/stasbilay02/MicroFrameWork 2024-12-03 17:17:07 +03:00
b00f30fe30 readme.md 2024-12-03 17:16:59 +03:00
6c124e9bb7 slider 2024-12-03 16:16:36 +03:00
aff394ae72 some fix 2024-12-03 12:13:18 +03:00
c0bedcb5ee add additional property to user 2024-12-03 10:51:22 +03:00
159b3933fb some fix 2024-12-02 16:50:44 +03:00
13978449a2 is server available 2024-12-02 16:38:05 +03:00
a1bed2d9f2 photo settings 2024-12-02 16:25:28 +03:00
567ab8544d tag settings 2024-12-02 14:15:01 +03:00
b981ff0c44 settings for tag 2024-11-29 16:54:35 +03:00
0ed97877fd fix photo module 2024-11-29 14:07:55 +03:00
3ef1e7d7e0 photo module 2024-11-29 13:23:48 +03:00
e7a20d9b97 additionsl property at list 2024-11-28 16:25:51 +03:00
921569b950 update, delete entity relations 2024-11-28 15:34:57 +03:00
44e61a2030 get additional property 2024-11-28 12:15:30 +03:00
2133fae2cc get item relations 2024-11-27 17:11:06 +03:00
bba35c7b14 tag settings 2024-11-27 16:19:19 +03:00
6d9d19ce36 init fix 2024-11-27 14:15:55 +03:00
8a9f156235 crud tag entity, some fix tag 2024-11-27 14:01:21 +03:00
4920d3b08e CRUD tag entity 2024-11-25 16:58:01 +03:00
745707ee09 tags 2024-11-25 15:17:41 +03:00
1bc7662be0 entyy_id add to tag migration 2024-11-21 15:53:52 +03:00
62eff81213 entity relation save 2024-11-21 13:00:21 +03:00
860ea1a82d add and remove entity relations 2024-11-21 11:47:13 +03:00
65b332811f Merge branch 'master' of https://git.itguild.info/stasbilay02/MicroFrameWork 2024-11-20 16:49:19 +03:00
b465020111 some 2024-11-20 16:48:13 +03:00
ee9d93f137 entity relations 2024-11-20 16:45:15 +03:00
19d668418c entity relations 2024-11-20 15:30:29 +03:00
a3f97456bc show img at menu 2024-11-20 13:41:31 +03:00
9cb82deaf8 merge 2024-11-20 12:52:26 +03:00
6ac5de06e6 action button update 2024-11-20 12:45:02 +03:00
0bfeabce33 action btn 2024-11-19 16:52:00 +03:00
6c2798c123 action btns 2024-11-19 14:55:25 +03:00
7a90980772 fix action btn widger 2024-11-19 14:08:43 +03:00
0f47f73dda action button class 2024-11-19 13:41:13 +03:00
772ad48961 some fix 2024-11-19 12:27:52 +03:00
202d265cab action button widget 2024-11-19 11:21:46 +03:00
f4b0f006aa update, delete module from shop on local page 2024-11-18 15:55:43 +03:00
faf0217b52 some fix 2024-11-18 13:56:00 +03:00
d2028e926b update modules from ms 2024-11-14 01:55:04 +03:00
44c94689c6 some fix 2024-11-08 16:19:11 +03:00
6cf35d5638 install modulu from shop 2024-11-08 14:47:59 +03:00
9a152885d8 module tabs widget 2024-11-05 15:36:46 +03:00
825d3df776 module shop client fix 2024-11-05 13:44:08 +03:00
6f7debc25b some fix 2024-11-05 12:15:09 +03:00
a02c55e16e ms client update 2024-10-31 16:12:02 +03:00
9d243b5b35 module shop client 2024-10-29 14:53:52 +03:00
8eae977357 module service fix 2024-10-25 16:36:48 +03:00
42aca3c1c0 Merge branch 'master' of https://git.itguild.info/stasbilay02/MicroFrameWork 2024-10-25 16:09:33 +03:00
0ca330a9f0 merge 2024-10-25 16:09:26 +03:00
5ec081022d module service some fix 2024-10-24 11:49:19 +03:00
c2dfe632e7 console msgs about modeule 2024-10-24 11:44:16 +03:00
e12bf58baf botstrap.php to kernel update 2024-10-23 16:36:17 +03:00
76d090febf some fix 2024-10-23 15:03:06 +03:00
a00f6566b2 bootstrap, .env.ezample to add update add 2024-10-23 13:33:59 +03:00
ffa659ea1d token generate 2024-10-23 11:38:53 +03:00
e3d1722f2c Merge branch 'master' of https://git.itguild.info/stasbilay02/MicroFrameWork 2024-10-22 16:40:51 +03:00
c9fe2f160a creste secret key 2024-10-22 16:40:40 +03:00
ae91334045 some fix 2024-10-22 14:25:31 +03:00
7ccf0957bf bearer middleware 2024-10-22 11:09:35 +03:00
215d2b1290 some fix 2024-10-21 15:56:51 +03:00
68615d1f8d api secure auth 2024-10-18 13:45:18 +03:00
bda9b03a9f kernel pack some fix 2024-10-17 16:47:04 +03:00
4355651695 flash, middleware 2024-10-17 14:55:00 +03:00
c3c377a4e2 some fix 2024-10-15 16:15:46 +03:00
d3d5e3a8e5 kernel pack, update and some fix 2024-10-14 15:52:52 +03:00
7cf3708e4d session errors 2024-10-11 17:02:35 +03:00
5b9386f970 module set and unset, dependencies 2024-10-11 15:44:15 +03:00
d9c4cecd48 module fix 2024-10-10 22:40:09 +03:00
94496910d7 merge 2024-10-10 16:51:19 +03:00
fb96676bb2 gitignore tmp 2024-10-10 16:50:10 +03:00
0a3b523e00 remove tmp from git 2024-10-10 16:49:16 +03:00
2711c0258d dependences 2024-10-10 16:45:53 +03:00
e29108f21d action update module add 2024-10-10 11:19:51 +03:00
f8e02dc19c install, uninstall. pack to ModuleService 2024-10-10 11:12:01 +03:00
9abfdd2fd9 install, uninstall. pack to ModuleService 2024-10-09 16:42:20 +03:00
fa2676ddb2 psck module 2024-10-09 15:12:30 +03:00
77933cdd9e brta archive module 2024-10-08 17:06:14 +03:00
381c6c059e app module 2024-10-08 13:16:57 +03:00
720d75ee51 module install/uninstall 2024-10-08 12:16:41 +03:00
9823a6ad8e reast api update 2024-10-07 16:57:26 +03:00
4c75c9469b rest to menu 2024-10-07 16:13:46 +03:00
a3f7a90e39 rest api expsnde add 2024-10-07 15:38:23 +03:00
c7e113e325 rest api expand, url params 2024-10-07 11:54:10 +03:00
04da662275 Merge branch 'master' of https://git.itguild.info/stasbilay02/MicroFrameWork 2024-10-07 11:31:20 +03:00
5fe6bd9629 rest api expand 2024-10-07 11:31:16 +03:00
a26eeb9441 fix slug 2024-10-07 11:29:56 +03:00
5944dac053 Create slug 2024-10-01 16:00:14 +03:00
160c381abc fix create slug 2024-10-01 12:25:07 +03:00
571782368c fix create slug 2024-10-01 12:20:01 +03:00
7ff9d45fe7 api action delete add, slug generator update 2024-09-26 16:49:01 +03:00
d49416a7d2 rest controller 2024-09-26 14:47:13 +03:00
810ca49de4 some fix 2024-09-26 11:06:25 +03:00
959d708daf secure module add 2024-09-25 14:17:36 +03:00
349c2992dc login 2024-09-24 17:22:09 +03:00
cb2c719b1b priority menu item 2024-09-24 14:57:25 +03:00
a48088581f admin init command 2024-09-23 17:03:42 +03:00
0f05bc2391 option CRUD 2024-09-23 15:33:48 +03:00
907 changed files with 32742 additions and 27388 deletions

View File

@ -1,11 +1,23 @@
APP_NAME="It Guild Micro Framework"
DB_HOST=localhost
DB_USER=root
DB_USER={db_user}
DB_DRIVER=mysql
DB_PASSWORD=123edsaqw
DB_NAME=mfw
DB_CHARSET=utf8
DB_COLLATION=utf8_unicode_ci
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
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=''

4
.gitignore vendored
View File

@ -2,4 +2,6 @@
vendor
.env
views_cache
resources/upload
resources/upload
resources/tmp
composer.lock

25
README.md Normal file
View 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`
***

2
app/admin_themes/custom/layout/main.php Normal file → Executable file
View File

@ -13,7 +13,7 @@
<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="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>

5
app/admin_themes/custom/manifest.json Normal file → Executable file
View File

@ -3,10 +3,11 @@
"version": "0.1",
"author": "Kavalar",
"slug": "custom",
"type": "admin_theme",
"description": "Custom admin theme",
"preview": "nrnv2024_640x360.jpg",
"resource": "/resources/custom",
"resource_path": "{RESOURCES}/custom",
"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"

View File

@ -0,0 +1,8 @@
<?php
namespace app\modules\photo;
class PhotoModule extends \kernel\app_modules\photo\PhotoModule
{
}

View File

@ -0,0 +1,8 @@
<?php
namespace app\modules\photo\controllers;
class PhotoController extends \kernel\app_modules\photo\controllers\PhotoController
{
}

View 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"
}

View File

@ -0,0 +1,2 @@
<?php
include KERNEL_APP_MODULES_DIR . "/photo/routs/photo.php";

View File

@ -2,32 +2,7 @@
namespace app\modules\tag;
use kernel\Module;
use kernel\modules\menu\service\MenuService;
class TagModule extends Module
class TagModule extends \kernel\app_modules\tag\TagModule
{
public MenuService $menuService;
public function __construct()
{
$this->menuService = new MenuService();
}
/**
* @throws \Exception
*/
public function init(): void
{
$this->menuService->createItem([
"label" => "Тэги",
"url" => "/admin/tag",
"slug" => "tag",
]);
}
public function deactivate(): void
{
$this->menuService->removeItemBySlug("tag");
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace app\modules\tag\controllers;
class TagController extends \kernel\app_modules\tag\controllers\TagController
{
}

View File

@ -1,9 +1,13 @@
{
"name": "Tags",
"version": "0.1",
"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"
}
"module_class_file": "{APP}/modules/tag/TagModule.php",
"routs": "routs/tag.php",
"dependence": "menu"
}

View File

@ -0,0 +1,2 @@
<?php
include KERNEL_APP_MODULES_DIR . "/tag/routs/tag.php";

View File

@ -0,0 +1,8 @@
<?php
namespace app\themes\custom;
class CustomTheme extends \kernel\app_themes\custom\CustomTheme
{
}

View 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");
}
}

View 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");
}
}

View 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"
}

View 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']);

View 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 &copy; 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>

View 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>

View 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 its 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>

View File

@ -6,12 +6,15 @@ $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";
@ -25,11 +28,14 @@ function getConst($text): array|false|string
"{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);

9
bootstrap/secure.php Normal file
View 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;

View File

@ -14,7 +14,14 @@
"itguild/forms": "^0.1.1",
"samejack/php-argv": "dev-master",
"itguild/eloquent-table": "^0.4.1",
"ext-zip": "*"
"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": {
"psr-4": {

2499
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -5,14 +5,17 @@ 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'];

View File

@ -5,7 +5,9 @@ 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
@ -17,8 +19,14 @@ class App
static Header $header;
static User $user;
static array $secure;
public ModuleService $moduleService;
public ThemeService $themeService;
public static Database $db;
public function run(): void
@ -48,6 +56,12 @@ class App
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

66
kernel/Assets.php Normal file
View 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'>";
}
}
}

21
kernel/CgRouteCollector.php Executable file → Normal file
View File

@ -27,6 +27,15 @@ class CgRouteCollector extends RouteCollector
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
@ -37,8 +46,16 @@ class CgRouteCollector extends RouteCollector
//TODO
}
public function console($route, $handler, array $filters = []): void
/**
* @param $route
* @param $handler
* @param array $filters
* @param array $additionalInfo
* @return void
*/
public function console($route, $handler, array $filters = [], array $additionalInfo = []): void
{
$this->addRoute(Route::GET, $route, $handler, $filters);
$additionalInfo['type'] = "console";
$this->addRoute(Route::GET, $route, $handler, $filters, $additionalInfo);
}
}

View File

@ -2,6 +2,8 @@
namespace kernel;
use kernel\helpers\Debug;
class CgView
{
public string $viewPath = '';
@ -10,6 +12,8 @@ class CgView
public array $varToLayout = [];
public bool|string $layout = false;
protected array $metaArr = [];
public function __construct()
{
@ -34,14 +38,44 @@ class CgView
$this->varToLayout[$key] = $value;
}
private function createContent(string $view, array $data = []): false|string
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 . $view);
include($this->viewPath . $viewFile);
$content = ob_get_contents();
ob_end_clean();
@ -50,6 +84,10 @@ class CgView
$file_content = $content;
if (!isset($title)){
$title = "No Title";
}
$layoutPath = $this->viewPath;
if ($this->layout) {

0
kernel/Database.php Executable file → Normal file
View File

279
kernel/EntityRelation.php Normal file
View 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);
}
}
}
}

View File

@ -36,7 +36,9 @@ class FileUpload
$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) . '/';
mkdir(ROOT_DIR . $this->uploadDir, 0777, true);
$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;
@ -49,7 +51,9 @@ class FileUpload
} else {
if (in_array($this->fileExtension, $this->allowedFileExtensions)) {
$this->uploadDir = $uploadDir;
mkdir(ROOT_DIR . $this->uploadDir, 0777, true);
$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;

39
kernel/Flash.php Normal file
View 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();
}
}
}

View File

@ -42,7 +42,7 @@ class FormModel
public function getItem(string $name)
{
if (isset($this->data[$name])){
if (isset($this->data[$name])) {
return $this->data[$name];
}
@ -59,9 +59,34 @@ class FormModel
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;
}
}

0
kernel/Header.php Executable file → Normal file
View File

View 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> ";
}
}

View File

@ -1,10 +1,10 @@
<?php
namespace app\tables\columns\post;
namespace kernel\IGTabel\action_column;
use Itguild\Tables\ActionColumn\ActionColumn;
class PostEditActionColumn extends ActionColumn
class EditActionColumn extends ActionColumn
{
protected string $prefix = "/update/";

View 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> ";
}
}

View 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> ";
}
}

View File

@ -6,9 +6,9 @@ class PrimaryBtn
{
protected string $btn = '';
public function __construct(string $title, string $url)
public function __construct(string $title, string $url, $width)
{
$this->btn = "<a class='btn btn-primary' href='$url' style='margin: 3px; width: 150px;' >$title</a>";
$this->btn = "<a class='btn btn-primary' href='$url' style='margin: 3px; width: '$width >$title</a>";
}
public function fetch(): string
@ -16,9 +16,9 @@ class PrimaryBtn
return $this->btn;
}
public static function create(string $title, string $url): PrimaryBtn
public static function create(string $title, string $url, $width = '150px'): PrimaryBtn
{
return new self($title, $url);
return new self($title, $url, $width);
}
}

50
kernel/Mailing.php Normal file
View 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
View File

@ -0,0 +1,10 @@
<?php
namespace kernel;
abstract class Middleware
{
abstract function handler();
}

View File

@ -119,11 +119,11 @@ class Request
/**
* Возвращает GET - параметр.
* @param string $param Параметр.
* @param mixed $defaultValue Значение если, параметр не передан.
* @param string|null $param Параметр.
* @param mixed|null $defaultValue Значение если, параметр не передан.
* @return mixed
*/
public function get($param = null, $defaultValue = null): mixed
public function get(string $param = null, mixed $defaultValue = null): mixed
{
if (is_null($param)) {
return $_GET;

0
kernel/ResponseType.php Executable file → Normal file
View File

139
kernel/RestController.php Normal file
View 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();
}
}

View File

@ -11,7 +11,7 @@ class Widget
public function __construct(array $data = [])
{
$this->cgView = new CgView();
$this->cgView->viewPath = ROOT_DIR . "/views/widgets";
$this->cgView->viewPath = KERNEL_DIR . "/views/widgets";
$this->data = $data;

View 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");
}
}

View 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>

View File

@ -2,26 +2,38 @@
/**
* @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>Sidebar 01</title>
<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">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="<?=$resources?>/css/style.css">
<?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="#" class="img logo rounded-circle mb-5" style="background-image: url(/resources/admin_theme/images/logo.jpg);"></a>
<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">
@ -40,14 +52,16 @@
<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">
<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>
<a class="nav-link" href="/admin/logout">Выход</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
@ -62,14 +76,22 @@
</div>
</div>
</nav>
<?= $content ?>
<?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>
<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>
<?php $assets->getJSAsStr(); ?>
</body>
</html>

View File

@ -3,10 +3,11 @@
"version": "0.1",
"author": "ItGuild",
"slug": "default",
"type": "admin_theme",
"description": "Default admin theme",
"preview": "preview.png",
"resource": "/resources/default",
"resource_path": "{RESOURCES}/default",
"resource": "/resources/admin_themes/default",
"resource_path": "{RESOURCES}/admin_themes/default",
"layout": "main.php",
"layout_path": "{KERNEL_ADMIN_THEMES}/default/layout"
}

View File

@ -13,7 +13,7 @@
<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="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>

View File

@ -5,8 +5,8 @@
"slug": "simple",
"description": "Simple admin theme",
"preview": "preview.png",
"resource": "/resources/simple",
"resource_path": "{RESOURCES}/simple",
"resource": "/resources/admin_themes/simple",
"resource_path": "{RESOURCES}/admin_themes/simple",
"layout": "main.php",
"layout_path": "{KERNEL_ADMIN_THEMES}/simple/layout"
}

View 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();
}
}

View 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);
}
}

View File

@ -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');
}
};

View 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;
}
}

View 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',
];
}
}

View 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']);
});
});
});

View 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 ?? "";
}
}

View 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();

View 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();

View 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();

View 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();
}
}

View 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);
}
}

View 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]);
}
}

View File

@ -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');
}
};

View File

@ -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('tag_entity', function (Blueprint $table) {
$table->increments('id');
$table->integer('tag_id')->nullable(false);
$table->string('entity', 255)->nullable(false);
$table->integer('entity_id')->nullable(false);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
\kernel\App::$db->schema->dropIfExists('tag_entity');
}
};

View File

@ -0,0 +1,61 @@
<?php
namespace kernel\app_modules\tag\models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property string $label
* @property string $entity
* @property int $entity_id
* @property string $slug
* @property int $status
*/
class Tag extends Model
{
const DISABLE_STATUS = 0;
const ACTIVE_STATUS = 1;
protected $table = 'tag';
protected $fillable = ['label', 'slug', 'status'];
public static function labels(): array
{
return [
'label' => 'Заголовок',
'entity' => 'Сущность',
'slug' => 'Slug',
'status' => 'Статус',
];
}
/**
* @return string[]
*/
public static function getStatus(): array
{
return [
self::DISABLE_STATUS => "Не активный",
self::ACTIVE_STATUS => "Активный",
];
}
public static function getTagListByEntity(string $entity): array
{
return self::where("entity", $entity)->get()->toArray();
}
public static function getTagLabelByEntity(string $entity): array
{
$result = [];
$tags = self::getTagListByEntity($entity);
foreach ($tags as $tag){
$result[$tag['id']] = $tag['label'];
}
return $result;
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace kernel\app_modules\tag\models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property int $tag_id
* @property string $entity
* @property int $entity_id
*/
class TagEntity extends Model
{
protected $table = 'tag_entity';
protected $fillable = ['tag_id', 'entity', 'entity_id'];
public static function labels(): array
{
return [
'tag_id' => 'тег',
'entity' => 'Сущность',
'entity_id' => 'Идентификатор сущности',
];
}
public function tag(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Tag::class);
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace kernel\app_modules\tag\models\forms;
use kernel\FormModel;
class CreateTagEntityForm extends FormModel
{
public function rules(): array
{
return [
'tag_id' => 'required',
'entity' => '',
'entity_id' => '',
];
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace kernel\app_modules\tag\models\forms;
use kernel\FormModel;
class CreateTagForm extends FormModel
{
public function rules(): array
{
return [
'label' => 'required|min-str-len:5|max-str-len:30',
'entity' => 'required',
'slug' => '',
'status' => ''
];
}
}

View File

@ -0,0 +1,34 @@
<?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" => "tag"], function (CGRouteCollector $router) {
App::$collector->get('/', [\app\modules\tag\controllers\TagController::class, 'actionIndex']);
App::$collector->get('/page/{page_number}', [\app\modules\tag\controllers\TagController::class, 'actionIndex']);
App::$collector->get('/create', [\app\modules\tag\controllers\TagController::class, 'actionCreate']);
App::$collector->post("/", [\app\modules\tag\controllers\TagController::class, 'actionAdd']);
App::$collector->get('/view/{id}', [\app\modules\tag\controllers\TagController::class, 'actionView']);
App::$collector->any('/update/{id}', [\app\modules\tag\controllers\TagController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\app\modules\tag\controllers\TagController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\app\modules\tag\controllers\TagController::class, 'actionDelete']);
});
App::$collector->group(["prefix" => "tag_entity"], function (CGRouteCollector $router) {
App::$collector->get('/', [\kernel\app_modules\tag\controllers\TagEntityController::class, 'actionIndex']);
App::$collector->get('/page/{page_number}', [\kernel\app_modules\tag\controllers\TagEntityController::class, 'actionIndex']);
App::$collector->get('/create', [\kernel\app_modules\tag\controllers\TagEntityController::class, 'actionCreate']);
App::$collector->post("/", [\kernel\app_modules\tag\controllers\TagEntityController::class, 'actionAdd']);
App::$collector->get('view/{id}', [\kernel\app_modules\tag\controllers\TagEntityController::class, 'actionView']);
App::$collector->any('/update/{id}', [\kernel\app_modules\tag\controllers\TagEntityController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\kernel\app_modules\tag\controllers\TagEntityController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\kernel\app_modules\tag\controllers\TagEntityController::class, 'actionDelete']);
});
App::$collector->group(["prefix" => "settings"], function (CGRouteCollector $router) {
App::$collector->get('/tag', [\app\modules\tag\controllers\TagController::class, 'actionSettings']);
App::$collector->post('/tag/update', [\app\modules\tag\controllers\TagController::class, 'actionSaveSettings']);
});
});
});

View File

@ -0,0 +1,51 @@
<?php
namespace kernel\app_modules\tag\service;
use kernel\app_modules\tag\models\Tag;
use kernel\app_modules\tag\models\TagEntity;
use kernel\FormModel;
use kernel\helpers\Debug;
use kernel\helpers\Slug;
class TagEntityService
{
public function create(FormModel $form_model): false|TagEntity
{
$model = new TagEntity();
$model->tag_id = $form_model->getItem('tag_id');
$model->entity = $form_model->getItem('entity');
$model->entity_id = $form_model->getItem('entity_id');
if ($model->save()){
return $model;
}
return false;
}
public function update(FormModel $form_model, TagEntity $tag): false|TagEntity
{
$tag->tag_id = $form_model->getItem('tag_id');
$tag->entity = $form_model->getItem('entity');
$tag->entity_id = $form_model->getItem('entity_id');
if ($tag->save()){
return $tag;
}
return false;
}
public static function getTagsByEntity(string $entity, int $entity_id): array
{
$tags= TagEntity::where("entity_id", $entity_id)->where("entity", $entity)->get();
$value = [];
foreach ($tags as $tag) {
$value[$tag->id] = $tag->tag->label;
}
return $value;
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace kernel\app_modules\tag\service;
use kernel\app_modules\tag\models\Tag;
use kernel\FormModel;
use kernel\helpers\Debug;
use kernel\helpers\Slug;
use kernel\services\ModuleService;
class TagService
{
public function create(FormModel $form_model): false|Tag
{
$model = new Tag();
$model->label = $form_model->getItem('label');
$model->entity = $form_model->getItem('entity');
$model->status = $form_model->getItem('status');
$model->slug = Slug::createSlug($form_model->getItem('label'), Tag::class);
if ($model->save()){
return $model;
}
return false;
}
public function update(FormModel $form_model, Tag $tag): false|Tag
{
if ($tag->label !== $form_model->getItem('label')) {
$tag->slug = Slug::createSlug($form_model->getItem('label'), Tag::class);
}
$tag->label = $form_model->getItem('label');
$tag->entity = $form_model->getItem('entity');
$tag->status = $form_model->getItem('status');
if ($tag->save()){
return $tag;
}
return false;
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* @var Tag $model
*/
use kernel\app_modules\tag\models\Tag;
$form = new \itguild\forms\ActiveForm();
$form->beginForm(isset($model) ? "/admin/tag/edit/" . $model->id : "/admin/tag");
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "label", params: [
'class' => "form-control",
'placeholder' => 'Заголовок',
'value' => $model->label ?? ''
])
->setLabel("Заголовок")
->render();
$form->field(class: \itguild\forms\inputs\Select::class, name: "entity", params: [
'class' => "form-control",
'value' => $model->entity ?? ''
])
->setLabel("Сущность")
->setOptions(\kernel\EntityRelation::getEntityList())
->render();
$form->field(\itguild\forms\inputs\Select::class, 'status', [
'class' => "form-control",
'value' => $model->status ?? ''
])
->setLabel("Статус")
->setOptions(Tag::getStatus())
->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();

View File

@ -0,0 +1,40 @@
<?php
/**
* @var int $page_number
*/
use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable;
use kernel\app_modules\tag\models\Tag;
use kernel\IGTabel\btn\PrimaryBtn;
use kernel\models\Menu;
use kernel\modules\menu\table\columns\MenuDeleteActionColumn;
use kernel\modules\menu\table\columns\MenuEditActionColumn;
use kernel\modules\menu\table\columns\MenuViewActionColumn;
$table = new ListEloquentTable(new EloquentDataProvider(Tag::class, [
'currentPage' => $page_number,
'perPage' => 8,
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/tag",
]));
$table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/tag/create")->fetch();
});
$table->columns([
"status" => [
"value" => function ($cell) {
return Tag::getStatus()[$cell];
}]
]);
\kernel\widgets\TagTabsWidget::create()->run();
$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class);
$table->addAction(\kernel\IGTabel\action_column\DeleteActionColumn::class);
$table->addAction(\kernel\IGTabel\action_column\EditActionColumn::class);
$table->create();
$table->render();

View File

@ -0,0 +1,47 @@
<?php
$form = new \itguild\forms\ActiveForm();
$form->beginForm("/admin/settings/tag/update");
//\kernel\helpers\Debug::dd($value);
?>
<div class="row">
<h5>Выберите сущности, к которым хотите прикрепить теги</h5>
</div>
<?php
$form->field(\itguild\forms\inputs\Select::class, "entity[]", [
'class' => "form-control",
'value' => \kernel\EntityRelation::getEntityByProperty('tag') ?? '',
'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();

View File

@ -0,0 +1,30 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $tag
*/
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;
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($tag, [
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/tag",
]));
$table->beforePrint(function () use ($tag) {
$btn = PrimaryBtn::create("Список", "/admin/tag")->fetch();
$btn .= SuccessBtn::create("Редактировать", "/admin/tag/update/" . $tag->id)->fetch();
$btn .= DangerBtn::create("Удалить", "/admin/tag/delete/" . $tag->id)->fetch();
return $btn;
});
$table->rows([
'status' => (function ($data) {
return \kernel\app_modules\tag\models\Tag::getStatus()[$data];
})
]);
$table->create();
$table->render();

View File

@ -0,0 +1,34 @@
<?php
/**
* @var int $page_number
*/
use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable;
use kernel\app_modules\tag\models\Tag;
use kernel\IGTabel\btn\PrimaryBtn;
$table = new ListEloquentTable(new EloquentDataProvider(\kernel\app_modules\tag\models\TagEntity::class, [
'currentPage' => $page_number,
'perPage' => 8,
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/tag_entity",
]));
$table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/tag_entity/create")->fetch();
});
$table->columns([
"tag_id" => [
"value" => function ($data) {
return Tag::find($data)->label;
}]
]);
$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class);
$table->addAction(\kernel\IGTabel\action_column\DeleteActionColumn::class);
$table->addAction(\kernel\IGTabel\action_column\EditActionColumn::class);
\kernel\widgets\TagTabsWidget::create()->run();
$table->create();
$table->render();

View File

@ -0,0 +1,30 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $tagEntity
*/
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;
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($tagEntity, [
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/tag",
]));
$table->beforePrint(function () use ($tagEntity) {
$btn = PrimaryBtn::create("Список", "/admin/tag_entity")->fetch();
$btn .= SuccessBtn::create("Редактировать", "/admin/tag_entity/update/" . $tagEntity->id)->fetch();
$btn .= DangerBtn::create("Удалить", "/admin/tag_entity/delete/" . $tagEntity->id)->fetch();
return $btn;
});
$table->rows([
'tag_id' => (function ($data) {
return \kernel\app_modules\tag\models\Tag::find($data)->label;
})
]);
$table->create();
$table->render();

View File

@ -0,0 +1,31 @@
<?php
namespace kernel\app_themes\custom;
use kernel\modules\menu\service\MenuService;
use kernel\services\MigrationService;
class CustomTheme
{
public MenuService $menuService;
public MigrationService $migrationService;
public function __construct()
{
$this->menuService = new MenuService();
$this->migrationService = new MigrationService();
}
/**
* @throws \Exception
*/
public function init(): void
{
//TODO
}
public function deactivate(): void
{
//TODO
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace kernel\app_themes\custom\services;
class CustomThemeService
{
}

0
kernel/console/ConsoleApp.php Executable file → Normal file
View File

0
kernel/console/ConsoleController.php Executable file → Normal file
View File

19
kernel/console/Out.php Executable file → Normal file
View File

@ -4,6 +4,8 @@
namespace kernel\console;
use kernel\helpers\Debug;
class Out
{
private $foreground_colors = array();
@ -64,6 +66,11 @@ class Out
echo $this->get($string, $foreground_color, $background_color) . "\n";
}
public function inLine($string, $foreground_color = null, $background_color = null): void
{
echo $this->get($string, $foreground_color, $background_color) ;
}
// Returns all foreground color names
public function getForegroundColors()
{
@ -75,4 +82,16 @@ class Out
{
return array_keys($this->background_colors);
}
// public function printHeaderTable(): void
// {
// echo "\n+-----------------------------+-----------------------------+-----------------------------+-----------------------------+\n";
// printf("%-30s", "| Routs");
// printf("%-30s", "| Description");
// printf("%-30s", "| Params");
// printf("%-30s", "| Params description");
// printf("%-30s", "|");
// echo "\n+-----------------------------+-----------------------------+-----------------------------+-----------------------------+\n";
// }
}

View File

@ -0,0 +1,184 @@
<?php
namespace kernel\console\controllers;
use kernel\console\ConsoleController;
use kernel\modules\menu\service\MenuService;
use kernel\modules\option\service\OptionService;
use kernel\modules\user\models\forms\CreateUserForm;
use kernel\modules\user\models\User;
use kernel\modules\user\service\UserService;
use kernel\services\MigrationService;
class AdminConsoleController extends ConsoleController
{
protected MigrationService $migrationService;
protected OptionService $optionService;
protected MenuService $menuService;
protected UserService $userService;
public function __construct()
{
parent::__construct();
$this->migrationService = new MigrationService();
$this->optionService = new OptionService();
$this->menuService = new MenuService();
$this->userService = new UserService();
}
/**
* @throws \Exception
*/
public function actionInit(): void
{
$out = $this->migrationService->runAtPath("kernel/modules/menu/migrations");
$this->out->r("create menu table", "green");
$out = $this->migrationService->runAtPath("kernel/modules/option/migrations");
$this->out->r("create option table", "green");
$out = $this->migrationService->runAtPath("kernel/modules/user/migrations");
$this->out->r("create user table", "green");
$out = $this->migrationService->runAtPath("kernel/modules/post/migrations");
$this->out->r("create post table", "green");
$out = $this->migrationService->runAtPath("kernel/modules/secure/migrations");
$this->out->r("create secret_code table", "green");
$this->optionService->createFromParams(
key: "admin_theme_paths",
value: "{\"paths\": [\"{KERNEL_ADMIN_THEMES}\", \"{APP}/admin_themes\"]}",
label: "Пути к темам админпанели"
);
$this->out->r("create option admin_theme_paths", "green");
$this->optionService->createFromParams(
key: "active_admin_theme",
value: "{KERNEL_ADMIN_THEMES}/default",
label: "Активная тема админпанели"
);
$this->out->r("create option active_admin_theme", "green");
$this->optionService->createFromParams(
key: "theme_paths",
value: "{\"paths\": [\"{KERNEL}/themes\", \"{APP}/themes\"]}",
label: "Пути к темам сайта"
);
$this->out->r("create option theme_paths", "green");
$this->optionService->createFromParams(
key: "active_theme",
value: "{KERNEL}/themes/default",
label: "Активная тема сайта"
);
$this->out->r("create option active_theme", "green");
$this->optionService->createFromParams(
key: "module_paths",
value: "{\"paths\": [\"{KERNEL_MODULES}\", \"{APP}/modules\"]}",
label: "Пути к модулям"
);
$this->out->r("create option module_paths", "green");
$this->optionService->createFromParams(
key: "active_modules",
value: "{\"modules\":[\"admin_themes\",\"themes\",\"secure\", \"user\", \"menu\", \"post\", \"option\"]}",
label: "Активные модули"
);
$this->out->r("create option active_modules", "green");
$this->optionService->createFromParams(
key: "entity_relations",
value: "{}",
label: "Свойства сущностей"
);
$this->out->r("create option entity_relations", "green");
$this->menuService->createItem([
"label" => "Модули",
"url" => "/admin",
"slug" => "module",
"priority" => 1,
]);
$this->out->r("create item menu module", "green");
$this->menuService->createItem([
"label" => "Пользователи",
"url" => "#",
"slug" => "user",
]);
$this->menuService->createItem([
"label" => "Список",
"url" => "/admin/user",
"slug" => "user_list",
"parent_slug" => "user",
]);
$this->menuService->createItem([
"label" => "Создать",
"url" => "/admin/user/create",
"slug" => "user_create",
"parent_slug" => "user",
]);
$this->out->r("create item menu user", "green");
$this->menuService->createItem([
"label" => "Посты",
"url" => "/admin/post",
"slug" => "post",
]);
$this->out->r("create item menu post", "green");
$this->menuService->createItem([
"label" => "Настройки",
"url" => "#",
"slug" => "settings",
]);
$this->out->r("create item menu settings", "green");
$this->menuService->createItem([
"label" => "Темы админпанели",
"url" => "/admin/settings/admin-themes",
"slug" => "admin-themes",
"parent_slug" => "settings"
]);
$this->out->r("create item menu admin-themes", "green");
$this->menuService->createItem([
"label" => "Темы сайта",
"url" => "/admin/settings/themes",
"slug" => "themes",
"parent_slug" => "settings"
]);
$this->out->r("create item menu themes", "green");
$this->menuService->createItem([
"label" => "Меню",
"url" => "/admin/settings/menu",
"slug" => "menu",
"parent_slug" => "settings"
]);
$this->out->r("create item menu menu", "green");
$this->menuService->createItem([
"label" => "Опции",
"url" => "/admin/option",
"slug" => "option"
]);
$this->out->r("create item menu option", "green");
$user = new CreateUserForm();
$user->load([
'username' => 'admin',
'password' => 'ChangeMe',
'email' => 'admin@test.ru',
'role' => User::ADMIN_USER_ROLE,
]);
$this->userService->create($user);
$this->out->r("create user with username admin", "green");
}
}

View File

@ -18,31 +18,15 @@ class AdminThemeController extends ConsoleController
throw new \Exception('Missing admin theme path "--path" specified');
}
$zip = new ZipArchive;
$tmpThemeDir = md5(time());
$res = $zip->open(ROOT_DIR . $this->argv['path']);
if ($res === TRUE) {
$tmpThemeDirFull = RESOURCES_DIR . '/tmp/ad/' . $tmpThemeDir . "/";
$zip->extractTo($tmpThemeDirFull);
$zip->close();
$this->out->r('Архив распакован', 'green');
if (file_exists(ROOT_DIR . $this->argv['path'])) {
$adminThemeService = new AdminThemeService();
if ($adminThemeService->install($this->argv['path'])) {
$this->out->r("Тема админ-панели установлена", 'green');
} else {
$this->out->r("Ошибка установки темы админ-панели", 'red');
}
} else {
$this->out->r('Message: Ошибка чтения архива', 'red');
}
if (file_exists($tmpThemeDirFull . "meta/manifest.json")){
$manifestJson = getConst(file_get_contents($tmpThemeDirFull . "meta/manifest.json"));
$manifest = Manifest::getWithVars($manifestJson);
$this->out->r('manifest.json инициализирован', 'green');
$fileHelper = new Files();
$fileHelper->copy_folder($tmpThemeDirFull . "meta", $manifest['theme_path']);
$fileHelper->copy_folder($tmpThemeDirFull . "resources", $manifest['resource_path']);
$this->out->r("Удаляем временные файлы", 'green');
$fileHelper->recursiveRemoveDir($tmpThemeDirFull);
$this->out->r("Тема " . $manifest['name'] . " установлена", 'green');
$this->out->r("Тема админ-панели не найдена", 'red');
}
}
@ -53,19 +37,11 @@ class AdminThemeController extends ConsoleController
}
if (file_exists(ROOT_DIR . $this->argv['path'])) {
$themeName = basename($this->argv['path']);
$active_admin_theme = Option::where("key", "active_admin_theme")->first();
var_dump($active_admin_theme->value);
var_dump(ROOT_DIR . $this->argv['path']);
if ($active_admin_theme->value === ROOT_DIR . $this->argv['path']) {
$this->out->r("Меняем тему на базовую", 'green');
$adminThemeService = new AdminThemeService();
$adminThemeService->setActiveAdminTheme(KERNEL_ADMIN_THEMES_DIR . '/default');
$this->out->r("Тема изменена", 'green');
}
$fileHelper = new Files();
$fileHelper->recursiveRemoveDir(ROOT_DIR . $this->argv['path']);
$fileHelper->recursiveRemoveDir(RESOURCES_DIR . '/' . $themeName);
$adminThemeService = new AdminThemeService();
$adminThemeService->uninstall($this->argv['path']);
$this->out->r("Тема удалена", 'green');
} else {
@ -73,4 +49,22 @@ class AdminThemeController extends ConsoleController
}
}
/**
* @throws \Exception
*/
public function actionPackTheme(): void
{
if (!isset($this->argv['path'])) {
throw new \Exception('Missing admin theme path "--path" specified');
}
if (file_exists(ROOT_DIR . $this->argv['path'])) {
$adminThemeService = new AdminThemeService();
$adminThemeService->pack($this->argv['path']);
$this->out->r("Тема админ-панели заархивирована", 'green');
} else {
$this->out->r("Тема админ-панели не найдена", 'red');
}
}
}

View File

@ -0,0 +1,128 @@
<?php
namespace kernel\console\controllers;
use kernel\console\ConsoleController;
use kernel\helpers\Files;
use ZipArchive;
class KernelController extends ConsoleController
{
protected Files $files;
public function __construct()
{
parent::__construct();
$this->files = new Files();
}
/**
* @throws \Exception
*/
public function actionPackKernel(): void
{
if (!isset($this->argv['path'])) {
throw new \Exception('Missing kernel path "--path" specified');
}
if (file_exists(ROOT_DIR . $this->argv['path'])) {
$tmpKernelDirFull = RESOURCES_DIR . '/tmp/ad/kernel/kernel';
$this->files->copyKernelFolder(ROOT_DIR . $this->argv['path'], $tmpKernelDirFull);
$this->out->r("Ядро скопировано во временную папку", 'green');
} else {
$this->out->r("Ядро не найдено", 'red');
}
if (file_exists(ROOT_DIR . '/bootstrap')) {
$tmpBootstrapDirFull = RESOURCES_DIR . '/tmp/ad/kernel/bootstrap';
$this->files->copyKernelFolder(ROOT_DIR . '/bootstrap', $tmpBootstrapDirFull);
$this->out->r("/bootstrap скопирован во временную папку", 'green');
} else {
$this->out->r("/bootstrap не найден", 'red');
}
if (file_exists(ROOT_DIR . '/bootstrap.php')) {
$tmpBootstrapPhpDirFull = RESOURCES_DIR . '/tmp/ad/kernel/bootstrap.php';
copy(ROOT_DIR . '/bootstrap.php', $tmpBootstrapPhpDirFull);
$this->out->r("/bootstrap.php скопирован во временную папку", 'green');
} else {
$this->out->r("/bootstrap.php не найден", 'red');
}
if (file_exists(ROOT_DIR . '/.env.example')) {
$tmpEnvDirFull = RESOURCES_DIR . '/tmp/ad/kernel/env.example';
copy(ROOT_DIR . '/.env.example', $tmpEnvDirFull);
$this->out->r("/.env.example скопирован во временную папку", 'green');
} else {
$this->out->r("/.env.example не найден", 'red');
}
if (file_exists(ROOT_DIR . '/composer.json')) {
$tmpComposerDirFull = RESOURCES_DIR . '/tmp/ad/kernel/composer.json';
copy(ROOT_DIR . '/composer.json', $tmpComposerDirFull);
$this->out->r("/composer.json скопирован во временную папку", 'green');
} else {
$this->out->r("/composer.json не найден", 'red');
}
if (!is_dir(RESOURCES_DIR . '/tmp/kernel')) {
mkdir(RESOURCES_DIR . '/tmp/kernel');
}
if (file_exists(KERNEL_DIR . '/manifest.json')) {
$manifest = json_decode(file_get_contents(KERNEL_DIR . '/manifest.json'), true);
$version = $manifest['version'] ?? '';
$this->files->pack(RESOURCES_DIR . '/tmp/ad/kernel/', RESOURCES_DIR . '/tmp/kernel/kernel_v' . $version . '.igk');
}
else {
$this->files->pack(RESOURCES_DIR . '/tmp/ad/kernel/', RESOURCES_DIR . '/tmp/kernel/kernel.igk');
}
$this->files->recursiveRemoveDir(RESOURCES_DIR . '/tmp/ad/kernel/');
}
/**
* @throws \Exception
*/
public function actionUpdateKernel(): void
{
if (!isset($this->argv['path'])) {
throw new \Exception('Missing kernel path "--path" specified');
}
$zip = new ZipArchive;
if (file_exists(ROOT_DIR . $this->argv['path'])) {
$tmpKernelDir = md5(time());
$res = $zip->open(ROOT_DIR . $this->argv['path']);
if ($res === TRUE) {
$tmpKernelDirFull = RESOURCES_DIR . '/tmp/kernel/' . $tmpKernelDir . "/";
$zip->extractTo($tmpKernelDirFull);
$zip->close();
$this->files->recursiveRemoveKernelDir();
$this->files->copyKernelFolder($tmpKernelDirFull . 'kernel' , ROOT_DIR . "/kernel");
if (isset($this->argv['bootstrap'])) {
$this->files->recursiveRemoveDir(ROOT_DIR . '/bootstrap');
$this->files->copyKernelFolder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap');
copy($tmpKernelDirFull . '/bootstrap.php' , ROOT_DIR . '/bootstrap.php');
}
if (isset($this->argv['env'])) {
copy($tmpKernelDirFull . 'env.example', ROOT_DIR . '/.env.example');
}
if (isset($this->argv['composer'])) {
copy($tmpKernelDirFull . 'composer.json', ROOT_DIR . '/composer.json');
}
$this->files->recursiveRemoveDir($tmpKernelDirFull);
$this->out->r('Ядро обновлено.', 'green');
} else {
$this->out->r('unable to open zip archive', 'red');
}
} else {
$this->out->r("archive not found", 'red');
}
}
}

View File

@ -2,7 +2,9 @@
namespace kernel\console\controllers;
use kernel\App;
use kernel\console\ConsoleController;
use kernel\helpers\Debug;
class MainController extends ConsoleController
{
@ -12,4 +14,25 @@ class MainController extends ConsoleController
$this->out->r("Привет", "green");
}
public function actionHelp(): void
{
$routs = App::$collector->getData()->getStaticRoutes();
foreach ($routs as $rout => $data){
$additionalInfo = $data['GET'][3];
if (isset($additionalInfo['description']) and $additionalInfo['type'] === "console"){
$this->out->inLine($rout . " - ", "green");
$this->out->inLine($additionalInfo['description'], 'yellow');
$this->out->r("");
if (isset($additionalInfo['params'])){
foreach ($additionalInfo['params'] as $key => $param){
$this->out->inLine($key . " - ", "green");
$this->out->inLine($param, 'yellow');
$this->out->r("");
}
}
$this->out->r("");
}
}
}
}

View File

@ -19,6 +19,7 @@ use kernel\services\ModuleService;
class MigrationController extends ConsoleController
{
protected ModuleService $moduleService;
public function __construct()
{
parent::__construct();
@ -35,8 +36,7 @@ class MigrationController extends ConsoleController
$table->integer('batch');
});
$this->out->r("Success", 'green');
}
catch (\Exception $e){
} catch (\Exception $e) {
$this->out->r($e->getMessage(), 'red');
}
}
@ -60,7 +60,7 @@ class MigrationController extends ConsoleController
);
$this->out->r(basename($res) . " created", 'green');
} catch (\Exception $e) {
$this->out->r('Message: ' .$e->getMessage(), 'red');
$this->out->r('Message: ' . $e->getMessage(), 'red');
}
}
@ -71,15 +71,23 @@ class MigrationController extends ConsoleController
$dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration');
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), new Filesystem());
$migrationPaths = array_merge($this->moduleService->getModulesMigrationsPaths(), [ROOT_DIR . '/migrations']);
//$migrationPaths = [ROOT_DIR . '/migrations'];
if (isset($this->argv['path'])){
$migrationPaths = [ROOT_DIR . $this->argv['path']];
}
else {
if (\kernel\App::$db->schema->hasTable('option')) {
$migrationPaths = array_merge($this->moduleService->getModulesMigrationsPaths(), [ROOT_DIR . '/migrations']);
} else {
$migrationPaths = [ROOT_DIR . '/migrations'];
}
}
$res = $m->run($migrationPaths);
foreach ($res as $re){
foreach ($res as $re) {
$this->out->r(basename($re), 'green');
}
}
catch (\Exception $e){
$this->out->r('Message: ' .$e->getMessage(), 'red');
} catch (\Exception $e) {
$this->out->r('Message: ' . $e->getMessage(), 'red');
}
}
@ -91,15 +99,20 @@ class MigrationController extends ConsoleController
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), new Filesystem());
//$migrationPaths = array_merge(App::$migrationsPaths, [WORKSPACE_DIR . '/console/migrations']);
$migrationPaths = [ROOT_DIR . '/migrations'];
if (isset($this->argv['path'])){
$migrationPaths = [ROOT_DIR . $this->argv['path']];
}
else {
$migrationPaths = [ROOT_DIR . '/migrations'];
}
$res = $m->rollback($migrationPaths, ['step' => $step]);
print_r($step);
foreach ($res as $re){
foreach ($res as $re) {
$this->out->r(basename($re), 'green');
}
}
catch (\Exception $e){
$this->out->r('Message: ' .$e->getMessage(), 'red');
} catch (\Exception $e) {
$this->out->r('Message: ' . $e->getMessage(), 'red');
}
}
}

View File

@ -0,0 +1,122 @@
<?php
namespace kernel\console\controllers;
use kernel\console\ConsoleController;
use kernel\helpers\Debug;
use kernel\helpers\Files;
use kernel\helpers\Manifest;
use kernel\models\Option;
use ZipArchive;
use kernel\services\ModuleService;
class ModuleController extends ConsoleController
{
/**
* @throws \Exception
*/
public function actionInstallModule(): void
{
if (!isset($this->argv['path'])) {
throw new \Exception('Missing module path "--path" specified');
}
if (file_exists(ROOT_DIR . $this->argv['path'])) {
$moduleService = new ModuleService();
if ($moduleService->installModule($this->argv['path'])) {
$this->out->r("Модуль установлен", 'green');
} else {
$this->out->r("Ошибка установки модуля", 'red');
}
} else {
$this->out->r("Модуль не найден", 'red');
}
}
/**
* @throws \Exception
*/
public function actionUninstallModule(): void
{
if (!isset($this->argv['path'])) {
throw new \Exception('Missing module path "--path" specified');
}
if (file_exists(ROOT_DIR . $this->argv['path'])) {
$moduleService = new ModuleService();
$moduleService->uninstallModule($this->argv['path']);
$this->out->r("Модуль удален", 'green');
} else {
$this->out->r("Модуль не найден", 'red');
}
}
/**
* @throws \Exception
*/
public function actionPackModule(): void
{
if (!isset($this->argv['path'])) {
throw new \Exception('Missing module path "--path" specified');
}
if (file_exists(ROOT_DIR . $this->argv['path'])) {
$moduleService = new ModuleService();
$moduleService->packModule($this->argv['path']);
$this->out->r("Модуль заархивирован", 'green');
} else {
$this->out->r("Модуль не найден", 'red');
}
}
/**
* @throws \Exception
*/
public function actionUpdateModule(): void
{
if (!isset($this->argv['path'])) {
throw new \Exception('Missing module path "--path" specified');
}
if (file_exists(ROOT_DIR . $this->argv['path'])) {
$moduleService = new ModuleService();
if ($moduleService->updateModule($this->argv['path'])) {
$this->out->r("Модуль обновлен", 'green');
} else {
$this->out->r("Ошибка обновления модуля", 'red');
}
} else {
$this->out->r("Модуль не найден", 'red');
}
}
public function actionConstructModule(): void
{
$this->out->r("Введите slug модуля:", 'yellow');
$slug = substr(fgets(STDIN), 0, -1);
$slug = strtolower($slug);
$this->out->r("Введите название модуля:", 'yellow');
$name = substr(fgets(STDIN), 0, -1);
$this->out->r("Введите автора модуля:", 'yellow');
$author = substr(fgets(STDIN), 0, -1);
$this->out->r("Введите название пунтка меню для модуля:", 'yellow');
$label = substr(fgets(STDIN), 0, -1);
$moduleService = new ModuleService();
$moduleService->createDirs($slug);
$moduleService->createModuleByParams([
'slug' => $slug,
'model' => ucfirst($slug),
'author' => $author,
'name' => $name,
'label' => $label,
]);
$this->out->r("Модуль $slug создан", 'green');
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace kernel\console\controllers;
use kernel\console\ConsoleController;
use kernel\services\TokenService;
use Random\RandomException;
class SecureController extends ConsoleController
{
/**
* @throws RandomException
*/
public function actionCreateSecretKey(): void
{
$envFile = \EnvEditor\EnvFile::loadFrom(ROOT_DIR . "/.env");
$envFile->setValue("SECRET_KEY", TokenService::random_bytes(15));
$envFile->saveTo(ROOT_DIR . "/.env");
$this->out->r("Secret key successfully created.", "green");
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace kernel\console\controllers;
use kernel\console\ConsoleController;
use kernel\helpers\Files;
use kernel\helpers\Manifest;
use kernel\models\Option;
use kernel\services\AdminThemeService;
use kernel\services\ThemeService;
use ZipArchive;
class ThemeController extends ConsoleController
{
/**
* @throws \Exception
*/
public function actionInstallTheme(): void
{
if (!isset($this->argv['path'])) {
throw new \Exception('Missing theme path "--path" specified');
}
if (file_exists(ROOT_DIR . $this->argv['path'])) {
$themeService = new ThemeService();
if ($themeService->install($this->argv['path'])) {
$this->out->r("Тема сайта установлена", 'green');
} else {
$this->out->r("Ошибка установки темы сайта", 'red');
}
} else {
$this->out->r("Тема сайта не найдена", 'red');
}
}
/**
* @throws \Exception
*/
public function actionUninstallTheme(): void
{
if (!isset($this->argv['path'])) {
throw new \Exception('Missing theme path "--path" specified');
}
if (file_exists(ROOT_DIR . $this->argv['path'])) {
$themeService = new ThemeService();
$themeService->uninstall($this->argv['path']);
$this->out->r("Тема сайта удалена", 'green');
} else {
$this->out->r("Тема сайта не найдена", 'red');
}
}
/**
* @throws \Exception
*/
public function actionPackTheme(): void
{
if (!isset($this->argv['path'])) {
throw new \Exception('Missing theme path "--path" specified');
}
if (file_exists(ROOT_DIR . $this->argv['path'])) {
$themeService = new ThemeService();
$themeService->pack($this->argv['path']);
$this->out->r("Тема сайта заархивирована", 'green');
} else {
$this->out->r("Тема сайта не найдена", 'red');
}
}
}

0
kernel/console/migrations/stubs/blank.stub Executable file → Normal file
View File

Some files were not shown because too many files have changed in this diff Show More