module construct, add some templates
This commit is contained in:
parent
a9951102c0
commit
1e566481f7
@ -5,7 +5,7 @@ namespace kernel\app_modules\photo;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use itguild\forms\builders\FileBuilder;
|
use itguild\forms\builders\FileBuilder;
|
||||||
use kernel\app_modules\photo\models\Photo;
|
use kernel\app_modules\photo\models\Photo;
|
||||||
use kernel\app_modules\photo\services\PhotoService;
|
use kernel\app_modules\photo\service\PhotoService;
|
||||||
use kernel\FileUpload;
|
use kernel\FileUpload;
|
||||||
use kernel\helpers\Html;
|
use kernel\helpers\Html;
|
||||||
use kernel\Module;
|
use kernel\Module;
|
||||||
|
@ -7,7 +7,7 @@ use JetBrains\PhpStorm\NoReturn;
|
|||||||
use kernel\AdminController;
|
use kernel\AdminController;
|
||||||
use kernel\app_modules\photo\models\form\CreatePhotoForm;
|
use kernel\app_modules\photo\models\form\CreatePhotoForm;
|
||||||
use kernel\app_modules\photo\models\Photo;
|
use kernel\app_modules\photo\models\Photo;
|
||||||
use kernel\app_modules\photo\services\PhotoService;
|
use kernel\app_modules\photo\service\PhotoService;
|
||||||
use kernel\EntityRelation;
|
use kernel\EntityRelation;
|
||||||
use kernel\Flash;
|
use kernel\Flash;
|
||||||
use kernel\helpers\Debug;
|
use kernel\helpers\Debug;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace kernel\app_modules\photo\services;
|
namespace kernel\app_modules\photo\service;
|
||||||
|
|
||||||
use kernel\app_modules\photo\models\Photo;
|
use kernel\app_modules\photo\models\Photo;
|
||||||
use kernel\FormModel;
|
use kernel\FormModel;
|
@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
use itguild\forms\builders\SelectBuilder;
|
use itguild\forms\builders\SelectBuilder;
|
||||||
use kernel\app_modules\tag\models\Tag;
|
use kernel\app_modules\tag\models\Tag;
|
||||||
use kernel\app_modules\tag\models\TagEntity;
|
use kernel\app_modules\tag\models\TagEntity;
|
||||||
use kernel\app_modules\tag\services\TagEntityService;
|
use kernel\app_modules\tag\service\TagEntityService;
|
||||||
use kernel\Module;
|
use kernel\Module;
|
||||||
use kernel\modules\menu\service\MenuService;
|
use kernel\modules\menu\service\MenuService;
|
||||||
use kernel\modules\option\service\OptionService;
|
use kernel\modules\option\service\OptionService;
|
||||||
|
@ -7,7 +7,7 @@ use JetBrains\PhpStorm\NoReturn;
|
|||||||
use kernel\AdminController;
|
use kernel\AdminController;
|
||||||
use kernel\app_modules\tag\models\forms\CreateTagForm;
|
use kernel\app_modules\tag\models\forms\CreateTagForm;
|
||||||
use kernel\app_modules\tag\models\Tag;
|
use kernel\app_modules\tag\models\Tag;
|
||||||
use kernel\app_modules\tag\services\TagService;
|
use kernel\app_modules\tag\service\TagService;
|
||||||
use kernel\EntityRelation;
|
use kernel\EntityRelation;
|
||||||
use kernel\Flash;
|
use kernel\Flash;
|
||||||
use kernel\helpers\Debug;
|
use kernel\helpers\Debug;
|
||||||
|
@ -8,8 +8,8 @@ use kernel\AdminController;
|
|||||||
use kernel\app_modules\tag\models\forms\CreateTagForm;
|
use kernel\app_modules\tag\models\forms\CreateTagForm;
|
||||||
use kernel\app_modules\tag\models\Tag;
|
use kernel\app_modules\tag\models\Tag;
|
||||||
use kernel\app_modules\tag\models\TagEntity;
|
use kernel\app_modules\tag\models\TagEntity;
|
||||||
use kernel\app_modules\tag\services\TagEntityService;
|
use kernel\app_modules\tag\service\TagEntityService;
|
||||||
use kernel\app_modules\tag\services\TagService;
|
use kernel\app_modules\tag\service\TagService;
|
||||||
use kernel\helpers\Debug;
|
use kernel\helpers\Debug;
|
||||||
use kernel\modules\menu\service\MenuService;
|
use kernel\modules\menu\service\MenuService;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace kernel\app_modules\tag\services;
|
namespace kernel\app_modules\tag\service;
|
||||||
|
|
||||||
use kernel\app_modules\tag\models\Tag;
|
use kernel\app_modules\tag\models\Tag;
|
||||||
use kernel\app_modules\tag\models\TagEntity;
|
use kernel\app_modules\tag\models\TagEntity;
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace kernel\app_modules\tag\services;
|
namespace kernel\app_modules\tag\service;
|
||||||
|
|
||||||
use kernel\app_modules\tag\models\Tag;
|
use kernel\app_modules\tag\models\Tag;
|
||||||
use kernel\FormModel;
|
use kernel\FormModel;
|
@ -118,7 +118,7 @@ class ModuleController extends ConsoleController
|
|||||||
$moduleService->createControllers($slug);
|
$moduleService->createControllers($slug);
|
||||||
$this->out->r("Контроллеры созданы", 'green');
|
$this->out->r("Контроллеры созданы", 'green');
|
||||||
|
|
||||||
$moduleService->createRouts($slug);
|
$moduleService->createRoutes($slug);
|
||||||
$this->out->r("Роуты созданы", 'green');
|
$this->out->r("Роуты созданы", 'green');
|
||||||
|
|
||||||
$moduleService->createModuleClassFiles($slug, $label);
|
$moduleService->createModuleClassFiles($slug, $label);
|
||||||
@ -130,6 +130,12 @@ class ModuleController extends ConsoleController
|
|||||||
$moduleService->createFormModel($slug);
|
$moduleService->createFormModel($slug);
|
||||||
$this->out->r("Форма валидации для модели создана", 'green');
|
$this->out->r("Форма валидации для модели создана", 'green');
|
||||||
|
|
||||||
|
$moduleService->createService($slug);
|
||||||
|
$this->out->r("Сервис создан", 'green');
|
||||||
|
|
||||||
|
$moduleService->createViews($slug);
|
||||||
|
$this->out->r("Представления созданы", 'green');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -5,14 +5,10 @@
|
|||||||
* @var int $page_number
|
* @var int $page_number
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use kernel\IGTabel\action_column\DeleteActionColumn;
|
|
||||||
use kernel\IGTabel\action_column\EditActionColumn;
|
|
||||||
use kernel\IGTabel\action_column\ViewActionColumn;
|
|
||||||
use kernel\modules\post\models\Post;
|
use kernel\modules\post\models\Post;
|
||||||
use kernel\modules\user\models\User;
|
use kernel\modules\user\models\User;
|
||||||
use Itguild\EloquentTable\EloquentDataProvider;
|
use Itguild\EloquentTable\EloquentDataProvider;
|
||||||
use Itguild\EloquentTable\ListEloquentTable;
|
use Itguild\EloquentTable\ListEloquentTable;
|
||||||
use kernel\IGTabel\btn\PrimaryBtn;
|
|
||||||
use kernel\widgets\IconBtn\IconBtnCreateWidget;
|
use kernel\widgets\IconBtn\IconBtnCreateWidget;
|
||||||
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||||
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||||
|
@ -7,9 +7,6 @@
|
|||||||
use kernel\modules\user\models\User;
|
use kernel\modules\user\models\User;
|
||||||
use Itguild\EloquentTable\ViewEloquentTable;
|
use Itguild\EloquentTable\ViewEloquentTable;
|
||||||
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
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\IconBtnDeleteWidget;
|
||||||
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||||
use kernel\widgets\IconBtn\IconBtnListWidget;
|
use kernel\widgets\IconBtn\IconBtnListWidget;
|
||||||
|
@ -534,6 +534,7 @@ class ModuleService
|
|||||||
mkdir(KERNEL_APP_MODULES_DIR . "/$slug");
|
mkdir(KERNEL_APP_MODULES_DIR . "/$slug");
|
||||||
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/controllers");
|
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/controllers");
|
||||||
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/migrations");
|
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/migrations");
|
||||||
|
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/service");
|
||||||
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/models");
|
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/models");
|
||||||
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/models/forms");
|
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/models/forms");
|
||||||
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/routs");
|
mkdir(KERNEL_APP_MODULES_DIR . "/$slug/routs");
|
||||||
@ -578,7 +579,7 @@ class ModuleService
|
|||||||
file_put_contents(APP_DIR . '/modules/' . $slug . '/controllers/' . ucfirst($slug) . 'Controller.php', $data );
|
file_put_contents(APP_DIR . '/modules/' . $slug . '/controllers/' . ucfirst($slug) . 'Controller.php', $data );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createRouts(string $slug): void
|
public function createRoutes(string $slug): void
|
||||||
{
|
{
|
||||||
$data = file_get_contents(KERNEL_DIR . '/templates/routs/kernel_routs_template');
|
$data = file_get_contents(KERNEL_DIR . '/templates/routs/kernel_routs_template');
|
||||||
$data = str_replace('{slug}', $slug, $data);
|
$data = str_replace('{slug}', $slug, $data);
|
||||||
@ -621,4 +622,43 @@ class ModuleService
|
|||||||
file_put_contents(KERNEL_APP_MODULES_DIR . '/' . $slug . '/models/forms/Create' . ucfirst($slug) . 'Form.php', $data);
|
file_put_contents(KERNEL_APP_MODULES_DIR . '/' . $slug . '/models/forms/Create' . ucfirst($slug) . 'Form.php', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function createService(string $slug): void
|
||||||
|
{
|
||||||
|
$data = file_get_contents(KERNEL_DIR . '/templates/services/service_template');
|
||||||
|
$data = str_replace('{slug}', $slug, $data);
|
||||||
|
$data = str_replace('{model}', ucfirst($slug), $data);
|
||||||
|
file_put_contents(KERNEL_APP_MODULES_DIR . '/' . $slug . '/service/' . ucfirst($slug) . 'Service.php', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createViews(string $slug): void
|
||||||
|
{
|
||||||
|
$this->createIndex($slug);
|
||||||
|
$this->createView($slug);
|
||||||
|
$this->createForm($slug);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createIndex(string $slug): void
|
||||||
|
{
|
||||||
|
$data = file_get_contents(KERNEL_DIR . '/templates/views/index_template');
|
||||||
|
$data = str_replace('{slug}', $slug, $data);
|
||||||
|
$data = str_replace('{model}', ucfirst($slug), $data);
|
||||||
|
file_put_contents(KERNEL_APP_MODULES_DIR . '/' . $slug . '/views/index.php', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createView(string $slug): void
|
||||||
|
{
|
||||||
|
$data = file_get_contents(KERNEL_DIR . '/templates/views/view_template');
|
||||||
|
$data = str_replace('{slug}', $slug, $data);
|
||||||
|
$data = str_replace('{model}', ucfirst($slug), $data);
|
||||||
|
file_put_contents(KERNEL_APP_MODULES_DIR . '/' . $slug . '/views/view.php', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createForm(string $slug): void
|
||||||
|
{
|
||||||
|
$data = file_get_contents(KERNEL_DIR . '/templates/views/form_template');
|
||||||
|
$data = str_replace('{slug}', $slug, $data);
|
||||||
|
$data = str_replace('{model}', ucfirst($slug), $data);
|
||||||
|
file_put_contents(KERNEL_APP_MODULES_DIR . '/' . $slug . '/views/form.php', $data);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ use JetBrains\PhpStorm\NoReturn;
|
|||||||
use kernel\AdminController;
|
use kernel\AdminController;
|
||||||
use kernel\app_modules\{slug}\models\forms\Create{model}Form;
|
use kernel\app_modules\{slug}\models\forms\Create{model}Form;
|
||||||
use kernel\app_modules\{slug}\models\{model};
|
use kernel\app_modules\{slug}\models\{model};
|
||||||
use kernel\app_modules\{slug}\services\{model}Service;
|
use kernel\app_modules\{slug}\service\{model}Service;
|
||||||
use kernel\EntityRelation;
|
use kernel\EntityRelation;
|
||||||
use kernel\Flash;
|
use kernel\Flash;
|
||||||
use kernel\helpers\Debug;
|
use kernel\helpers\Debug;
|
||||||
|
40
kernel/templates/services/service_template
Normal file
40
kernel/templates/services/service_template
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\app_modules\{slug}\service;
|
||||||
|
|
||||||
|
use kernel\helpers\Debug;
|
||||||
|
use kernel\helpers\Slug;
|
||||||
|
use kernel\app_modules\{slug}\models\{model};
|
||||||
|
use kernel\FormModel;
|
||||||
|
|
||||||
|
class {model}Service
|
||||||
|
{
|
||||||
|
public function create(FormModel $form_model): false|{model}
|
||||||
|
{
|
||||||
|
$model = new {model}();
|
||||||
|
// Пример заполнения:
|
||||||
|
// $model->content = $form_model->getItem('content');
|
||||||
|
// $model->user_id = $form_model->getItem('user_id');
|
||||||
|
// $model->title = $form_model->getItem('title');
|
||||||
|
// $model->slug = Slug::createSlug($form_model->getItem('title'), {model}::class); // Генерация уникального slug
|
||||||
|
|
||||||
|
if ($model->save()){
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(FormModel $form_model, {model} ${slug}): false|{model}
|
||||||
|
{
|
||||||
|
// Пример обновления:
|
||||||
|
// ${slug}->content = $form_model->getItem('content');
|
||||||
|
// ${slug}->user_id = $form_model->getItem('user_id');
|
||||||
|
|
||||||
|
if (${slug}->save()){
|
||||||
|
return ${slug};
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
55
kernel/templates/views/form_template
Normal file
55
kernel/templates/views/form_template
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var {model} $model
|
||||||
|
*/
|
||||||
|
|
||||||
|
use kernel\app_modules\{slug}\models\{model};
|
||||||
|
|
||||||
|
$form = new \itguild\forms\ActiveForm();
|
||||||
|
$form->beginForm(isset($model) ? "/admin/{slug}/edit/" . $model->id : "/admin/{slug}", 'multipart/form-data');
|
||||||
|
|
||||||
|
// Пример формы:
|
||||||
|
|
||||||
|
/*
|
||||||
|
$form->field(\itguild\forms\inputs\TextInput::class, 'title', [
|
||||||
|
'class' => "form-control",
|
||||||
|
'placeholder' => 'Заголовок поста',
|
||||||
|
'value' => $model->title ?? ''
|
||||||
|
])
|
||||||
|
->setLabel("Заголовок")
|
||||||
|
->render();
|
||||||
|
|
||||||
|
$form->field(class: \itguild\forms\inputs\Select::class, name: "user_id", params: [
|
||||||
|
'class' => "form-control",
|
||||||
|
'value' => $model->user_id ?? ''
|
||||||
|
])
|
||||||
|
->setLabel("Пользователи")
|
||||||
|
->setOptions(\kernel\modules\user\service\UserService::createUsernameArr())
|
||||||
|
->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();
|
37
kernel/templates/views/index_template
Normal file
37
kernel/templates/views/index_template
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Illuminate\Database\Eloquent\Collection ${slug}
|
||||||
|
* @var int $page_number
|
||||||
|
*/
|
||||||
|
|
||||||
|
use kernel\app_modules\{slug}\models\{model};
|
||||||
|
use Itguild\EloquentTable\EloquentDataProvider;
|
||||||
|
use Itguild\EloquentTable\ListEloquentTable;
|
||||||
|
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({model}::class, [
|
||||||
|
'currentPage' => $page_number,
|
||||||
|
'perPage' => 8,
|
||||||
|
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||||
|
'baseUrl' => "/admin/{slug}"
|
||||||
|
]));
|
||||||
|
|
||||||
|
$table->beforePrint(function () {
|
||||||
|
return IconBtnCreateWidget::create(['url' => '/admin/{slug}/create'])->run();
|
||||||
|
});
|
||||||
|
|
||||||
|
$table->addAction(function($row) {
|
||||||
|
return IconBtnViewWidget::create(['url' => '/admin/{slug}/view/' . $row['id']])->run();
|
||||||
|
});
|
||||||
|
$table->addAction(function($row) {
|
||||||
|
return IconBtnEditWidget::create(['url' => '/admin/{slug}/update/' . $row['id']])->run();
|
||||||
|
});
|
||||||
|
$table->addAction(function($row) {
|
||||||
|
return IconBtnDeleteWidget::create(['url' => '/admin/{slug}/delete/' . $row['id']])->run();
|
||||||
|
});
|
||||||
|
$table->create();
|
||||||
|
$table->render();
|
25
kernel/templates/views/view_template
Normal file
25
kernel/templates/views/view_template
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Illuminate\Database\Eloquent\Collection ${slug}
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Itguild\EloquentTable\ViewEloquentTable;
|
||||||
|
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||||||
|
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||||
|
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||||
|
use kernel\widgets\IconBtn\IconBtnListWidget;
|
||||||
|
|
||||||
|
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel(${slug}, [
|
||||||
|
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||||
|
'baseUrl' => "/admin/{slug}",
|
||||||
|
]));
|
||||||
|
$table->beforePrint(function () use (${slug}) {
|
||||||
|
$btn = IconBtnListWidget::create(['url' => '/admin/{slug}'])->run();
|
||||||
|
$btn .= IconBtnEditWidget::create(['url' => '/admin/{slug}/update/' . ${slug}->id])->run();
|
||||||
|
$btn .= IconBtnDeleteWidget::create(['url' => '/admin/{slug}/delete/' . ${slug}->id])->run();
|
||||||
|
return $btn;
|
||||||
|
});
|
||||||
|
|
||||||
|
$table->create();
|
||||||
|
$table->render();
|
Loading…
Reference in New Issue
Block a user