Compare commits

..

35 Commits

Author SHA1 Message Date
2b02ca4471 v0.1.11 2025-08-01 15:06:16 +03:00
b86b8ff923 v0.1.10 2025-08-01 14:29:50 +03:00
2ab819ff30 v0.1.8 2025-06-22 15:27:26 +03:00
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
658 changed files with 26437 additions and 178 deletions

1
.gitignore vendored
View File

@@ -5,3 +5,4 @@ views_cache
resources/upload
resources/tmp
composer.lock
kernel/app_themes

View File

@@ -6,8 +6,8 @@
"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

@@ -1,6 +1,6 @@
{
"name": "Photo",
"version": "0.1",
"version": "0.2",
"author": "ITGuild",
"slug": "photo",
"type": "additional_property",

View File

@@ -1,6 +1,6 @@
{
"name": "Tags",
"version": "0.1",
"version": "0.1.1",
"author": "ITGuild",
"slug": "tag",
"type": "additional_property",

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

@@ -7,6 +7,7 @@ $dotenv->load();
include_once __DIR__ . "/bootstrap/db.php";
include_once __DIR__ . "/bootstrap/header.php";
include_once __DIR__ . "/bootstrap/secure.php";
include_once __DIR__ . "/bootstrap/notification.php";
const ROOT_DIR = __DIR__;
const KERNEL_DIR = __DIR__ . "/kernel";
const KERNEL_MODULES_DIR = __DIR__ . "/kernel/modules";
@@ -18,7 +19,7 @@ const KERNEL_APP_MODULES_DIR = KERNEL_DIR . "/app_modules";
const APP_DIR = ROOT_DIR . "/app";
\kernel\Theme::$assetsCollector = new \kernel\AssetsCollector();
function getConst($text): array|false|string
{

View File

@@ -0,0 +1,4 @@
<?php
\kernel\App::$notificationDispatcher = new \kernel\modules\notification\NotificationDispatcher();
\kernel\App::$notificationDispatcher->addChannel('email', new \kernel\modules\notification\channels\EmailChannel());

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,8 +5,10 @@ namespace kernel;
use kernel\helpers\Debug;
use kernel\modules\notification\NotificationDispatcher;
use kernel\modules\user\models\User;
use kernel\services\ModuleService;
use kernel\services\ThemeService;
use Phroute\Phroute\Dispatcher;
class App
@@ -20,10 +22,16 @@ class App
static User $user;
static NotificationDispatcher $notificationDispatcher;
static array $secure;
public ModuleService $moduleService;
static Hook $hook;
public ThemeService $themeService;
public static Database $db;
public function run(): void
@@ -38,6 +46,7 @@ class App
public function load(): static
{
App::$hook = new Hook();
$this->moduleService = new ModuleService();
App::$collector = new CgRouteCollector();
$this->setRouting();
@@ -50,9 +59,16 @@ class App
include KERNEL_DIR . "/routs/admin.php";
include ROOT_DIR . "/rout.php";
$modules_routs = $this->moduleService->getModulesRouts();
$this->moduleService->setModulesHooks();
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

82
kernel/Assets.php Normal file
View File

@@ -0,0 +1,82 @@
<?php
namespace kernel;
class Assets
{
protected array $jsHeader = [];
protected array $jsBody = [];
protected array $collectorJs = [];
protected array $css = [];
protected array $collectorCss = [];
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, string $after = null): void
{
$resource = $addResourceURI ? $this->resourceURI . $resource : $resource;
if ($body) {
$this->jsBody[$slug] = $resource;
} else {
$this->jsHeader[$slug] = $resource;
}
$this->collectorJs[$slug] = ['resource' => $resource, 'after' => $after, 'body' => $body];
}
public function registerCSS(string $slug, string $resource, bool $addResourceURI = true, string $after = null): void
{
$resource = $addResourceURI ? $this->resourceURI . $resource : $resource;
$this->css[$slug] = $resource;
$this->collectorCss[$slug] = ['resource' => $resource, 'after' => $after];
}
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'>";
}
}
public function getCollectorCss(): array
{
return $this->collectorCss;
}
public function getCollectorJs(): array
{
return $this->collectorJs;
}
}

128
kernel/AssetsCollector.php Normal file
View File

@@ -0,0 +1,128 @@
<?php
namespace kernel;
use RuntimeException;
class AssetsCollector
{
protected array $assetsPool = [];
public function registerAsset(Assets $assets): void
{
$this->assetsPool[] = $assets;
}
public function renderCss(): void
{
$css = [];
foreach ($this->assetsPool as $item) {
/** @var Assets $item */
$css = array_merge($css, $item->getCollectorCss());
}
try {
$sortedStyles = $this->sortStyles($css);
// Выводим отсортированные стили
foreach ($sortedStyles as $style) {
echo '<link rel="stylesheet" href="' . htmlspecialchars($style) . '">' . "\n";
}
} catch (RuntimeException $e) {
echo 'Ошибка: ' . $e->getMessage();
}
}
public function renderJs(bool $body = true): void
{
$scripts = [];
foreach ($this->assetsPool as $item) {
/** @var Assets $item */
$scripts = array_merge($scripts, $item->getCollectorJs());
}
try {
$sortedScripts = $this->sortScripts($scripts);
// Разделяем скрипты для head и body
$headScripts = [];
$bodyScripts = [];
foreach ($sortedScripts as $script) {
if ($script['body']) {
$bodyScripts[] = $script['resource'];
} else {
$headScripts[] = $script['resource'];
}
}
// Выводим скрипты для head
if ($body){
$scriptsToRender = $bodyScripts;
}
else {
$scriptsToRender = $headScripts;
}
foreach ($scriptsToRender as $script) {
echo '<script src="' . htmlspecialchars($script) . '"></script>' . "\n";
}
}
catch (RuntimeException $e) {
echo 'Ошибка: ' . $e->getMessage();
}
}
protected function sortStyles(array $styles): array
{
$sorted = [];
$added = [];
// Пока не добавим все стили
while (count($sorted) < count($styles)) {
$found = false;
foreach ($styles as $name => $style) {
// Если стиль еще не добавлен и его зависимости выполнены
if (!isset($added[$name]) &&
(empty($style['after']) || isset($added[$style['after']]))) {
$sorted[] = $style['resource'];
$added[$name] = true;
$found = true;
}
}
if (!$found) {
// Если есть циклическая зависимость
throw new RuntimeException('Обнаружена циклическая зависимость в стилях');
}
}
return $sorted;
}
protected function sortScripts(array $scripts): array
{
$sorted = [];
$added = [];
while (count($sorted) < count($scripts)) {
$found = false;
foreach ($scripts as $name => $script) {
if (!isset($added[$name]) &&
(empty($script['after']) || isset($added[$script['after']]))) {
$sorted[] = $script;
$added[$name] = true;
$found = true;
}
}
if (!$found) {
throw new RuntimeException('Обнаружена циклическая зависимость в скриптах');
}
}
return $sorted;
}
}

View File

@@ -2,6 +2,8 @@
namespace kernel;
use kernel\helpers\Debug;
class CgView
{
public string $viewPath = '';
@@ -61,6 +63,13 @@ class CgView
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;

View File

@@ -0,0 +1,345 @@
<?php
namespace kernel;
use Illuminate\Database\Eloquent\Collection;
class CollectionTableRenderer
{
protected \Illuminate\Database\Eloquent\Collection $collection;
protected array $columns;
protected array $tableAttributes;
protected array $customColumns = [];
protected array $valueProcessors = [];
protected array $filters = [];
protected bool $filterRowEnabled = false;
protected array $filterRowAttributes = [
'class' => 'filter-row'
];
/**
* Конструктор класса
*
* @param Collection $collection
*/
public function __construct(Collection $collection)
{
$this->collection = $collection;
$this->columns = [];
$this->customColumns = [];
$this->valueProcessors = [];
$this->filters = [];
$this->tableAttributes = [
'class' => 'table table-bordered table-striped',
'id' => 'dataTable'
];
}
/**
* Установка столбцов для отображения
*
* @param array $columns Массив столбцов в формате ['field' => 'Заголовок']
* @return $this
*/
public function setColumns(array $columns): static
{
$this->columns = $columns;
return $this;
}
/**
* Добавление кастомной колонки
*
* @param string $columnName Название колонки (ключ)
* @param string $title Заголовок колонки
* @param callable $callback Функция для генерации содержимого
* @return $this
*/
public function addCustomColumn(string $columnName, string $title, callable $callback): static
{
$this->customColumns[$columnName] = [
'title' => $title,
'callback' => $callback
];
return $this;
}
/**
* Добавление обработчика значения для колонки
*
* @param string $columnName Название колонки
* @param callable $processor Функция обработки значения
* @return $this
*/
public function addValueProcessor(string $columnName, callable $processor): static
{
$this->valueProcessors[$columnName] = $processor;
return $this;
}
/**
* Добавление фильтра для колонки
*
* @param string $columnName Название колонки
* @param string $filterHtml HTML-код фильтра
* @return $this
*/
public function addFilter(string $columnName, string $filterHtml): static
{
$this->filters[$columnName] = $filterHtml;
$this->filterRowEnabled = true;
return $this;
}
/**
* Включение/отключение строки фильтров
*
* @param bool $enabled
* @return $this
*/
public function enableFilterRow(bool $enabled = true): static
{
$this->filterRowEnabled = $enabled;
return $this;
}
/**
* Установка атрибутов строки фильтров
*
* @param array $attributes
* @return $this
*/
public function setFilterRowAttributes(array $attributes): static
{
$this->filterRowAttributes = array_merge($this->filterRowAttributes, $attributes);
return $this;
}
/**
* Установка атрибутов для таблицы
*
* @param array $attributes Массив атрибутов HTML
* @return $this
*/
public function setTableAttributes(array $attributes): static
{
$this->tableAttributes = array_merge($this->tableAttributes, $attributes);
return $this;
}
/**
* Получить HTML-код таблицы (без вывода)
*
* @return string
*/
public function getHtml(): string
{
if (empty($this->columns) && empty($this->customColumns) && $this->collection->isNotEmpty()) {
// Автоматически определяем столбцы на основе первой модели
$firstItem = $this->collection->first();
$this->columns = array_combine(
array_keys($firstItem->toArray()),
array_map('ucfirst', array_keys($firstItem->toArray()))
);
}
$html = '<table ' . $this->buildAttributes($this->tableAttributes) . '>';
$html .= $this->renderHeader();
if ($this->filterRowEnabled) {
$html .= $this->renderFilterRow();
}
$html .= $this->renderBody();
$html .= '</table>';
return $html;
}
/**
* Генерация HTML-таблицы
*
* @return string
*/
public function render(): void
{
echo $this->getHtml();
}
public function fetch(): string
{
return $this->getHtml();
}
/**
* Генерация заголовка таблицы
*
* @return string
*/
protected function renderHeader(): string
{
$html = '<thead><tr>';
// Обычные колонки
foreach ($this->columns as $title) {
$html .= '<th>' . htmlspecialchars($title) . '</th>';
}
// Кастомные колонки
foreach ($this->customColumns as $column) {
$html .= '<th>' . htmlspecialchars($column['title']) . '</th>';
}
$html .= '</tr></thead>';
return $html;
}
/**
* Генерация строки фильтров
*
* @return string
*/
protected function renderFilterRow(): string
{
$html = '<tr ' . $this->buildAttributes($this->filterRowAttributes) . '>';
// Обычные колонки
foreach (array_keys($this->columns) as $field) {
$html .= '<td>';
if (isset($this->filters[$field])) {
$html .= $this->filters[$field];
} else {
$html .= '&nbsp;';
}
$html .= '</td>';
}
// Кастомные колонки
foreach (array_keys($this->customColumns) as $columnName) {
$html .= '<td>';
if (isset($this->filters[$columnName])) {
$html .= $this->filters[$columnName];
} else {
$html .= '&nbsp;';
}
$html .= '</td>';
}
$html .= '</tr>';
return $html;
}
/**
* Генерация тела таблицы
*
* @return string
*/
protected function renderBody(): string
{
$html = '<tbody>';
foreach ($this->collection as $item) {
$html .= '<tr>';
// Обычные колонки
foreach (array_keys($this->columns) as $field) {
$value = $this->getValue($item, $field);
$value = $this->processValue($field, $value, $item);
$html .= '<td>' . $value . '</td>';
}
// Кастомные колонки
foreach ($this->customColumns as $columnName => $column) {
$value = call_user_func($column['callback'], $item, $columnName);
$html .= '<td>' . $value . '</td>';
}
$html .= '</tr>';
}
$html .= '</tbody>';
return $html;
}
/**
* Обработка значения ячейки
*
* @param string $field Название поля
* @param mixed $value Значение
* @param mixed $item Весь элемент коллекции
* @return mixed
*/
protected function processValue(string $field, mixed $value, mixed $item): mixed
{
// Если есть обработчик для этого поля - применяем его
if (isset($this->valueProcessors[$field])) {
$value = call_user_func($this->valueProcessors[$field], $value, $item, $field);
}
// Если значение не прошло обработку - экранируем его
// if (is_string($value)) {
// return htmlspecialchars($value);
// }
return $value;
}
/**
* Получение значения из элемента коллекции
*
* @param mixed $item
* @param string $field
* @return mixed
*/
protected function getValue(mixed $item, string $field): mixed
{
// Поддержка dot-notation для отношений
if (str_contains($field, '.')) {
return data_get($item, $field);
}
// Поддержка accessor'ов модели
if (method_exists($item, 'get' . ucfirst($field) . 'Attribute')) {
return $item->{$field};
}
return $item->{$field} ?? null;
}
/**
* Сборка HTML-атрибутов
*
* @param array $attributes
* @return string
*/
protected function buildAttributes(array $attributes): string
{
$result = [];
foreach ($attributes as $key => $value) {
$result[] = $key . '="' . htmlspecialchars($value) . '"';
}
return implode(' ', $result);
}
/**
* Магический метод для преобразования в строку
*
* @return string
*/
public function __toString()
{
return $this->render();
}
}

View File

@@ -9,12 +9,13 @@ class Flash
public static function setMessage(string $type, string $msg): void
{
Session::start();
self::start();
Session::set($type, $msg);
}
public static function getMessage(string $type): string
{
self::start();
$msg = Session::get($type, false);
Session::remove($type);
@@ -23,7 +24,16 @@ class Flash
public static function hasMessage(string $type): bool
{
self::start();
return Session::has($type);
}
public static function start()
{
if (!Session::isStarted()){
Session::start();
}
}
}

41
kernel/Hook.php Normal file
View File

@@ -0,0 +1,41 @@
<?php
namespace kernel;
class Hook
{
protected array $pool = [];
public function add(string $entity, \Closure $handler): void
{
$this->pool[] = [
'entity' => $entity,
'handler' => $handler,
];
}
public function getHooksByEntity(string $entity): array
{
$hooks = [];
foreach ($this->pool as $item){
if ($item['entity'] === $entity){
$hooks[] = $item;
}
}
return $hooks;
}
public function runHooksByEntity(string $entity, array $params = []): void
{
$response = '';
$hooks = $this->getHooksByEntity($entity);
foreach ($hooks as $hook){
$response .= call_user_func_array($hook['handler'], $params ?? []);
}
echo $response;
}
}

View File

@@ -17,13 +17,32 @@ class RestController
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 {
@@ -31,7 +50,7 @@ class RestController
}
$expand = $this->expand();
$expandParams = explode( ",", $request->get('expand') ?? "");
$expandParams = explode(",", $request->get('expand') ?? "");
$finalExpand = array_intersect($expandParams, $expand);
if ($finalExpand) {
$res = $query->get()->load($finalExpand)->toArray();
@@ -46,14 +65,14 @@ class RestController
{
$expand = $this->expand();
$request = new Request();
$expandParams = explode( ",", $request->get('expand') ?? "");
$expandParams = explode(",", $request->get('expand') ?? "");
$model = $this->model->where("id", $id)->first();
$finalExpand = array_intersect($expandParams, $expand);
if ($finalExpand){
if ($finalExpand) {
$model->load($finalExpand);
}
$res = [];
if ($model){
if ($model) {
$res = $model->toArray();
}
@@ -64,7 +83,7 @@ class RestController
{
$model = $this->model->where("id", $id)->first();
$res = [];
if ($model){
if ($model) {
$res = $model->toArray();
}
@@ -78,7 +97,7 @@ class RestController
{
$request = new Request();
$data = $request->post();
foreach ($this->model->getFillable() as $item){
foreach ($this->model->getFillable() as $item) {
$this->model->{$item} = $data[$item] ?? null;
}
$this->model->save();
@@ -93,8 +112,8 @@ class RestController
$model = $this->model->where('id', $id)->first();
foreach ($model->getFillable() as $item){
if (!empty($data[$item])){
foreach ($model->getFillable() as $item) {
if (!empty($data[$item])) {
$model->{$item} = $data[$item] ?? null;
}
}
@@ -117,5 +136,4 @@ class RestController
}
}

15
kernel/Theme.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
namespace kernel;
class Theme
{
static AssetsCollector $assetsCollector;
public function __construct()
{
}
}

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

@@ -5,7 +5,12 @@
* @var string $title
* @var \kernel\CgView $view
*/
use kernel\Theme;
\Josantonius\Session\Facades\Session::start();
//$assets = new \kernel\admin_themes\default\DefaultAdminThemeAssets($resources);
Theme::$assetsCollector->registerAsset(new \kernel\admin_themes\default\DefaultAdminThemeAssets($resources));
?>
<!doctype html>
<html lang="en">
@@ -17,19 +22,21 @@
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
<link rel="stylesheet" href="<?= $resources ?>/css/bootstrap.min.css">
<link rel="stylesheet" href="<?= $resources ?>/css/style.css">
<?php Theme::$assetsCollector->renderCss(); ?>
<?php Theme::$assetsCollector->renderJs(body: false); ?>
</head>
<body>
<div class="wrapper d-flex align-items-stretch">
<nav id="sidebar">
<div class="p-4 pt-5">
<a href="<?= '/admin/user/view/' . \kernel\modules\user\service\UserService::getAuthUser()->id ?>" class="img logo rounded-circle mb-5"
style="background-image: url(<?= \kernel\modules\user\service\UserService::getAuthUserPhoto() ?? '/resources/images/noPhoto.png' ?>);"></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>
<?= \kernel\modules\user\service\UserService::getAuthUsername() ?>
<a href="<?= '/admin/user/profile' ?>">
<?= \kernel\modules\user\service\UserService::getAuthUsername() ?>
</a>
</p>
<?php \kernel\widgets\MenuWidget::create()->run(); ?>
<div class="footer">
@@ -74,24 +81,21 @@
</div>
</nav>
<?php if (\kernel\Flash::hasMessage("error")): ?>
<div class="alert alert-danger alert-dismissible mainAlert">
<?= \kernel\Flash::getMessage("error"); ?>
<button type="button" class="btn-close closeAlertBtn"></button>
</div>
<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>
<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 Theme::$assetsCollector->renderJs(); ?>
</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

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

0
kernel/app_modules/tag/controllers/TagController.php Executable file → Normal file
View File

View File

0
kernel/app_modules/tag/models/Tag.php Executable file → Normal file
View File

0
kernel/app_modules/tag/models/TagEntity.php Executable file → Normal file
View File

View File

0
kernel/app_modules/tag/models/forms/CreateTagForm.php Executable file → Normal file
View File

0
kernel/app_modules/tag/routs/tag.php Executable file → Normal file
View File

0
kernel/app_modules/tag/service/TagEntityService.php Executable file → Normal file
View File

0
kernel/app_modules/tag/service/TagService.php Executable file → Normal file
View File

0
kernel/app_modules/tag/views/tag/form.php Executable file → Normal file
View File

0
kernel/app_modules/tag/views/tag/index.php Executable file → Normal file
View File

0
kernel/app_modules/tag/views/tag/view.php Executable file → Normal file
View File

0
kernel/app_modules/tag/views/tag_entity/index.php Executable file → Normal file
View File

0
kernel/app_modules/tag/views/tag_entity/view.php Executable file → Normal file
View File

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
{
}

View File

@@ -49,6 +49,9 @@ class AdminConsoleController extends ConsoleController
$out = $this->migrationService->runAtPath("kernel/modules/secure/migrations");
$this->out->r("create secret_code table", "green");
$out = $this->migrationService->runAtPath("kernel/modules/notification/migrations");
$this->out->r("create notification table", "green");
$this->optionService->createFromParams(
key: "admin_theme_paths",
value: "{\"paths\": [\"{KERNEL_ADMIN_THEMES}\", \"{APP}/admin_themes\"]}",
@@ -63,6 +66,20 @@ class AdminConsoleController extends ConsoleController
);
$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\"]}",
@@ -72,7 +89,7 @@ class AdminConsoleController extends ConsoleController
$this->optionService->createFromParams(
key: "active_modules",
value: "{\"modules\":[\"admin_themes\", \"secure\", \"user\", \"menu\", \"post\", \"option\"]}",
value: "{\"modules\":[\"admin_themes\",\"themes\",\"secure\", \"user\", \"menu\", \"post\", \"option\"]}",
label: "Активные модули"
);
$this->out->r("create option active_modules", "green");
@@ -133,6 +150,14 @@ class AdminConsoleController extends ConsoleController
]);
$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",
@@ -148,6 +173,13 @@ class AdminConsoleController extends ConsoleController
]);
$this->out->r("create item menu option", "green");
$this->menuService->createItem([
"label" => "Уведомления",
"url" => "/admin/notification",
"slug" => "notification"
]);
$this->out->r("create notification option", "green");
$user = new CreateUserForm();
$user->load([
'username' => 'admin',

View File

@@ -71,10 +71,15 @@ class MigrationController extends ConsoleController
$dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration');
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), new Filesystem());
if (\kernel\App::$db->schema->hasTable('option')) {
$migrationPaths = array_merge($this->moduleService->getModulesMigrationsPaths(), [ROOT_DIR . '/migrations']);
} else {
$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);
@@ -94,7 +99,13 @@ 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) {

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

View File

@@ -41,6 +41,21 @@ App::$collector->group(["prefix" => "admin-theme"], callback: function (RouteCol
);
});
App::$collector->group(["prefix" => "theme"], callback: function (RouteCollector $router){
App::$collector->console('install',
[\kernel\console\controllers\ThemeController::class, 'actionInstallTheme'],
additionalInfo: ['description' => 'Установить тему сайта', 'params' => ['--path' => 'Путь к устанавливаемой теме']]
);
App::$collector->console('uninstall',
[\kernel\console\controllers\ThemeController::class, 'actionUninstallTheme'],
additionalInfo: ['description' => 'Удалить тему сайта', 'params' => ['--path' => 'Путь к удаляемой теме']]
);
App::$collector->console('pack',
[\kernel\console\controllers\ThemeController::class, 'actionPackTheme'],
additionalInfo: ['description' => 'Заархивировать тему сайта', 'params' => ['--path' => 'Путь к теме, которую нужно заархивировать']]
);
});
App::$collector->group(["prefix" => "secure"], callback: function (RouteCollector $router){
App::$collector->console('create-secret-key',
[\kernel\console\controllers\SecureController::class, 'actionCreateSecretKey'],

View File

@@ -13,8 +13,9 @@ class BootstrapSelectFilter extends Filter
{
$select = SelectBuilder::build($this->name, [
'class' => 'form-control',
'options' => $this->param,
'options' => $this->params['options'],
'value' => $this->value,
'prompt' => $this->params['prompt'] ?? null,
]);
return "<td>" . $select->create()->fetch() . "</td>";

View File

@@ -1,23 +0,0 @@
<?php
namespace kernel\filters;
use itguild\forms\builders\SelectBuilder;
use Itguild\Tables\Filter\Filter;
use kernel\helpers\Debug;
class BootstrapSelectFilterWithPrompt extends Filter
{
public function fetch(): string
{
$select = SelectBuilder::build($this->name, [
'class' => 'form-control',
'options' => $this->param,
'value' => $this->value,
'prompt' => "Не выбрано"
]);
return "<td>" . $select->create()->fetch() . "</td>";
}
}

View File

@@ -23,6 +23,12 @@ class Html
return "<a href='$link' $paramsStr>";
}
public static function link(string $title, string $link, array $params = []): string
{
$paramsStr = self::createParams($params);
return "<a href='$link' $paramsStr>$title</a>";
}
/**
* @param array $data
* @return string

View File

@@ -0,0 +1,48 @@
<?php
namespace kernel\helpers;
class ImageGD
{
public \GdImage $img;
public function __construct(string $resource = '', int $width = 200, int $height = 200)
{
if ($resource){
$this->img = imagecreatefrompng($resource);
}
else {
$this->img = imagecreatetruecolor($width, $height);
}
imagesavealpha($this->img, true);
}
public function addText(string $font_size, int $degree, int $x, int $y, string $color, string $font, string $text): void
{
$rgbArr = $this->hexToRgb($color);
$color = imagecolorallocate($this->img, $rgbArr[0], $rgbArr[1], $rgbArr[2]);
imagettftext($this->img, $font_size, $degree, $x, $y, $color, $font, $text);
}
public function addImg(\GdImage $gdImage, int $location_x, int $location_y, int $offset_src_x, int $offset_src_y, int $src_width, int $src_height, int $no_transparent): void
{
imagecopymerge($this->img, $gdImage, $location_x, $location_y, $offset_src_x, $offset_src_y, $src_width, $src_height, $no_transparent);
}
public function getImg()
{
return $this->img;
}
public function save(string $path): void
{
imagepng($this->img, $path);
imagedestroy($this->img);
}
protected function hexToRgb(string $hex)
{
return sscanf($hex, "#%02x%02x%02x");
}
}

View File

@@ -24,7 +24,7 @@ class SMTP
/**
* @throws Exception
*/
public function send_html(array $params)
public function send_html(array $params): bool
{
if (!isset($params['address'])){
return false;
@@ -35,6 +35,6 @@ class SMTP
$body = $params['body'] ?? 'Нет информации';
$this->mail->msgHTML($body);
$this->mail->send();
return $this->mail->send();
}
}

View File

@@ -13,4 +13,9 @@ class Version
3 => intval($version),
};
}
public static function compare($current, $version): bool|int
{
return version_compare($current, $version);
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "Kernel",
"version": "0.1.1",
"version": "0.1.11",
"author": "ITGuild",
"slug": "kernel",
"type": "kernel",

View File

@@ -5,6 +5,7 @@ namespace kernel\modules\module_shop_client\controllers;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use JetBrains\PhpStorm\NoReturn;
use Josantonius\Session\Facades\Session;
use kernel\AdminController;
use kernel\Flash;
use kernel\helpers\Debug;
@@ -16,6 +17,7 @@ use kernel\services\AdminThemeService;
use kernel\services\KernelService;
use kernel\services\ModuleService;
use kernel\services\ModuleShopService;
use kernel\services\ThemeService;
use PHPMailer\PHPMailer\Exception;
class ModuleShopClientController extends AdminController
@@ -59,6 +61,7 @@ class ModuleShopClientController extends AdminController
'per_page' => $per_page,
'kernelService' => new KernelService(),
'adminThemeService' => new AdminThemeService(),
'themeService' => new ThemeService(),
]);
} else {
$this->cgView->render("module_shop_error_connection.php");
@@ -89,7 +92,7 @@ class ModuleShopClientController extends AdminController
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $module_info['path_to_archive'], RESOURCES_DIR . "/tmp/modules");
$this->moduleService->installModule('/resources/tmp/modules/' . basename($module_info['path_to_archive']));
Flash::setMessage("success", "Модуль успешно установлен.");
Flash::setMessage("success", "Модуль успешно загружен.");
$this->redirect('/admin/module_shop_client', 302);
}
@@ -162,18 +165,22 @@ class ModuleShopClientController extends AdminController
$filters = $request->get();
if ($this->moduleService->issetModuleShopToken()) {
if ($this->moduleService->isServerAvailable()) {
$modules_info = [];
// $modules_info = [];
$per_page = 8;
$modules = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
$modules = json_decode($modules->getBody()->getContents(), true);
foreach ($modules as $module) {
foreach ($filters as $key => $value) {
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
foreach ($modules_info as $key => $module) {
foreach ($filters as $column => $value) {
if ($value === '') continue;
if ($module[$key] !== $value) {
break;
if (is_numeric($value)) {
if ($module[$column] !== $value) {
unset($modules_info[$key]);
}
} elseif (is_string($value)) {
if (!str_contains($module[$column], $value)) {
unset($modules_info[$key]);
}
}
$modules_info[] = $module;
}
}
$module_count = count($modules_info);
@@ -209,7 +216,7 @@ class ModuleShopClientController extends AdminController
$moduleShopService = new ModuleShopService();
$result = $moduleShopService->email_auth($address);
if ($result['status'] == 'success'){
if ($result['status'] == 'success') {
$this->cgView->render('enter_code.php', ['email' => $address]);
}
@@ -224,7 +231,7 @@ class ModuleShopClientController extends AdminController
$moduleShopService = new ModuleShopService();
$result = $moduleShopService->code_check($code);
if (isset($result['access_token'])){
if (isset($result['access_token'])) {
$envFile = \EnvEditor\EnvFile::loadFrom(ROOT_DIR . "/.env");
@@ -238,4 +245,107 @@ class ModuleShopClientController extends AdminController
$this->cgView->render('module_shop_error_connection.php');
}
#[NoReturn] public function actionAdminThemeInstall(): void
{
$request = new Request();
$id = $request->get("id");
$adminThemeInfo = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/install/' . $id);
$adminThemeInfo = json_decode($adminThemeInfo->getBody()->getContents(), true);
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $adminThemeInfo['path_to_archive'], RESOURCES_DIR . "/tmp/admin_themes");
if ($this->adminThemeService->install('/resources/tmp/admin_themes/' . basename($adminThemeInfo['path_to_archive']))) {
Flash::setMessage("success", "Тема админ-панели успешно загружена.");
} else {
Flash::setMessage("error", implode(";", $this->adminThemeService->getErrors()));
}
$this->redirect('/admin/module_shop_client', 302);
}
#[NoReturn] public function actionAdminThemeUpdate(): void
{
$request = new Request();
$slug = $request->get("slug");
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
foreach ($modules_info as $module) {
if ($module['slug'] === $slug) {
$path = $module['path_to_archive'];
}
}
if (isset($path)) {
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $path, RESOURCES_DIR . "/tmp/admin_themes");
$this->adminThemeService->update('/resources/tmp/admin_themes/' . basename($path));
Flash::setMessage("success", "Тема админ-панели успешно обновлена.");
} else {
Flash::setMessage("error", "Ошибка обновления темы админ-панели.");
}
$this->redirect('/admin/module_shop_client', 302);
}
#[NoReturn] public function actionAdminThemeDelete(): void
{
$request = new Request();
$slug = $request->get("slug");
$adminThemeInfo = $this->adminThemeService->getAdminThemeInfoBySlug($slug);
$this->adminThemeService->uninstall($adminThemeInfo['path']);
Flash::setMessage("success", "Тема админ-панели успешно удалена.");
$this->redirect('/admin/module_shop_client', 302);
}
#[NoReturn] public function actionThemeInstall(): void
{
$request = new Request();
$id = $request->get("id");
$themeInfo = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/install/' . $id);
$themeInfo = json_decode($themeInfo->getBody()->getContents(), true);
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $themeInfo['path_to_archive'], RESOURCES_DIR . "/tmp/themes");
if ($this->themeService->install('/resources/tmp/themes/' . basename($themeInfo['path_to_archive']))) {
Flash::setMessage("success", "Тема сайта успешно загружена.");
} else {
Session::start();
Session::set("error", implode(";", $this->themeService->getErrors()));
}
$this->redirect('/admin/module_shop_client', 302);
}
#[NoReturn] public function actionThemeUpdate(): void
{
$request = new Request();
$slug = $request->get("slug");
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
foreach ($modules_info as $module) {
if ($module['slug'] === $slug) {
$path = $module['path_to_archive'];
}
}
if (isset($path)) {
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $path, RESOURCES_DIR . "/tmp/themes");
$this->themeService->update('/resources/tmp/themes/' . basename($path));
Flash::setMessage("success", "Тема сайта успешно обновлена.");
} else {
Flash::setMessage("error", "Ошибка обновления темы сайта.");
}
$this->redirect('/admin/module_shop_client', 302);
}
#[NoReturn] public function actionThemeDelete(): void
{
$request = new Request();
$slug = $request->get("slug");
$themeInfo = $this->themeService->getThemeInfoBySlug($slug);
$this->themeService->uninstall($themeInfo['path']);
Flash::setMessage("success", "Тема сайта успешно удалена.");
$this->redirect('/admin/module_shop_client', 302);
}
}

View File

@@ -24,7 +24,13 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
});
App::$collector->group(["prefix" => "admin_theme"], function (RouteCollector $router) {
App::$collector->get('/install', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeInstall']);
App::$collector->post('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeUpdate']);
App::$collector->get('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeUpdate']);
App::$collector->get('/delete', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeDelete']);
});
App::$collector->group(["prefix" => "theme"], function (RouteCollector $router) {
App::$collector->get('/install', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionThemeInstall']);
App::$collector->get('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionThemeUpdate']);
App::$collector->get('/delete', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionThemeDelete']);
});
});
});

View File

@@ -7,11 +7,13 @@
* @var \kernel\services\ModuleService $moduleService
* @var \kernel\services\KernelService $kernelService
* @var \kernel\services\AdminThemeService $adminThemeService
* @var \kernel\services\ThemeService $themeService
* @var array $filterValues
*/
use Itguild\Tables\ListJsonTable;
use kernel\widgets\ActionButtonWidget;
$meta = [];
$meta['columns'] = [
"name" => "Название",
@@ -42,10 +44,13 @@ $table->addAction(function ($row, $url) use ($moduleService) {
$table->columns([
'type' => [
'filter' => [
'class' => \kernel\filters\BootstrapSelectFilterWithPrompt::class,
'param' => [
'kernel' => 'kernel',
'entity' => 'entity',
'class' => \kernel\filters\BootstrapSelectFilter::class,
'params' => [
'options' => [
'kernel' => 'kernel',
'entity' => 'entity',
],
'prompt' => 'Не выбрано'
],
'value' => $filterValues['type'] ?? ''
],
@@ -100,7 +105,7 @@ $table->addAction(function ($row, $url) use ($adminThemeService) {
$slug = $row['slug'];
if ($adminThemeService->isInstall($slug)) {
if (!$adminThemeService->isLastVersion($slug)) {
$url = "$url/admin_theme/update/";
$url = "$url/admin_theme/update/?slug=" . $row['slug'];
return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run();
}
@@ -110,6 +115,53 @@ $table->addAction(function ($row, $url) use ($adminThemeService) {
return false;
});
$table->addAction(function ($row, $url) use ($adminThemeService) {
if ($row['type'] === 'admin_theme') {
if ($adminThemeService->isInstall($row['slug'])) {
$url = "$url/admin_theme/delete/?slug=" . $row['slug'];
return \kernel\widgets\IconBtn\IconBtnDeleteWidget::create(['url' => $url])->run();
} else {
$url = "$url/admin_theme/install/?id=" . $row['id'];
return \kernel\widgets\IconBtn\IconBtnInstallWidget::create(['url' => $url])->run();
}
}
return false;
});
$table->addAction(function ($row, $url) use ($themeService) {
if ($row['type'] === 'theme') {
$slug = $row['slug'];
if ($themeService->isInstall($slug)) {
if (!$themeService->isLastVersion($slug)) {
$url = "$url/theme/update/?slug=" . $row['slug'];
return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run();
}
}
}
return false;
});
$table->addAction(function ($row, $url) use ($themeService) {
if ($row['type'] === 'theme') {
if ($themeService->isInstall($row['slug'])) {
$url = "$url/theme/delete/?slug=" . $row['slug'];
return \kernel\widgets\IconBtn\IconBtnDeleteWidget::create(['url' => $url])->run();
} else {
$url = "$url/theme/install/?id=" . $row['id'];
return \kernel\widgets\IconBtn\IconBtnInstallWidget::create(['url' => $url])->run();
}
}
return false;
});
$table->afterPrint(function () {
return \kernel\IGTabel\btn\PrimaryBtn::create('Сбросить все фильтры', '/admin/module_shop_client')->fetch();
});

View File

@@ -15,7 +15,8 @@ $table_info = [
"version" => "Версия",
"description" => "Описание",
"installations" => "Установки",
"views" => "Просмотры"
"views" => "Просмотры",
"dependence" => "Зависимости"
],
"params" => ["class" => "table table-bordered"],
"baseUrl" => "/admin/module_shop_client",

View File

@@ -0,0 +1,31 @@
<?php
namespace kernel\modules\notification;
use kernel\Flash;
use kernel\modules\notification\contracts\NotificationChannelInterface;
use kernel\modules\notification\contracts\NotificationMessage;
use kernel\modules\user\models\User;
class NotificationDispatcher
{
protected array $channels = [];
public function addChannel(string $channelName, NotificationChannelInterface $channel): void
{
$this->channels[$channelName] = $channel;
}
public function dispatch(NotificationMessage $notification, User $user): void
{
foreach ($notification->via() as $channelName) {
if (isset($this->channels[$channelName])) {
try {
$this->channels[$channelName]->send($notification, $user);
} catch (\Exception $e) {
Flash::setMessage("error", $e->getMessage());
}
}
}
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace kernel\modules\notification;
use kernel\Module;
use kernel\modules\menu\service\MenuService;
use kernel\services\MigrationService;
class NotificationModule 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/modules/notification/migrations");
$this->menuService->createItem([
"label" => "Уведомления",
"url" => "/admin/notification",
"slug" => "notification"
]);
}
/**
* @throws \Exception
*/
public function deactivate(): void
{
$this->migrationService->rollbackAtPath("kernel/modules/notification/migrations");
$this->menuService->removeItemBySlug("notification");
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace kernel\modules\notification\channels;
use kernel\Flash;
use kernel\modules\notification\contracts\NotificationChannelInterface;
use kernel\modules\notification\contracts\NotificationMessage;
use kernel\modules\notification\models\User;
class DatabaseChannel implements NotificationChannelInterface
{
public function send(NotificationMessage $notification, User $user): bool
{
try {
$user->notifications()->create([
'message' => $notification->getMessage(),
'data' => $notification->toArray()
]);
return true;
} catch (\Exception $e) {
Flash::setMessage("error", $e->getMessage());
return false;
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace kernel\modules\notification\channels;
use kernel\helpers\SMTP;
use kernel\modules\notification\contracts\NotificationChannelInterface;
use kernel\modules\notification\contracts\NotificationMessage;
use kernel\modules\user\models\User;
use PHPMailer\PHPMailer\Exception;
class EmailChannel implements NotificationChannelInterface
{
/**
* @throws Exception
*/
public function send(NotificationMessage $notification, User $user): bool
{
$smtp = new SMTP();
// Здесь можно использовать Laravel Mail
// \Illuminate\Support\Facades\Mail::to($user->email)
// ->send(new \App\Mail\NotificationMail(
// $notification->getSubject(),
// $notification->getMessage()
// ));
return $smtp->send_html([
'address' => $user->email,
'subject' => $notification->getSubject(),
'body' => $notification->getMessage(),
'from_name' => $_ENV['MAIL_SMTP_USERNAME'],
]);
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace kernel\modules\notification\channels;
use kernel\modules\notification\contracts\NotificationChannelInterface;
use kernel\modules\notification\contracts\NotificationMessage;
use kernel\modules\user\models\User;
class SmsChannel implements NotificationChannelInterface
{
public function send(NotificationMessage $notification, User $user): bool
{
if (empty($user->phone)) {
return false;
}
// Интеграция с SMS-сервисом
//$smsService = new \App\Services\SmsService();
//return $smsService->send($user->phone, $notification->getMessage());
return true;
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace kernel\modules\notification\channels;
use kernel\Flash;
use kernel\modules\notification\contracts\NotificationChannelInterface;
use kernel\modules\notification\contracts\NotificationMessage;
use kernel\modules\notification\models\User;
class TelegramChannel implements NotificationChannelInterface
{
protected string $botToken;
public function __construct(string $botToken)
{
$this->botToken = $botToken;
}
public function send(NotificationMessage $notification, User $user): bool
{
if (empty($user->telegram_chat_id)) {
return false;
}
$httpClient = new \GuzzleHttp\Client();
try {
$response = $httpClient->post("https://api.telegram.org/bot{$this->botToken}/sendMessage", [
'form_params' => [
'chat_id' => $user->telegram_chat_id,
'text' => $notification->getMessage(),
'parse_mode' => 'HTML'
]
]);
return $response->getStatusCode() === 200;
} catch (\Exception $e) {
Flash::setMessage("error", $e->getMessage());
return false;
}
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace kernel\modules\notification\contracts;
use kernel\modules\notification\models\User;
interface NotificationChannelInterface
{
public function send(NotificationMessage $notification, User $user): bool;
}

View File

@@ -0,0 +1,31 @@
<?php
namespace kernel\modules\notification\contracts;
abstract class NotificationMessage
{
protected array $channels = [];
abstract public function getMessage(): string;
abstract public function getSubject(): string;
public function via(): array
{
return $this->channels;
}
public function addChannel(string $channel): void
{
if (!in_array($channel, $this->channels)) {
$this->channels[] = $channel;
}
}
public function toArray(): array
{
return [
'message' => $this->getMessage(),
'subject' => $this->getSubject(),
];
}
}

View File

@@ -0,0 +1,106 @@
<?php
namespace kernel\modules\notification\controllers;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\Flash;
use kernel\helpers\Debug;
use kernel\modules\notification\models\forms\CreateNotificationForm;
use kernel\modules\notification\models\Notification;
use kernel\modules\notification\service\NotificationService;
use kernel\modules\option\models\forms\CreateOptionForm;
class NotificationController extends AdminController
{
private NotificationService $optionService;
public function init(): void
{
parent::init();
$this->cgView->viewPath = KERNEL_MODULES_DIR . '/notification/views/';
$this->optionService = new NotificationService();
}
public function actionCreate(): void
{
$this->cgView->render('form.php');
}
#[NoReturn] public function actionAdd(): void
{
$optionForm = new CreateNotificationForm();
$optionForm->load($_REQUEST);
if ($optionForm->validate()) {
$option = $this->optionService->create($optionForm);
if ($option) {
Flash::setMessage("success", "notification успешно создана.");
$this->redirect('/admin/notification');
}
}
Flash::setMessage("error", $optionForm->getErrorsStr());
$this->redirect('/admin/notification/create');
}
public function actionIndex($page_number = 1): void
{
$this->cgView->render('index.php', ['page_number' => $page_number]);
}
/**
* @throws \Exception
*/
public function actionView(int $id): void
{
$option = Notification::find($id);
if (!$option) {
throw new \Exception('notification not found');
}
$this->cgView->render("view.php", ['option' => $option]);
}
/**
* @throws \Exception
*/
public function actionUpdate(int $id): void
{
$model = Notification::find($id);
if (!$model) {
throw new \Exception('notification not found');
}
$this->cgView->render("form.php", ['model' => $model]);
}
/**
* @throws \Exception
*/
public function actionEdit(int $id): void
{
$option = Notification::find($id);
if (!$option) {
throw new \Exception('Option not found');
}
$optionForm = new CreateOptionForm();
$optionForm->load($_REQUEST);
if ($optionForm->validate()) {
$option = $this->optionService->update($optionForm, $option);
if ($option) {
$this->redirect('/admin/notification/view/' . $option->id);
}
}
$this->redirect('/admin/notification/update/' . $id);
}
#[NoReturn] public function actionDelete(int $id): void
{
Notification::find($id)->delete();
Flash::setMessage("success", "notification успешно удалена.");
$this->redirect('/admin/notification');
}
}

View File

@@ -0,0 +1,13 @@
{
"name": "Notifications",
"version": "0.1",
"author": "ITGuild",
"slug": "notification",
"type": "entity",
"description": "Notifications module",
"module_class": "kernel\\modules\\notification\\NotificationModule",
"module_class_file": "{KERNEL_MODULES}/notification/NotificationModule.php",
"routs": "routs/notification.php",
"migration_path": "migrations",
"dependence": "user,menu"
}

View File

@@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
\kernel\App::$db->schema->create('notification', function (Blueprint $table) {
$table->id();
// Связь с пользователем
$table->unsignedBigInteger('user_id');
// Основные данные уведомления
$table->string('type')->index(); // Класс уведомления (например, App\Notifications\OrderCreated)
$table->text('message'); // Текст уведомления
$table->string('subject')->nullable(); // Тема (для email)
$table->json('data')->nullable(); // Дополнительные данные в JSON
// Статус уведомления
$table->boolean('is_read')->default(false);
$table->integer('status')->default(1);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
\kernel\App::$db->schema->dropIfExists('notification');
}
};

View File

@@ -0,0 +1,71 @@
<?php
namespace kernel\modules\notification\models;
use Illuminate\Database\Eloquent\Model;
use kernel\modules\user\models\User;
/**
* @property int $id
* @property int $user_id
* @property bool $is_read
* @property array|string $data
* @property string $type
* @property string $message
* @property string $subject
* @property int $status
*/
class Notification extends Model
{
const DISABLE_STATUS = 0;
const TO_SEND_STATUS = 1;
const SENT_STATUS = 2;
protected $table = 'notification';
protected $fillable = ['user_id', 'message', 'is_read', 'data', 'type', 'subject', 'status'];
protected $casts = [
'is_read' => 'boolean',
'data' => 'array'
];
public static function labels(): array
{
return [
'user_id' => 'Пользователь',
'message' => 'Сообщение',
'subject' => 'Тема',
'is_read' => 'Прочитано',
'data' => 'Данные',
'type' => 'Тип',
'status' => 'Статус'
];
}
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(User::class);
}
public function markAsRead(): static
{
$this->update(['is_read' => true]);
return $this;
}
/**
* @return string[]
*/
public static function getStatus(): array
{
return [
self::DISABLE_STATUS => "Не активный",
self::TO_SEND_STATUS => "На отправку",
self::SENT_STATUS => "Отправлено",
];
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace kernel\modules\notification\models;
class User extends \kernel\modules\user\models\User
{
public function notifications(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Notification::class);
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace kernel\modules\notification\models\forms;
use kernel\FormModel;
/**
* @property string $key
* @property string $value
* @property string $label
* @property integer $status
*/
class CreateNotificationForm extends FormModel
{
public function rules(): array
{
return [
'user_id' => 'required|integer',
'message' => 'required',
'is_read' => '',
'data' => '',
'type' => 'required',
'subject' => '',
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
use kernel\App;
use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router) {
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
App::$collector->group(["prefix" => "notification"], callback: function (RouteCollector $router) {
App::$collector->get('/', [\kernel\modules\notification\controllers\NotificationController::class, 'actionIndex']);
App::$collector->get('/page/{page_number}', [\kernel\modules\notification\controllers\NotificationController::class, 'actionIndex']);
App::$collector->get('/create', [\kernel\modules\notification\controllers\NotificationController::class, 'actionCreate']);
App::$collector->post("/", [\kernel\modules\notification\controllers\NotificationController::class, 'actionAdd']);
App::$collector->get('/view/{id}', [\kernel\modules\notification\controllers\NotificationController::class, 'actionView']);
App::$collector->any('/update/{id}', [\kernel\modules\notification\controllers\NotificationController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\kernel\modules\notification\controllers\NotificationController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\kernel\modules\notification\controllers\NotificationController::class, 'actionDelete']);
});
});
});

View File

@@ -0,0 +1,57 @@
<?php
namespace kernel\modules\notification\service;
use kernel\FormModel;
use kernel\modules\notification\models\Notification;
class NotificationService
{
public function create(FormModel $form_model): false|Notification
{
$model = new Notification();
$model->user_id = $form_model->getItem('user_id');
$model->message = $form_model->getItem('message');
$model->is_read = $form_model->getItem('is_read');
$model->data = $form_model->getItem('data');
$model->type = $form_model->getItem('type');
$model->subject = $form_model->getItem('subject');
$model->status = $form_model->getItem('status');
if ($model->save()) {
return $model;
}
return false;
}
public function update(FormModel $form_model, Notification $notification): false|Notification
{
$notification->user_id = $form_model->getItem('user_id');
$notification->message = $form_model->getItem('message');
$notification->is_read = $form_model->getItem('is_read');
$notification->data = $form_model->getItem('data');
$notification->type = $form_model->getItem('type');
$notification->subject = $form_model->getItem('subject');
$notification->status = $form_model->getItem('status');
if ($notification->save()) {
return $notification;
}
return false;
}
// public function createOptionArr(): array
// {
// foreach (Option::all()->toArray() as $option) {
// $optionArr[$option['id']] = $option['key'];
// }
// if (!empty($optionArr)) {
// return $optionArr;
// }
// return [];
// }
}

View File

@@ -0,0 +1,16 @@
<?php
namespace kernel\modules\option\table\columns;
use Itguild\Tables\ActionColumn\ActionColumn;
class OptionDeleteActionColumn 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

@@ -0,0 +1,16 @@
<?php
namespace kernel\modules\option\table\columns;
use Itguild\Tables\ActionColumn\ActionColumn;
class OptionEditActionColumn extends ActionColumn
{
protected string $prefix = "/update/";
public function fetch(): string
{
$link = $this->baseUrl . $this->prefix . $this->id;
return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace kernel\modules\option\table\columns;
use Itguild\Tables\ActionColumn\ActionColumn;
class OptionViewActionColumn extends ActionColumn
{
protected string $prefix = "/";
public function fetch()
{
$link = $this->baseUrl . $this->prefix . $this->id;
return " <a href='$link' class='btn btn-primary'>Просмотр</a> ";
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* @var Notification $model
*/
use itguild\forms\ActiveForm;
use kernel\modules\notification\models\Notification;
$form = new ActiveForm();
$form->beginForm(isset($model) ? "/admin/notification/edit/" . $model->id : "/admin/notification");
$form->field(class: \itguild\forms\inputs\Select::class, name: "user_id", params: [
'class' => "form-control",
'value' => $model->user_id ?? ''
])
->setLabel(Notification::labels()['user_id'])
->setOptions(\kernel\modules\user\service\UserService::createUsernameArr())
->render();
$form->field(\itguild\forms\inputs\TextInput::class, 'subject', [
'class' => "form-control",
'placeholder' => Notification::labels()['subject'],
'value' => $model->subject ?? ''
])
->setLabel(Notification::labels()['subject'])
->render();
$form->field(\itguild\forms\inputs\TextInput::class, 'type', [
'class' => "form-control",
'placeholder' => Notification::labels()['type'],
'value' => $model->type ?? ''
])
->setLabel(Notification::labels()['type'])
->render();
$form->field(\itguild\forms\inputs\TextArea::class, 'message', [
'class' => "form-control",
'placeholder' => Notification::labels()['message'],
'value' => $model->message ?? ''
])
->setLabel(Notification::labels()['message'])
->render();
$form->field(\itguild\forms\inputs\Checkbox::class, 'is_read', [
'class' => "form-check-input",
'placeholder' => Notification::labels()['is_read'],
'value' => $model->is_read ?? ''
])
->setLabel(Notification::labels()['is_read'])
->render();
$form->field(\itguild\forms\inputs\Select::class, 'status', [
'class' => "form-control",
'value' => $model->status ?? ''
])
->setLabel("Статус")
->setOptions(Notification::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,44 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $options
* @var int $page_number
*/
use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable;
use kernel\modules\notification\models\Notification;
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(Notification::class, [
'current_page' => $page_number,
'per_page' => 5,
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/notification",
]));
$table->beforePrint(function () {
return IconBtnCreateWidget::create(['url' => '/admin/notification/create'])->run();
});
$table->columns([
"status" => [
"value" => function ($cell) {
return Notification::getStatus()[$cell];
}]
]);
$table->addAction(function($row) {
return IconBtnViewWidget::create(['url' => '/admin/notification/view/' . $row['id']])->run();
});
$table->addAction(function($row) {
return IconBtnEditWidget::create(['url' => '/admin/Notification/update/' . $row['id']])->run();
});
$table->addAction(function($row) {
return IconBtnDeleteWidget::create(['url' => '/admin/Notification/delete/' . $row['id']])->run();
});
$table->create();
$table->render();

View File

@@ -0,0 +1,32 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $option
*/
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($option, [
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/user",
]));
$table->beforePrint(function () use ($option) {
$btn = IconBtnListWidget::create(['url' => '/admin/option'])->run();
$btn .= IconBtnEditWidget::create(['url' => '/admin/option/update/' . $option->id])->run();
$btn .= IconBtnDeleteWidget::create(['url' => '/admin/option/delete/' . $option->id])->run();
return $btn;
});
$table->rows([
'status' => (function ($data) {
return \kernel\modules\option\models\Notification::getStatus()[$data];
})
]);
$table->create();
$table->render();

View File

@@ -3,6 +3,7 @@
namespace kernel\modules\option\service;
use kernel\FormModel;
use kernel\helpers\Debug;
use kernel\modules\option\models\Option;
class OptionService
@@ -49,6 +50,26 @@ class OptionService
return false;
}
public static function createOrUpdate(string $key, string $value, string $label = ''): false|Option
{
/** @var Option $option */
$option = self::getItemObject($key);
if (!$option) {
$option = new Option();
$option->key = $key;
}
$option->value = $value;
if (!empty($label)){
$option->label = $label;
}
if ($option->save()) {
return $option;
}
return false;
}
/**
* @param $key
* @return false|array|string
@@ -63,6 +84,20 @@ class OptionService
return false;
}
/**
* @param $key
* @return false|array|string|Option
*/
public static function getItemObject($key): false|array|string|Option
{
$item = Option::where("key", $key)->first();
if ($item){
return $item;
}
return false;
}
public static function removeOptionByKey(string $key): bool
{
$option = Option::where("key", $key)->first();

View File

@@ -33,4 +33,9 @@ class PostService
return false;
}
public static function getListArr()
{
return Post::pluck('title', 'id')->toArray();
}
}

View File

@@ -26,8 +26,6 @@ $table = new ListEloquentTable(new EloquentDataProvider(Post::class, [
'searchParams' => $get,
]));
//\kernel\helpers\Debug::dd((new \kernel\Request())->get());
$view->setTitle("Список постов");
$view->setMeta([
'description' => 'Список постов системы'
@@ -72,12 +70,13 @@ $table->columns([
return User::find($data)->username;
},
'filter' => [
'class' => \kernel\filters\BootstrapSelectFilterWithPrompt::class,
'param' => \kernel\modules\user\service\UserService::createUsernameArr(),
'class' => \kernel\filters\BootstrapSelectFilter::class,
'params' => [
'options' => \kernel\modules\user\service\UserService::createUsernameArr(),
'prompt' => 'Не выбрано'
],
'value' => $get['user_id'] ?? '',
'prompt' => 'dsds'
],
'prompt' => 'dsds'
]
]);

View File

@@ -8,6 +8,7 @@ use kernel\App;
use kernel\Flash;
use kernel\helpers\Debug;
use kernel\Mailing;
use kernel\modules\secure\models\forms\ChangePasswordForm;
use kernel\modules\secure\models\forms\LoginEmailForm;
use kernel\modules\secure\models\forms\LoginForm;
use kernel\modules\secure\models\forms\RegisterForm;
@@ -40,7 +41,7 @@ class SecureController extends AdminController
// $this->cgView->render('login.php');
}
#[NoReturn] public function actionAuth(): void
#[NoReturn] public function actionAuth($basePath = '/admin'): void
{
$loginForm = new LoginForm();
$loginForm->load($_REQUEST);
@@ -51,19 +52,36 @@ class SecureController extends AdminController
else {
$field = "username";
}
$user = $this->userService->getByField($field, $loginForm->getItem("username"));
if (!$user){
Flash::setMessage("error", "User not found.");
$this->redirect("/admin/login", code: 302);
$this->redirect($basePath . "/login", code: 302);
}
if (password_verify($loginForm->getItem("password"), $user->password_hash)) {
setcookie('user_id', $user->id, time()+60*60*24, '/', $_SERVER['SERVER_NAME'], false);
$this->redirect("/admin", code: 302);
$this->redirect($basePath . '/', code: 302);
} else {
Flash::setMessage("error", "Username or password incorrect.");
$this->redirect("/admin/login", code: 302);
$this->redirect($basePath . "/login", code: 302);
}
}
#[NoReturn] public function actionChangePassword($basePath = '/admin'): void
{
$changePasswordForm = new ChangePasswordForm();
$changePasswordForm->load($_REQUEST);
$user = UserService::getAuthUser();
if (password_verify($changePasswordForm->getItem("old_password"), $user->password_hash)) {
$user->password_hash = password_hash($changePasswordForm->getItem("new_password"), PASSWORD_DEFAULT);
$user->save();
Flash::setMessage("success", "Пароль успешно изменен.");
$this->redirect($basePath . '', code: 302);
} else {
Flash::setMessage("error", "Username or password incorrect.");
$this->redirect($basePath . "", code: 302);
}
}
@@ -148,25 +166,25 @@ class SecureController extends AdminController
$this->cgView->render('register.php');
}
public function actionRegistration(): void
public function actionRegistration($basePath = '/admin'): void
{
$regForm = new RegisterForm();
$regForm->load($_REQUEST);
if ($this->userService->getByField('username', $regForm->getItem("username"))) {
Flash::setMessage("error", "Username already exists.");
$this->redirect("/admin/register", code: 302);
$this->redirect($basePath . "/register", code: 302);
}
if ($this->userService->getByField('email', $regForm->getItem("email"))) {
Flash::setMessage("error", "Email already exists.");
$this->redirect("/admin/register", code: 302);
$this->redirect($basePath . "/register", code: 302);
}
$user = $this->userService->create($regForm);
if ($user){
setcookie('user_id', $user->id, time()+60*60*24, '/', $_SERVER['SERVER_NAME'], false);
$this->redirect("/admin", code: 302);
$this->redirect($basePath . "/", code: 302);
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace kernel\modules\secure\models\forms;
use kernel\FormModel;
class ChangePasswordForm extends FormModel
{
public function rules(): array
{
return [
'old_password' => 'required|min-str-len:6|max-str-len:50',
'new_password' => 'required|min-str-len:6|max-str-len:50',
];
}
}

View File

@@ -13,21 +13,28 @@ use kernel\services\TokenService;
class SecureService
{
public static function createSecretCode(User $user): void
public static function createSecretCode(User $user): SecretCode
{
$secretCode = new SecretCode();
$secretCode->user_id = $user->id;
$secretCode->code = mt_rand(100000, 999999);
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
$secretCode->save();
return $secretCode;
}
public static function updateSecretCode(User $user): void
public static function updateSecretCode(User $user): SecretCode
{
$secretCode = SecretCode::where('user_id', $user->id)->first();
if(!$secretCode){
return self::createSecretCode($user);
}
$secretCode->code = mt_rand(100000, 999999);
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
$secretCode->save();
return $secretCode;
}
public static function getCodeByUserId(int $user_id)

View File

@@ -0,0 +1,33 @@
<?php
namespace kernel\modules\themes;
use kernel\Module;
use kernel\modules\menu\service\MenuService;
class ThemesModule extends Module
{
public MenuService $menuService;
public function __construct()
{
$this->menuService = new MenuService();
}
/**
* @throws \Exception
*/
public function init(): void
{
$this->menuService->createItem([
"label" => "Темы сайта",
"url" => "/admin/settings/themes",
"slug" => "themes",
"parent_slug" => "settings"
]);
}
public function deactivate(): void
{
$this->menuService->removeItemBySlug("themes");
}
}

View File

@@ -0,0 +1,95 @@
<?php
namespace kernel\modules\themes\controllers;
use DirectoryIterator;
use GuzzleHttp\Exception\GuzzleException;
use JetBrains\PhpStorm\NoReturn;
use Josantonius\Session\Exceptions\HeadersSentException;
use Josantonius\Session\Exceptions\SessionNotStartedException;
use Josantonius\Session\Exceptions\SessionStartedException;
use Josantonius\Session\Exceptions\WrongSessionOptionException;
use Josantonius\Session\Facades\Session;
use kernel\AdminController;
use kernel\helpers\Debug;
use kernel\models\Option;
use kernel\Request;
use kernel\services\ModuleService;
use kernel\services\ThemeService;
class ThemeController extends AdminController
{
public ThemeService $themeService;
public ModuleService $moduleService;
protected function init(): void
{
parent::init();
$this->cgView->viewPath = KERNEL_MODULES_DIR . "/themes/views/";
$this->themeService = new ThemeService();
$this->moduleService = new ModuleService();
}
public function actionIndex(): void
{
$themePaths = Option::where("key", "theme_paths")->first();
$dirs = [];
if ($themePaths){
$path = json_decode($themePaths->value);
foreach ($path->paths as $p){
$dirs[] = getConst($p);
}
}
$infoToTable = [];
$meta = [];
$meta['columns'] = [
"preview" => "Превью",
"name" => "Название",
"author" => "Автор",
"version" => "Версия",
"description" => "Описание"
];
$meta['params'] = ["class" => "table table-bordered"];
$meta['perPage'] = 10;
$meta['baseUrl'] = "/admin/settings/themes";
$meta['currentPage'] = 1;
$infoToTable['meta'] = $meta;
$themesInfo = [];
foreach ($dirs as $dir){
$i = 1;
foreach (new DirectoryIterator($dir) as $fileInfo) {
$info = [];
if($fileInfo->isDot()) continue;
$info['id'] = $i;
$themesInfo[] = array_merge($info, $this->themeService->getThemeInfo($fileInfo->getPathname()));
$i++;
}
}
$infoToTable['meta']['total'] = count($themesInfo);
$infoToTable['data'] = $themesInfo;
$this->cgView->render("index.php", ['json' => json_encode($infoToTable, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)]);
}
/**
* @throws HeadersSentException
* @throws WrongSessionOptionException
* @throws SessionStartedException
* @throws GuzzleException
* @throws SessionNotStartedException
*/
#[NoReturn] public function actionActivate(): void
{
$request = new Request();
if(!$this->themeService->setActiveTheme($request->get("p"))){
$this->redirect("/admin/settings/themes/", 302);
}
$this->cgView->render("view.php", ['data' => $this->themeService->getThemeInfo($request->get("p"))]);
}
}

View File

@@ -0,0 +1,10 @@
{
"name": "Themes",
"version": "0.1",
"author": "ITGuild",
"slug": "themes",
"description": "Themes module",
"module_class": "kernel\\modules\\themes\\ThemesModule",
"module_class_file": "{KERNEL_MODULES}/themes/ThemesModule.php",
"routs": "routs/themes.php"
}

View File

@@ -0,0 +1,16 @@
<?php
use kernel\App;
use kernel\modules\admin_themes\controllers\AdminThemeController;
use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
App::$collector->group(["prefix" => "settings"], function (RouteCollector $router) {
App::$collector->group(["prefix" => "themes"], function (RouteCollector $router) {
App::$collector->get('/', [\kernel\modules\themes\controllers\ThemeController::class, 'actionIndex']);
App::$collector->get('/activate', [\kernel\modules\themes\controllers\ThemeController::class, 'actionActivate']);
});
});
});
});

View File

@@ -0,0 +1,25 @@
<?php
/**
* @var $json string
*/
$table = new \Itguild\Tables\ListJsonTable($json);
$table->columns([
'preview' => function ($data) {
return "<img src='$data' width='200px'>";
}
]);
$table->addAction(function ($row, $url){
$active_admin_theme = \kernel\modules\option\service\OptionService::getItem('active_theme');
if ($row['path'] === $active_admin_theme){
return "Активна";
} else {
$url = "$url/activate/?p=" . $row['path'];
return \kernel\widgets\IconBtn\IconBtnActivateWidget::create(['url' => $url])->run();
}
});
$table->create();
$table->render();

View File

@@ -0,0 +1,25 @@
<?php
/**
* @var array $data
*/
$table_info = [
"meta" => [
"rows" => ["preview" => "Превью", "name" => "Название", "version" => "Версия", "description" => "Описание"],
"params" => ["class" => "table table-bordered"],
"baseUrl" => "/admin/settings/themes",
],
"data" => $data
];
$table = new \Itguild\Tables\ViewJsonTable(json_encode($table_info, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
$table->rows([
'preview' => function ($data) {
return "<img src='$data' width='500px'>";
}
]);
$table->beforePrint(function () {
return \kernel\widgets\IconBtn\IconBtnListWidget::create(['url' => '/admin/settings/themes'])->run();
});
$table->create();
$table->render();

View File

@@ -7,6 +7,7 @@ use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\EntityRelation;
use kernel\FileUpload;
use kernel\Flash;
use kernel\helpers\Debug;
use kernel\modules\user\models\forms\CreateUserForm;
use kernel\modules\user\models\User;
@@ -55,6 +56,7 @@ class UserController extends AdminController
$this->redirect("/admin/user/view/" . $user->id);
}
}
Flash::setMessage("error", $userForm->getErrorsStr());
$this->redirect("/admin/user/create");
}
@@ -144,4 +146,53 @@ class UserController extends AdminController
$this->redirect("/admin/user/");
}
public function actionProfile(): void
{
$user = UserService::getAuthUser();
if (!$user){
throw new Exception(message: "The user not found");
}
$this->cgView->render("view_profile.php", ['user' => $user]);
}
public function actionProfileUpdate(): void
{
$model = UserService::getAuthUser();
if (!$model){
throw new Exception(message: "The user not found");
}
$this->cgView->render("form_profile.php", ['model' => $model]);
}
public function actionProfileEdit(): void
{
$user = UserService::getAuthUser();
if (!$user){
throw new Exception(message: "The user not found");
}
$userForm = new CreateUserForm();
$userService = new UserService();
$userForm->load($_REQUEST);
if (isset($_FILES['user_photo']) && $_FILES['user_photo']['error'] === UPLOAD_ERR_OK) {
$file = new FileUpload($_FILES['user_photo'], ['jpg', 'jpeg', 'png']);
$file->upload();
$userForm->setItem('user_photo', $file->getUploadFile());
}
if ($userForm->validateForUpdate()){
$user = $userService->update($userForm, $user);
$entityRelation = new EntityRelation();
$entityRelation->saveEntityRelation(entity: "user", model: $user, request: new Request());
if ($user){
$this->redirect("/admin/user/profile");
}
}
$this->redirect("/admin/user/profile/update");
}
}

View File

@@ -17,6 +17,11 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->any('/update/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\kernel\modules\user\controllers\UserController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionDelete']);
App::$collector->group(["prefix" => "profile"], callback: function (RouteCollector $router) {
App::$collector->get('/', [\kernel\modules\user\controllers\UserController::class, 'actionProfile']);
App::$collector->get('/update', [\kernel\modules\user\controllers\UserController::class, 'actionProfileUpdate']);
App::$collector->any('/edit', [\kernel\modules\user\controllers\UserController::class, 'actionProfileEdit']);
});
});
});
});

View File

@@ -2,6 +2,7 @@
namespace kernel\modules\user\service;
use itguild\forms\ActiveForm;
use kernel\FormModel;
use kernel\helpers\Debug;
use kernel\modules\user\models\User;
@@ -11,7 +12,11 @@ class UserService
public function create(FormModel $form_model): false|User
{
$model = new User();
$model = User::where("username", $form_model->getItem('username'))->first();
if ($model){
return $model;
}
$model = new User();
$model->username = $form_model->getItem('username');
$model->email = $form_model->getItem('email');
$model->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT);
@@ -118,4 +123,12 @@ class UserService
$user->save();
}
public static function getList(): array
{
return User::select('id', 'username')->get()
->pluck('username', 'id')
->toArray();
}
}

View File

@@ -47,6 +47,8 @@ if (!isset($model)) {
$model = new User();
}
$entityRelations->renderEntityAdditionalPropertyFormBySlug("user", $model);
?>
<div class="row">
<div class="col-sm-2">

View File

@@ -0,0 +1,74 @@
<?php
/**
* @var User $model
*/
use kernel\modules\user\models\User;
$form = new \itguild\forms\ActiveForm();
$form->beginForm("/admin/user/profile/edit", enctype: 'multipart/form-data');
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "username", params: [
'class' => "form-control",
'placeholder' => 'Логин',
'value' => $model->username ?? ''
])
->setLabel("Логин")
->render();
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "password", params: [
'class' => "form-control",
'type' => "password",
])
->setLabel("Пароль")
->render();
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "email", params: [
'class' => "form-control",
'type' => "email",
'placeholder' => 'test@mail.ru',
'value' => $model->email ?? ''
])
->setLabel("Email")
->render();
if (!empty($model->user_photo)){
echo "<div><img src='$model->user_photo' width='200px'></div>";
}
$form->field(class: \itguild\forms\inputs\File::class, name: "user_photo", params: [
'class' => "form-control",
'value' => $model->user_photo ?? ''
])
->setLabel("Фото профиля")
->render();
$entityRelations = new \kernel\EntityRelation();
if (!isset($model)) {
$model = new User();
}
$entityRelations->renderEntityAdditionalPropertyFormBySlug("user", $model);
?>
<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

@@ -1,7 +1,7 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $user
* @var User $user
*/
use kernel\modules\user\models\User;
@@ -55,3 +55,5 @@ $table->rows([
]);
$table->create();
$table->render();
\kernel\App::$hook->runHooksByEntity('user_view', ['user' => $user]);

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