Compare commits

..

No commits in common. "6c124e9bb7f53320aaa3b68936183cb17dec9e63" and "e7a20d9b97716c33cfd8a9234f48e78b4ce139ac" have entirely different histories.

39 changed files with 93 additions and 1025 deletions

View File

@ -1,115 +0,0 @@
<?php
namespace app\modules\photo;
use Cassandra\Decimal;
use Illuminate\Database\Eloquent\Model;
use itguild\forms\builders\FileBuilder;
use kernel\app_modules\photo\models\Photo;
use kernel\app_modules\photo\services\PhotoService;
use kernel\app_modules\tag\services\TagEntityService;
use kernel\FileUpload;
use kernel\helpers\Debug;
use kernel\helpers\Html;
use kernel\Module;
use kernel\modules\menu\service\MenuService;
use kernel\Request;
use kernel\services\MigrationService;
class PhotoModule extends Module
{
public MenuService $menuService;
public MigrationService $migrationService;
public function __construct()
{
$this->menuService = new MenuService();
$this->migrationService = new MigrationService();
}
/**
* @throws \Exception
*/
public function init(): void
{
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/photo/migrations");
$this->menuService->createItem([
"label" => "Фото",
"url" => "/admin/photo",
"slug" => "photo",
]);
$this->menuService->createItem([
"label" => "Фото",
"url" => "/admin/settings/photo",
"slug" => "photo_settings",
"parent_slug" => "settings"
]);
}
public function deactivate(): void
{
$this->menuService->removeItemBySlug("photo");
$this->menuService->removeItemBySlug("photo_settings");
}
public function formInputs(string $entity, Model $model = null): void
{
if (isset($model->id)) {
$value = PhotoService::getByEntity($entity, $model->id);
echo Html::img($value, ['width' => '200px']);
}
$input = FileBuilder::build("image", [
'class' => 'form-control',
'value' => $value ?? '',
]);
$input->setLabel("Фото");
$input->create()->render();
}
public function saveInputs(string $entity, Model $model, Request $request): void
{
Photo::where("entity", $entity)->where("entity_id", $model->id)->delete();
if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) {
$file = new FileUpload($_FILES['image'], ['jpg', 'jpeg', 'png']);
$file->upload();
$image = $file->getUploadFile();
$photo = new Photo();
$photo->entity = $entity;
$photo->entity_id = $model->id;
$photo->image = $image;
$photo->save();
}
}
public function getItems(string $entity, Model $model): array|string
{
$photos = Photo::where("entity", $entity)->where("entity_id", $model->id)->get();
$photoStr = "";
foreach ($photos as $photo) {
$photoStr .= "<img src='$photo->image' width='150px'>" . " ";
}
return substr($photoStr, 0, -1);
}
public function getItem(string $entity, string $entity_id): string
{
$photos = Photo::where("entity", $entity)->where("entity_id", $entity_id)->get();
$photoStr = "";
foreach ($photos as $photo) {
$photoStr .= "<img src='$photo->image' width='150px'>" . " ";
}
return substr($photoStr, 0, -1);
}
public function deleteItems(string $entity, Model $model): void
{
Photo::where("entity", $entity)->where("entity_id", $model->id)->delete();
}
}

View File

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

View File

@ -1,13 +0,0 @@
{
"name": "Photo",
"version": "0.1",
"author": "ITGuild",
"slug": "photo",
"type": "additional_property",
"description": "Photo module",
"app_module_path": "{APP}/modules/{slug}",
"module_class": "app\\modules\\photo\\PhotoModule",
"module_class_file": "{APP}/modules/photo/PhotoModule.php",
"routs": "routs/photo.php",
"dependence": "menu"
}

View File

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

View File

@ -1,38 +0,0 @@
<?php
namespace app\modules\slider;
use kernel\Module;
use kernel\modules\menu\service\MenuService;
use kernel\services\MigrationService;
class SliderModule extends Module
{
public MenuService $menuService;
public MigrationService $migrationService;
public function __construct()
{
$this->menuService = new MenuService();
$this->migrationService = new MigrationService();
}
/**
* @throws \Exception
*/
public function init(): void
{
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/slider/migrations");
$this->menuService->createItem([
"label" => "Слайдер",
"url" => "/admin/slider",
"slug" => "slider",
]);
}
public function deactivate(): void
{
$this->menuService->removeItemBySlug("slider");
}
}

View File

@ -1,35 +0,0 @@
<?php
namespace app\modules\slider\controllers;
use app\modules\slider\models\Slider;
use Exception;
use kernel\AdminController;
class SliderController extends AdminController
{
protected function init(): void
{
parent::init();
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/photo/views/";
}
public function actionIndex($page_number = 1): void
{
$this->cgView->render("index.php", ['page_number' => $page_number]);
}
/**
* @throws Exception
*/
public function actionView($id): void
{
$slide = Slider::find($id);
if (!$slide){
throw new Exception(message: "The slide not found");
}
$this->cgView->render("view.php", ['slider' => $slide]);
}
}

View File

@ -1,13 +0,0 @@
{
"name": "Slider",
"version": "0.1",
"author": "ITGuild",
"slug": "slider",
"type": "entity",
"description": "Slider module",
"app_module_path": "{APP}/modules/{slug}",
"module_class": "app\\modules\\slider\\SliderModule",
"module_class_file": "{APP}/modules/slider/SliderModule.php",
"routs": "routs/slider.php",
"dependence": "menu, user"
}

View File

@ -1,31 +0,0 @@
<?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('slider', function (Blueprint $table) {
$table->increments('id');
$table->string('title', 255)->nullable(false);
$table->string('additional_information', 255)->nullable(false);
$table->string('content', 255)->nullable(false);
$table->integer('status')->default(0);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
\kernel\App::$db->schema->dropIfExists('slider');
}
};

View File

@ -1,39 +0,0 @@
<?php
namespace app\modules\slider\models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property string $title
* @property string $additionalInformation
* @property string $content
*/
class Slider extends Model
{
const int DISABLE_STATUS = 0;
const int ACTIVE_STATUS = 1;
protected $table = "slider";
protected $fillable = ['title', 'additional_information', 'content'];
public static function labels()
{
return [
'title' => 'Заголовок',
'additional_information' => 'Дополнительная информация',
'content' => 'Контент'
];
}
public static function getStatus(): array
{
return [
self::DISABLE_STATUS => "Не активный",
self::ACTIVE_STATUS => "Активный",
];
}
}

View File

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

View File

@ -1,43 +0,0 @@
<?php
/**
* @var int $page_number
*/
use app\modules\slider\models\Slider;
use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable;
use kernel\app_modules\photo\models\Photo;
use kernel\widgets\IconBtn\IconBtnCreateWidget;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnViewWidget;
$table = new ListEloquentTable(new EloquentDataProvider(Slider::class, [
'currentPage' => $page_number,
'perPage' => 8,
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/photo",
]));
$table->beforePrint(function () {
return IconBtnCreateWidget::create(['url' => '/admin/slider/create'])->run();
});
$table->columns([
"status" => [
"value" => function ($cell) {
return Slider::getStatus()[$cell];
}]
]);
$table->addAction(function($row) {
return IconBtnViewWidget::create(['url' => '/admin/slider/view/' . $row['id']])->run();
});
$table->addAction(function($row) {
return IconBtnEditWidget::create(['url' => '/admin/slider/update/' . $row['id']])->run();
});
$table->addAction(function($row) {
return IconBtnDeleteWidget::create(['url' => '/admin/slider/delete/' . $row['id']])->run();
});
$table->create();
$table->render();

View File

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

View File

@ -65,7 +65,6 @@ class TagModule extends Module
if (isset($model->id)) {
$value = TagEntityService::getTagsByEntity($entity, $model->id);
}
$input = SelectBuilder::build("tag[]", [
'class' => 'form-control',
'placeholder' => 'Теги',
@ -82,7 +81,6 @@ class TagModule extends Module
TagEntity::where("entity", $entity)->where("entity_id", $model->id)->delete();
$tags = $request->post("tag");
if (is_array($tags)) {
foreach ($tags as $tag) {
$tagEntity = new TagEntity();
$tagEntity->entity = $entity;
@ -91,7 +89,6 @@ class TagModule extends Module
$tagEntity->save();
}
}
}
public function getItems(string $entity, Model $model): array|string

View File

@ -25,7 +25,7 @@ class EntityRelation
$activeModules = $moduleService->getActiveModules();
foreach ($activeModules as $module) {
if (isset($module['type']) and $module['type'] === "entity") {
$list[$module['slug']] = $module['slug'];
$list[$module['slug']] = $module['name'];
}
}
@ -45,7 +45,7 @@ class EntityRelation
return $list;
}
public static function getEntitiesRelations(): array|bool
public function getEntitiesRelations(): array|bool
{
$entity_relations = OptionService::getItem("entity_relations");
if ($entity_relations) {
@ -61,13 +61,8 @@ class EntityRelation
if ($entity_relations_info) {
$entity_relations = json_decode($entity_relations_info->value, true);
if ($entity_relations[$entity]) {
$propertyKey = array_search($property, $entity_relations[$entity]);
if ($entity_relations[$entity][$propertyKey] === $property) {
unset($entity_relations[$entity][$propertyKey]);
$entity_relations[$entity] = array_values($entity_relations[$entity]);
if (empty($entity_relations[$entity])) {
unset($entity_relations[$entity]);
}
if ($entity_relations[$entity][$property]) {
unset($entity_relations[$entity][$property]);
$entity_relations_info->value = json_encode($entity_relations, JSON_UNESCAPED_UNICODE);
$entity_relations_info->save();
return true;
@ -123,10 +118,10 @@ class EntityRelation
}
}
return [];
return false;
}
public static function addEntityRelation(string $entity, string $property): bool
public function addEntityRelation(string $entity, string $property): bool
{
$entity_relations_info = Option::where("key", "entity_relations")->first();
if ($entity_relations_info) {
@ -134,7 +129,7 @@ class EntityRelation
if (isset($entity_relations[$entity])) {
$entity_relations[$entity][] = $property;
} else {
$entity_relations[$entity][] = $property;
$entity_relations[$entity] = $property;
}
$entity_relations_info->value = json_encode($entity_relations, JSON_UNESCAPED_UNICODE);
$entity_relations_info->save();
@ -236,44 +231,4 @@ class EntityRelation
}
}
}
public static function getEntityByProperty(string $data): array
{
$entityRelations = self::getEntitiesRelations();
$entities = [];
foreach ($entityRelations as $entity => $property) {
if (in_array($data, $property)) {
$entities[] = $entity;
}
}
return $entities;
}
public static function configurationEntitiesByProperty(array|null $entities, string $property): void
{
$entityRelations = self::getEntitiesRelations();
if (isset($entities)) {
foreach ($entities as $entity) {
if (!isset($entityRelations[$entity])) {
EntityRelation::addEntityRelation($entity, $property);
}
}
foreach ($entityRelations as $entity => $additionalProperty) {
if (in_array($entity, $entities)) {
if (!in_array($property, $additionalProperty)) {
EntityRelation::addEntityRelation($entity, $property);
}
} else {
if (in_array($property, $additionalProperty)) {
EntityRelation::removePropertyFromEntityRelations($entity, $property);
}
}
}
} else {
foreach ($entityRelations as $entity => $additionalProperty) {
EntityRelation::removePropertyFromEntityRelations($entity, $property);
}
}
}
}

View File

@ -59,16 +59,6 @@ class FormModel
return false;
}
public function validateForUpdate(): bool
{
$res = $this->validator->validate($this->data, $this->rulesForUpdate());
if (!$res) {
return true;
}
return false;
}
public function getErrors(): array
{
return $this->validator->getProcessedErrors();

View File

@ -1,77 +0,0 @@
<?php
namespace kernel\app_modules\photo\controllers;
use Exception;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\app_modules\photo\models\form\CreatePhotoForm;
use kernel\app_modules\photo\models\Photo;
use kernel\app_modules\photo\services\PhotoService;
use kernel\EntityRelation;
use kernel\Flash;
use kernel\helpers\Debug;
use kernel\Request;
class PhotoController extends AdminController
{
private PhotoService $photoService;
protected function init(): void
{
parent::init();
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/photo/views/";
$this->photoService = new PhotoService();
}
public function actionCreate(): void
{
$this->cgView->render("form.php");
}
#[NoReturn] public function actionAdd(): void
{
$photoForm = new CreatePhotoForm();
$photoForm->load($_REQUEST);
if ($photoForm->validate()){
$photo = $this->photoService->create($photoForm);
if ($photo){
$this->redirect("/admin/photo/view/" . $photo->id);
}
}
$this->redirect("/admin/photo/create");
}
public function actionIndex($page_number = 1): void
{
$this->cgView->render("index.php", ['page_number' => $page_number]);
}
/**
* @throws Exception
*/
public function actionView($id): void
{
$photo = Photo::find($id);
if (!$photo){
throw new Exception(message: "The photo not found");
}
$this->cgView->render("view.php", ['photo' => $photo]);
}
public function actionSettings(): void
{
$this->cgView->render('settingsForm.php');
}
#[NoReturn] public function actionSaveSettings(): void
{
$request = new Request();
$entities = $request->post('entity');
EntityRelation::configurationEntitiesByProperty($entities, 'photo');
Flash::setMessage("success", "Настройка прошла успешно");
$this->redirect("/admin/settings/photo", 302);
}
}

View File

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

View File

@ -1,44 +0,0 @@
<?php
namespace kernel\app_modules\photo\models;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property string $image
* @property string $entity
* @property int $entity_id
*/
class Photo extends Model
{
protected $table = 'photo';
protected $fillable = ['image', 'entity', 'entity_id'];
public static function labels(): array
{
return [
'image' => 'Фото',
'entity' => 'Сущность',
'entity_id' => 'Идентификатор сущности',
];
}
public static function getPhotoListByEntity(string $entity): array
{
return self::where("entity", $entity)->get()->toArray();
}
public static function getPhotoByEntity(string $entity): array
{
$result = [];
$photos = self::getPhotoListByEntity($entity);
foreach ($photos as $photo) {
$result[$photo['id']] = $photo['label'];
}
return $result;
}
}

View File

@ -1,19 +0,0 @@
<?php
namespace kernel\app_modules\photo\models\form;
use kernel\FormModel;
class CreatePhotoForm extends FormModel
{
public function rules(): array
{
return [
'image' => 'required',
'entity' => 'required|string',
'entity_id' => 'required|integer|min:1',
];
}
}

View File

@ -1,24 +0,0 @@
<?php
use kernel\App;
use kernel\CgRouteCollector;
use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
App::$collector->group(["prefix" => "photo"], function (CGRouteCollector $router) {
App::$collector->get('/', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionIndex']);
App::$collector->get('/page/{page_number}', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionIndex']);
App::$collector->get('/create', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionCreate']);
App::$collector->post("/", [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionAdd']);
App::$collector->get('/view/{id}', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionView']);
App::$collector->any('/update/{id}', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\kernel\app_modules\photo\controllers\PhotoController::class]);
});
App::$collector->group(["prefix" => "settings"], function (CGRouteCollector $router) {
App::$collector->get('/photo', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionSettings']);
App::$collector->post('/photo/update', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionSaveSettings']);
});
});
});

View File

@ -1,40 +0,0 @@
<?php
namespace kernel\app_modules\photo\services;
use kernel\app_modules\photo\models\Photo;
use kernel\FormModel;
use kernel\helpers\Debug;
class PhotoService
{
public function create(FormModel $form_model): false|Photo
{
$model = new Photo();
$model->image = $form_model->getItem('image');
$model->entity = $form_model->getItem('entity');
$model->entity_id = $form_model->getItem('entity_id');
return false;
}
public function update(FormModel $form_model, Photo $photo): false|Photo
{
$photo->image = $form_model->getItem('image');
$photo->entity = $form_model->getItem('entity');
$photo->entity_id = $form_model->getItem('entity_id');
if ($photo->save()){
return $photo;
}
return false;
}
public static function getByEntity(string $entity, int $entity_id): string
{
$photo = Photo::where("entity", $entity)->where("entity_id", $entity_id)->first();
return $photo->image ?? "";
}
}

View File

@ -1,41 +0,0 @@
<?php
/**
* @var int $page_number
*/
use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable;
use kernel\app_modules\photo\models\Photo;
use kernel\widgets\IconBtn\IconBtnCreateWidget;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnViewWidget;
$table = new ListEloquentTable(new EloquentDataProvider(Photo::class, [
'currentPage' => $page_number,
'perPage' => 8,
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/photo",
]));
//$table->beforePrint(function () {
// return IconBtnCreateWidget::create(['url' => '/admin/photo/create'])->run();
//});
$table->columns([
'image' => function ($data) {
return $data ? "<img src='$data' width='150px'>" : "";
}
]);
$table->addAction(function($row) {
return IconBtnViewWidget::create(['url' => '/admin/photo/view/' . $row['id']])->run();
});
//$table->addAction(function($row) {
// return IconBtnEditWidget::create(['url' => '/admin/photo/update/' . $row['id']])->run();
//});
//$table->addAction(function($row) {
// return IconBtnDeleteWidget::create(['url' => '/admin/photo/delete/' . $row['id']])->run();
//});
$table->create();
$table->render();

View File

@ -1,46 +0,0 @@
<?php
$form = new \itguild\forms\ActiveForm();
$form->beginForm("/admin/settings/photo/update");
?>
<div class="row">
<h5>Выберите сущности, к которым хотите прикрепить фото</h5>
</div>
<?php
$form->field(\itguild\forms\inputs\Select::class, "entity[]", [
'class' => "form-control",
'value' => \kernel\EntityRelation::getEntityByProperty('photo') ?? '',
'multiple' => "multiple",
])
->setLabel("Сущности")
->setOptions(\kernel\EntityRelation::getEntityList())
->render();
?>
<div class="row">
<div class="col-sm-2">
<?php
$form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [
'class' => "btn btn-primary ",
'value' => 'Отправить',
'typeInput' => 'submit'
])
->render();
?>
</div>
<div class="col-sm-2">
<?php
$form->field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [
'class' => "btn btn-warning",
'value' => 'Сбросить',
'typeInput' => 'reset'
])
->render();
?>
</div>
</div>
<?php
$form->endForm();

View File

@ -1,34 +0,0 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $photo
*/
use kernel\modules\user\models\User;
use Itguild\EloquentTable\ViewEloquentTable;
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
use kernel\IGTabel\btn\DangerBtn;
use kernel\IGTabel\btn\PrimaryBtn;
use kernel\IGTabel\btn\SuccessBtn;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnListWidget;
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($photo, [
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/photo",
]));
$table->beforePrint(function () use ($photo) {
$btn = IconBtnListWidget::create(['url' => '/admin/photo'])->run();
// $btn .= IconBtnEditWidget::create(['url' => '/admin/photo/update/' . $photo->id])->run();
// $btn .= IconBtnDeleteWidget::create(['url' => '/admin/photo/delete/' . $photo->id])->run();
return $btn;
});
$table->rows([
'image' => function ($data) {
return $data ? "<img src='$data' width='300px'>" : "";
}
]);
$table->create();
$table->render();

View File

@ -8,12 +8,8 @@ use kernel\AdminController;
use kernel\app_modules\tag\models\forms\CreateTagForm;
use kernel\app_modules\tag\models\Tag;
use kernel\app_modules\tag\services\TagService;
use kernel\EntityRelation;
use kernel\Flash;
use kernel\helpers\Debug;
use kernel\models\Option;
use kernel\modules\menu\service\MenuService;
use kernel\Request;
class TagController extends AdminController
{
@ -104,17 +100,7 @@ class TagController extends AdminController
public function actionSettings(): void
{
$this->cgView->render('settingsForm.php');
}
#[NoReturn] public function actionSaveSettings(): void
{
$request = new Request();
$entities = $request->post('entity');
EntityRelation::configurationEntitiesByProperty($entities, 'tag');
Flash::setMessage("success", "Настройка прошла успешно");
$this->redirect("/admin/settings/tag", 302);
$this->cgView->render('form.php');
}
}

View File

@ -15,19 +15,32 @@ use kernel\modules\menu\service\MenuService;
class TagEntityController extends AdminController
{
/**
* @return void
*/
private TagEntityService $tagEntityService;
protected function init(): void
{
parent::init();
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/tag_entity/";
$this->tagEntityService = new TagEntityService();
}
/**
* @param $page_number
* @return void
*/
// public function actionCreate(): void
// {
// $this->cgView->render("form.php");
// }
//
// #[NoReturn] public function actionAdd(): void
// {
// $tagForm = new CreateTagForm();
// $tagForm->load($_REQUEST);
// if ($tagForm->validate()){
// $tag = $this->tagEntityService->create($tagForm);
// if ($tag){
// $this->redirect("/admin/tag/" . $tag->id);
// }
// }
// $this->redirect("/admin/tag/create");
// }
public function actionIndex($page_number = 1): void
{
$this->cgView->render("index.php", ['page_number' => $page_number]);
@ -46,4 +59,45 @@ class TagEntityController extends AdminController
$this->cgView->render("view.php", ['tagEntity' => $tagEntity]);
}
// /**
// * @throws Exception
// */
// public function actionUpdate($id): void
// {
// $model = Tag::find($id);
// if (!$model){
// throw new Exception(message: "The tag not found");
// }
//
// $this->cgView->render("form.php", ['model' => $model]);
// }
//
// /**
// * @throws Exception
// */
// public function actionEdit($id): void
// {
// $tag = Tag::find($id);
// if (!$tag){
// throw new Exception(message: "The tag not found");
// }
// $tagForm = new CreateTagForm();
// $tagService = new TagService();
// $tagForm->load($_REQUEST);
// if ($tagForm->validate()) {
// $tag = $tagService->update($tagForm, $tag);
// if ($tag) {
// $this->redirect("/admin/tag/" . $tag->id);
// }
// }
// $this->redirect("/admin/tag/update/" . $id);
// }
//
// #[NoReturn] public function actionDelete($id): void
// {
// $post = Tag::find($id)->first();
// $post->delete();
// $this->redirect("/admin/tag/");
// }
}

View File

@ -28,7 +28,6 @@ App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router
});
App::$collector->group(["prefix" => "settings"], function (CGRouteCollector $router) {
App::$collector->get('/tag', [\app\modules\tag\controllers\TagController::class, 'actionSettings']);
App::$collector->post('/tag/update', [\app\modules\tag\controllers\TagController::class, 'actionSaveSettings']);
});
});
});

View File

@ -1,5 +1,6 @@
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $menuItem
* @var int $page_number
*/
@ -21,6 +22,7 @@ $table = new ListEloquentTable(new EloquentDataProvider(Tag::class, [
$table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/tag/create")->fetch();
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
});
$table->columns([

View File

@ -1,47 +0,0 @@
<?php
$form = new \itguild\forms\ActiveForm();
$form->beginForm("/admin/settings/tag/update");
//\kernel\helpers\Debug::dd($value);
?>
<div class="row">
<h5>Выберите сущности, к которым хотите прикрепить теги</h5>
</div>
<?php
$form->field(\itguild\forms\inputs\Select::class, "entity[]", [
'class' => "form-control",
'value' => \kernel\EntityRelation::getEntityByProperty('tag') ?? '',
'multiple' => "multiple",
])
->setLabel("Сущности")
->setOptions(\kernel\EntityRelation::getEntityList())
->render();
?>
<div class="row">
<div class="col-sm-2">
<?php
$form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [
'class' => "btn btn-primary ",
'value' => 'Отправить',
'typeInput' => 'submit'
])
->render();
?>
</div>
<div class="col-sm-2">
<?php
$form->field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [
'class' => "btn btn-warning",
'value' => 'Сбросить',
'typeInput' => 'reset'
])
->render();
?>
</div>
</div>
<?php
$form->endForm();

View File

@ -1,30 +0,0 @@
<?php
namespace kernel\helpers;
class Html
{
public static function img(string $src, array $params = [])
{
$paramsStr = self::createParams($params);
return "<img src='$src' $paramsStr>";
}
/**
* @param array $data
* @return string
*/
public static function createParams(array $data = []): string
{
$paramsString = "";
foreach($data as $key => $param){
if(is_string($param)){
$paramsString .= $key . "='" . $param . "'";
}
}
return $paramsString;
}
}

View File

@ -6,7 +6,7 @@
use kernel\modules\post\models\Post;
$form = new \itguild\forms\ActiveForm();
$form->beginForm(isset($model) ? "/admin/post/edit/" . $model->id : "/admin/post", 'multipart/form-data');
$form->beginForm(isset($model) ? "/admin/post/edit/" . $model->id : "/admin/post");
$form->field(\itguild\forms\inputs\TextInput::class, 'title', [
'class' => "form-control",

View File

@ -5,11 +5,9 @@ namespace kernel\modules\user\controllers;
use Exception;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\EntityRelation;
use kernel\modules\user\models\forms\CreateUserForm;
use kernel\modules\user\models\User;
use kernel\modules\user\service\UserService;
use kernel\Request;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
@ -37,11 +35,6 @@ class UserController extends AdminController
$userForm->load($_REQUEST);
if ($userForm->validate()){
$user = $this->userService->create($userForm);
$entityRelation = new EntityRelation();
$entityRelation->saveEntityRelation(entity: "user", model: $user, request: new Request());
if ($user){
$this->redirect("/admin/user/view/" . $user->id);
}
@ -98,12 +91,8 @@ class UserController extends AdminController
$userForm = new CreateUserForm();
$userService = new UserService();
$userForm->load($_REQUEST);
if ($userForm->validateForUpdate()){
if ($userForm->validate()){
$user = $userService->update($userForm, $user);
$entityRelation = new EntityRelation();
$entityRelation->saveEntityRelation(entity: "user", model: $user, request: new Request());
if ($user){
$this->redirect("/admin/user/view/" . $user->id);
}
@ -111,20 +100,9 @@ class UserController extends AdminController
$this->redirect("/admin/user/update/" . $id);
}
/**
* @throws Exception
*/
#[NoReturn] public function actionDelete($id): void
{
$user = User::find($id)->first();
if (!$user){
throw new Exception(message: "The user not found");
}
$entityRelation = new EntityRelation();
$entityRelation->deleteEntityRelation(entity: "user", model: $user);
$user->delete();
User::find($id)->delete();
$this->redirect("/admin/user/");
}

View File

@ -16,13 +16,4 @@ class CreateUserForm extends FormModel
];
}
public function rulesForUpdate(): array
{
return [
'username' => 'required|min-str-len:5|max-str-len:30',
'password' => '',
'email' => 'required|email'
];
}
}

View File

@ -3,7 +3,6 @@
namespace kernel\modules\user\service;
use kernel\FormModel;
use kernel\helpers\Debug;
use kernel\modules\user\models\User;
class UserService
@ -26,9 +25,7 @@ class UserService
{
$user->username = $form_model->getItem('username');
$user->email = $form_model->getItem('email');
if ($form_model->getItem('password')) {
$user->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT);
}
if ($user->save()){
return $user;
}

View File

@ -6,7 +6,7 @@
use kernel\modules\user\models\User;
$form = new \itguild\forms\ActiveForm();
$form->beginForm(isset($model) ? "/admin/user/edit/" . $model->id : "/admin/user", enctype: 'multipart/form-data');
$form->beginForm(isset($model) ? "/admin/user/edit/" . $model->id : "/admin/user");
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "username", params: [
'class' => "form-control",
@ -32,11 +32,6 @@ $form->field(class: \itguild\forms\inputs\TextInput::class, name: "email", param
->setLabel("Email")
->render();
$entityRelations = new \kernel\EntityRelation();
if (!isset($model)) {
$model = new User();
}
$entityRelations->renderEntityAdditionalPropertyFormBySlug("user", $model);
?>
<div class="row">
<div class="col-sm-2">

View File

@ -24,16 +24,6 @@ $table = new ListEloquentTable(new EloquentDataProvider(User::class, [
'baseUrl' => "/admin/user",
'filters' => ['email'],
]));
$entityRelation = new \kernel\EntityRelation();
$additionals = $entityRelation->getEntityRelationsBySlug("user");
foreach ($additionals as $additional) {
$table->addColumn($additional, $additional, function ($id) use ($entityRelation, $additional) {
return $entityRelation->getAdditionalPropertyByEntityId("user", $id, $additional);
});
}
$table->columns([
'username' => [
"filter" => [

View File

@ -25,15 +25,6 @@ $table->beforePrint(function () use ($user) {
return $btn;
});
$entityRelation = new \kernel\EntityRelation();
$additionals = $entityRelation->getEntityAdditionalProperty("user", $user);
foreach ($additionals as $key => $additional) {
$table->addRow($key, function () use ($additional) {
return $additional;
}, ['after' => 'email']);
}
$table->rows([
'created_at' => function ($data) {
if (!$data){

View File

@ -4,21 +4,17 @@ namespace kernel\services;
use DirectoryIterator;
use kernel\EntityRelation;
use kernel\Flash;
use kernel\helpers\Debug;
use kernel\helpers\Files;
use kernel\helpers\Manifest;
use kernel\helpers\RESTClient;
use kernel\models\Option;
use MongoDB\Driver\Session;
use ZipArchive;
class ModuleService
{
protected array $errors = [];
protected null|bool $serverAvailable = null;
/**
* @param string $module
* @return false|array|string
@ -363,6 +359,8 @@ class ModuleService
mkdir(RESOURCES_DIR . '/tmp/modules', 0777, true);
}
$fileHelper->pack($tmpModuleDirFull, RESOURCES_DIR . '/tmp/modules/' . $moduleName . '.igm');
//$fileHelper->recursiveRemoveDir($tmpModuleDirFull);
}
/**
@ -444,7 +442,6 @@ class ModuleService
public function isLastVersion(string $slug): bool
{
if ($this->isServerAvailable()){
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
@ -454,9 +451,8 @@ class ModuleService
return true;
}
}
}
return false;
}
public function isKernelModule(string $slug): bool
@ -471,23 +467,6 @@ class ModuleService
return false;
}
public function isShopModule(string $slug): bool
{
if ($this->isServerAvailable()){
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
$mod_info = $this->getModuleInfoBySlug($slug);
foreach ($modules_info as $mod) {
if ($mod['slug'] === $mod_info['slug']) {
return true;
}
}
}
return false;
}
public function getKernelModules(): array
{
$modules_info = [];
@ -499,21 +478,4 @@ class ModuleService
return $modules_info;
}
public function isServerAvailable(): bool
{
if (null !== $this->serverAvailable){
return $this->serverAvailable;
}
try {
RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
$this->serverAvailable = true;
return true;
} catch (\Exception $e) {
$this->serverAvailable = false;
return false;
}
}
}

View File

@ -7,7 +7,6 @@
* @var \kernel\services\ModuleService $moduleService
*/
use kernel\Flash;
use kernel\widgets\IconBtn\IconBtnActivateWidget;
use kernel\widgets\IconBtn\IconBtnDeactivateWidget;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
@ -54,7 +53,7 @@ $table->addAction(function ($row, $url) use ($moduleService) {
});
$table->addAction(function ($row, $url) use ($moduleService){
if ($moduleService->isShopModule($row['slug'])){
if (!$moduleService->isKernelModule($row['slug'])){
if (!$moduleService->isLastVersion($row['slug'])) {
$url = "$url/update/?slug=". $row['slug'];
@ -75,7 +74,7 @@ $table->addAction(function ($row) use ($moduleService){
return false;
});
if ($moduleService->isActive('module_shop_client') && $moduleService->isServerAvailable()) {
if ($moduleService->isActive('module_shop_client')) {
ModuleTabsWidget::create()->run();
}