diff --git a/kernel/app_modules/photo/PhotoModule.php b/kernel/app_modules/photo/PhotoModule.php index a944c08..f151a35 100644 --- a/kernel/app_modules/photo/PhotoModule.php +++ b/kernel/app_modules/photo/PhotoModule.php @@ -5,7 +5,7 @@ namespace kernel\app_modules\photo; use Illuminate\Database\Eloquent\Model; use itguild\forms\builders\FileBuilder; use kernel\app_modules\photo\models\Photo; -use kernel\app_modules\photo\services\PhotoService; +use kernel\app_modules\photo\service\PhotoService; use kernel\FileUpload; use kernel\helpers\Html; use kernel\Module; diff --git a/kernel/app_modules/photo/controllers/PhotoController.php b/kernel/app_modules/photo/controllers/PhotoController.php index 17be731..fccbbfa 100755 --- a/kernel/app_modules/photo/controllers/PhotoController.php +++ b/kernel/app_modules/photo/controllers/PhotoController.php @@ -7,7 +7,7 @@ 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\app_modules\photo\service\PhotoService; use kernel\EntityRelation; use kernel\Flash; use kernel\helpers\Debug; diff --git a/kernel/app_modules/photo/services/PhotoService.php b/kernel/app_modules/photo/service/PhotoService.php similarity index 95% rename from kernel/app_modules/photo/services/PhotoService.php rename to kernel/app_modules/photo/service/PhotoService.php index dd82590..fa280f7 100755 --- a/kernel/app_modules/photo/services/PhotoService.php +++ b/kernel/app_modules/photo/service/PhotoService.php @@ -1,6 +1,6 @@ createControllers($slug); $this->out->r("Контроллеры созданы", 'green'); - $moduleService->createRouts($slug); + $moduleService->createRoutes($slug); $this->out->r("Роуты созданы", 'green'); $moduleService->createModuleClassFiles($slug, $label); @@ -130,6 +130,12 @@ class ModuleController extends ConsoleController $moduleService->createFormModel($slug); $this->out->r("Форма валидации для модели создана", 'green'); + $moduleService->createService($slug); + $this->out->r("Сервис создан", 'green'); + + $moduleService->createViews($slug); + $this->out->r("Представления созданы", 'green'); + } } \ No newline at end of file diff --git a/kernel/modules/post/views/index.php b/kernel/modules/post/views/index.php index d82ecb5..906528a 100644 --- a/kernel/modules/post/views/index.php +++ b/kernel/modules/post/views/index.php @@ -5,14 +5,10 @@ * @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\user\models\User; use Itguild\EloquentTable\EloquentDataProvider; use Itguild\EloquentTable\ListEloquentTable; -use kernel\IGTabel\btn\PrimaryBtn; use kernel\widgets\IconBtn\IconBtnCreateWidget; use kernel\widgets\IconBtn\IconBtnDeleteWidget; use kernel\widgets\IconBtn\IconBtnEditWidget; diff --git a/kernel/modules/post/views/view.php b/kernel/modules/post/views/view.php index e3693d1..537ee55 100644 --- a/kernel/modules/post/views/view.php +++ b/kernel/modules/post/views/view.php @@ -7,9 +7,6 @@ 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; diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index 92d8a3d..94ca517 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -534,6 +534,7 @@ class ModuleService mkdir(KERNEL_APP_MODULES_DIR . "/$slug"); mkdir(KERNEL_APP_MODULES_DIR . "/$slug/controllers"); 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/forms"); 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 ); } - public function createRouts(string $slug): void + public function createRoutes(string $slug): void { $data = file_get_contents(KERNEL_DIR . '/templates/routs/kernel_routs_template'); $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); } + 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); + } + } \ No newline at end of file diff --git a/kernel/templates/controllers/kernel_controller_template b/kernel/templates/controllers/kernel_controller_template index c9fcf7c..8afd414 100644 --- a/kernel/templates/controllers/kernel_controller_template +++ b/kernel/templates/controllers/kernel_controller_template @@ -7,7 +7,7 @@ use JetBrains\PhpStorm\NoReturn; use kernel\AdminController; use kernel\app_modules\{slug}\models\forms\Create{model}Form; 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\Flash; use kernel\helpers\Debug; diff --git a/kernel/templates/services/service_template b/kernel/templates/services/service_template new file mode 100644 index 0000000..ba4277d --- /dev/null +++ b/kernel/templates/services/service_template @@ -0,0 +1,40 @@ +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; + } +} \ No newline at end of file diff --git a/kernel/templates/views/form_template b/kernel/templates/views/form_template new file mode 100644 index 0000000..180618b --- /dev/null +++ b/kernel/templates/views/form_template @@ -0,0 +1,55 @@ +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(); +*/ + +?> +
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ + 'class' => "btn btn-primary ", + 'value' => 'Отправить', + 'typeInput' => 'submit' + ]) + ->render(); + ?> +
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [ + 'class' => "btn btn-warning", + 'value' => 'Сбросить', + 'typeInput' => 'reset' + ]) + ->render(); + ?> +
+
+endForm(); diff --git a/kernel/templates/views/index_template b/kernel/templates/views/index_template new file mode 100644 index 0000000..c710ca6 --- /dev/null +++ b/kernel/templates/views/index_template @@ -0,0 +1,37 @@ + $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(); \ No newline at end of file diff --git a/kernel/templates/views/view_template b/kernel/templates/views/view_template new file mode 100644 index 0000000..1ce19c5 --- /dev/null +++ b/kernel/templates/views/view_template @@ -0,0 +1,25 @@ + ["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(); \ No newline at end of file