This commit is contained in:
Билай Станислав 2024-10-17 11:35:56 +03:00
parent 9af44ca95f
commit 5285acae12
28 changed files with 34 additions and 355 deletions

View File

@ -84,42 +84,14 @@ class ModuleShopController extends AdminController
public function actionView(int $id): void public function actionView(int $id): void
{ {
$module = ModuleShop::find($id);
$module = ModuleShop::find($id);
if (!$module) { if (!$module) {
throw new Exception("The module not found"); throw new Exception("The module not found");
} }
$this->cgView->render("view.php", ['module' => $module]); $this->cgView->render("view.php", ['module' => $module]);
} }
public function actionUpdate(int $id): void
{
$model = ModuleShop::find($id);
if (!$model) {
throw new Exception("The module not found");
}
$this->cgView->render("form.php", ['model' => $model]);
}
public function actionEdit(int $id): void
{
$module = ModuleShop::find($id);
if (!$module) {
throw new Exception("The module not found");
}
$moduleForm = new CreateModuleShopForm();
$moduleForm->load($_REQUEST);
if ($moduleForm->validate()) {
$module = $this->moduleShopService->update($moduleForm, $module);
if ($module) {
$this->redirect("/admin/module_shop/" . $module->id);
}
}
$this->redirect("/admin/module_shop/update/" . $id);
}
public function actionDelete(int $id): void public function actionDelete(int $id): void
{ {

View File

@ -22,7 +22,7 @@ class ModuleShop extends Model
protected $table = "module_shop"; protected $table = "module_shop";
protected $fillable = ['name', 'slug', 'version', 'description', 'author', 'status', 'path_to_archive', 'dependence']; protected $fillable = ['name', 'slug', 'version', 'description', 'author', 'status', 'dependence'];
public static function labels(): array public static function labels(): array
{ {
@ -33,7 +33,6 @@ class ModuleShop extends Model
'author' => 'Автор', 'author' => 'Автор',
'status' => 'Статус', 'status' => 'Статус',
'slug' => 'Slug', 'slug' => 'Slug',
'path_to_archive' => 'Путь к файлу модуля',
'dependence' => 'Зависимости', 'dependence' => 'Зависимости',
]; ];
} }

View File

@ -50,27 +50,4 @@ class ModuleShopService extends ModuleService
return false; return false;
} }
public function packModule($module): void
{
$tmpModuleDir = md5(time());
$authorSlug = Slug::createSlug($module->author);
$nameSlug = Slug::createSlug($module->name);
$tmpModuleDirFull = RESOURCES_DIR . '/tmp/modules/' . $tmpModuleDir . '/';
$fileHelper = new Files();
Debug::dd(APP_DIR . '/modules/' . $nameSlug);
$fileHelper->copy_folder(APP_DIR . '/modules/' . $nameSlug, $tmpModuleDirFull . 'app/');
// $fileHelper->copy_folder(KERNEL_APP_MODULES_DIR . '/' . $nameSlug, $tmpModuleDirFull . 'kernel/');
$fileHelper->pack(
$tmpModuleDirFull,
RESOURCES_DIR . '/module_shop/' .
$authorSlug . '/' .
$module->slug . '/' .
$module->version . '/' .
$nameSlug . '.itguild'
);
$fileHelper->recursiveRemoveDir($tmpModuleDirFull);
}
} }

View File

@ -1,16 +0,0 @@
<?php
namespace app\modules\module_shop\table\columns;
use Itguild\Tables\ActionColumn\ActionColumn;
class ModuleShopDeleteActionColumn extends ActionColumn
{
protected string $prefix = "/delete/";
public function fetch()
{
$link = $this->baseUrl . $this->prefix . $this->id;
return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
}
}

View File

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

@ -1,16 +0,0 @@
<?php
namespace app\modules\module_shop\table\columns;
use Itguild\Tables\ActionColumn\ActionColumn;
class ModuleShopPackActionColumn extends ActionColumn
{
protected string $prefix = "/pack/";
public function fetch()
{
$link = $this->baseUrl . $this->prefix . $this->id;
return " <a href='$link' class='btn btn-info'>Заархивировать</a> ";
}
}

View File

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

View File

@ -6,7 +6,7 @@
use app\modules\module_shop\models\ModuleShop; use app\modules\module_shop\models\ModuleShop;
$form = new \itguild\forms\ActiveForm(); $form = new \itguild\forms\ActiveForm();
$form->beginForm(isset($model) ? "/admin/module_shop/edit/" . $model->id : "/admin/module_shop", enctype: 'multipart/form-data'); $form->beginForm("/admin/module_shop", enctype: 'multipart/form-data');

View File

@ -7,11 +7,9 @@
use app\modules\module_shop\models\ModuleShop; use app\modules\module_shop\models\ModuleShop;
use Itguild\EloquentTable\EloquentDataProvider; use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable; use Itguild\EloquentTable\ListEloquentTable;
use kernel\IGTabel\action_column\DeleteActionColumn;
use kernel\IGTabel\action_column\ViewActionColumn;
use kernel\IGTabel\btn\PrimaryBtn; use kernel\IGTabel\btn\PrimaryBtn;
use kernel\models\Menu;
use kernel\modules\menu\table\columns\MenuDeleteActionColumn;
use kernel\modules\menu\table\columns\MenuEditActionColumn;
use kernel\modules\menu\table\columns\MenuViewActionColumn;
$table = new ListEloquentTable(new EloquentDataProvider(\app\modules\module_shop\models\ModuleShop::class, [ $table = new ListEloquentTable(new EloquentDataProvider(\app\modules\module_shop\models\ModuleShop::class, [
'currentPage' => $page_number, 'currentPage' => $page_number,
@ -29,8 +27,7 @@ $table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/module_shop/create")->fetch(); return PrimaryBtn::create("Создать", "/admin/module_shop/create")->fetch();
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
}); });
$table->addAction(\app\modules\module_shop\table\columns\ModuleShopViewActionColumn::class); $table->addAction(ViewActionColumn::class);
$table->addAction(\app\modules\module_shop\table\columns\ModuleShopEditActionColumn::class); $table->addAction(DeleteActionColumn::class);
$table->addAction(\app\modules\module_shop\table\columns\ModuleShopDeleteActionColumn::class);
$table->create(); $table->create();
$table->render(); $table->render();

View File

@ -18,7 +18,6 @@ $table = new ViewEloquentTable(new ViewJsonTableEloquentModel($module, [
])); ]));
$table->beforePrint(function () use ($module) { $table->beforePrint(function () use ($module) {
$btn = PrimaryBtn::create("Список", "/admin/module_shop")->fetch(); $btn = PrimaryBtn::create("Список", "/admin/module_shop")->fetch();
$btn .= SuccessBtn::create("Редактировать", "/admin/module_shop/update/" . $module->id)->fetch();
$btn .= DangerBtn::create("Удалить", "/admin/module_shop/delete/" . $module->id)->fetch(); $btn .= DangerBtn::create("Удалить", "/admin/module_shop/delete/" . $module->id)->fetch();
return $btn; return $btn;
}); });

View File

@ -8,10 +8,6 @@ use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable; use Itguild\EloquentTable\ListEloquentTable;
use kernel\app_modules\tag\models\Tag; use kernel\app_modules\tag\models\Tag;
use kernel\IGTabel\btn\PrimaryBtn; use kernel\IGTabel\btn\PrimaryBtn;
use kernel\models\Menu;
use kernel\modules\menu\table\columns\MenuDeleteActionColumn;
use kernel\modules\menu\table\columns\MenuEditActionColumn;
use kernel\modules\menu\table\columns\MenuViewActionColumn;
$table = new ListEloquentTable(new EloquentDataProvider(Tag::class, [ $table = new ListEloquentTable(new EloquentDataProvider(Tag::class, [
'currentPage' => $page_number, 'currentPage' => $page_number,

View File

@ -1,17 +0,0 @@
<?php
namespace kernel\modules\menu\table\columns;
use Itguild\Tables\ActionColumn\ActionColumn;
class MenuDeleteActionColumn extends ActionColumn
{
protected string $prefix = "/delete/";
public function fetch(): string
{
$link = $this->baseUrl . $this->prefix . $this->id;
return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
}
}

View File

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

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

View File

@ -6,11 +6,11 @@
use Itguild\EloquentTable\EloquentDataProvider; use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable; use Itguild\EloquentTable\ListEloquentTable;
use kernel\IGTabel\action_column\DeleteActionColumn;
use kernel\IGTabel\action_column\EditActionColumn;
use kernel\IGTabel\action_column\ViewActionColumn;
use kernel\IGTabel\btn\PrimaryBtn; use kernel\IGTabel\btn\PrimaryBtn;
use kernel\models\Menu; use kernel\models\Menu;
use kernel\modules\menu\table\columns\MenuDeleteActionColumn;
use kernel\modules\menu\table\columns\MenuEditActionColumn;
use kernel\modules\menu\table\columns\MenuViewActionColumn;
$table = new ListEloquentTable(new EloquentDataProvider(Menu::class, [ $table = new ListEloquentTable(new EloquentDataProvider(Menu::class, [
'currentPage' => $page_number, 'currentPage' => $page_number,
@ -28,8 +28,8 @@ $table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/settings/menu/create")->fetch(); return PrimaryBtn::create("Создать", "/admin/settings/menu/create")->fetch();
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
}); });
$table->addAction(MenuViewActionColumn::class); $table->addAction(ViewActionColumn::class);
$table->addAction(MenuEditActionColumn::class); $table->addAction(EditActionColumn::class);
$table->addAction(MenuDeleteActionColumn::class); $table->addAction(DeleteActionColumn::class);
$table->create(); $table->create();
$table->render(); $table->render();

View File

@ -1,16 +0,0 @@
<?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

@ -1,16 +0,0 @@
<?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

@ -1,18 +0,0 @@
<?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

@ -6,11 +6,11 @@
use Itguild\EloquentTable\EloquentDataProvider; use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable; use Itguild\EloquentTable\ListEloquentTable;
use kernel\IGTabel\action_column\DeleteActionColumn;
use kernel\IGTabel\action_column\EditActionColumn;
use kernel\IGTabel\action_column\ViewActionColumn;
use kernel\IGTabel\btn\PrimaryBtn; use kernel\IGTabel\btn\PrimaryBtn;
use kernel\modules\option\models\Option; use kernel\modules\option\models\Option;
use kernel\modules\option\table\columns\OptionDeleteActionColumn;
use kernel\modules\option\table\columns\OptionEditActionColumn;
use kernel\modules\option\table\columns\OptionViewActionColumn;
$table = new ListEloquentTable(new EloquentDataProvider(Option::class, [ $table = new ListEloquentTable(new EloquentDataProvider(Option::class, [
'current_page' => $page_number, 'current_page' => $page_number,
@ -31,8 +31,8 @@ $table->columns([
}] }]
]); ]);
$table->addAction(OptionViewActionColumn::class); $table->addAction(ViewActionColumn::class);
$table->addAction(OptionEditActionColumn::class); $table->addAction(EditActionColumn::class);
$table->addAction(OptionDeleteActionColumn::class); $table->addAction(DeleteActionColumn::class);
$table->create(); $table->create();
$table->render(); $table->render();

View File

@ -1,16 +0,0 @@
<?php
namespace kernel\modules\post\table\columns;
use Itguild\Tables\ActionColumn\ActionColumn;
class PostDeleteActionColumn extends ActionColumn
{
protected string $prefix = "/delete/";
public function fetch(): string
{
$link = $this->baseUrl . $this->prefix . $this->id;
return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
}
}

View File

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

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

View File

@ -5,14 +5,11 @@
* @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\post\table\columns\PostDeleteActionColumn;
use kernel\modules\post\table\columns\PostEditActionColumn;
use kernel\modules\post\table\columns\PostViewActionColumn;
use kernel\modules\user\models\User; use kernel\modules\user\models\User;
//use app\tables\columns\post\PostDeleteActionColumn;
//use app\tables\columns\post\PostEditActionColumn;
//use app\tables\columns\post\PostViewActionColumn;
use Itguild\EloquentTable\EloquentDataProvider; use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable; use Itguild\EloquentTable\ListEloquentTable;
use kernel\IGTabel\btn\PrimaryBtn; use kernel\IGTabel\btn\PrimaryBtn;
@ -46,8 +43,8 @@ $table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/post/create")->fetch(); return PrimaryBtn::create("Создать", "/admin/post/create")->fetch();
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
}); });
$table->addAction(PostViewActionColumn::class); $table->addAction(ViewActionColumn::class);
$table->addAction(PostEditActionColumn::class); $table->addAction(EditActionColumn::class);
$table->addAction(PostDeleteActionColumn::class); $table->addAction(DeleteActionColumn::class);
$table->create(); $table->create();
$table->render(); $table->render();

View File

@ -1,16 +0,0 @@
<?php
namespace kernel\modules\user\table\columns;
use Itguild\Tables\ActionColumn\ActionColumn;
class UserDeleteActionColumn extends ActionColumn
{
protected string $prefix = "/delete/";
public function fetch(): string
{
$link = $this->baseUrl . $this->prefix . $this->id;
return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
}
}

View File

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

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

View File

@ -7,11 +7,11 @@
use Itguild\EloquentTable\EloquentDataProvider; use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable; use Itguild\EloquentTable\ListEloquentTable;
use kernel\IGTabel\action_column\DeleteActionColumn;
use kernel\IGTabel\action_column\EditActionColumn;
use kernel\IGTabel\action_column\ViewActionColumn;
use kernel\IGTabel\btn\PrimaryBtn; use kernel\IGTabel\btn\PrimaryBtn;
use kernel\modules\user\models\User; use kernel\modules\user\models\User;
use kernel\modules\user\table\columns\UserDeleteActionColumn;
use kernel\modules\user\table\columns\UserEditActionColumn;
use kernel\modules\user\table\columns\UserViewActionColumn;
$table = new ListEloquentTable(new EloquentDataProvider(User::class, [ $table = new ListEloquentTable(new EloquentDataProvider(User::class, [
'currentPage' => $page_number, 'currentPage' => $page_number,
@ -45,8 +45,8 @@ $table->beforePrint(function () {
return PrimaryBtn::create("Создать", "/admin/user/create")->fetch(); return PrimaryBtn::create("Создать", "/admin/user/create")->fetch();
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
}); });
$table->addAction(UserViewActionColumn::class); $table->addAction(ViewActionColumn::class);
$table->addAction(UserEditActionColumn::class); $table->addAction(EditActionColumn::class);
$table->addAction(UserDeleteActionColumn::class); $table->addAction(DeleteActionColumn::class);
$table->create(); $table->create();
$table->render(); $table->render();

View File

@ -346,6 +346,9 @@ class ModuleService
$fileHelper->copy_folder(APP_DIR . '/modules/' . $moduleName, $tmpModuleDirFull . 'app/'); $fileHelper->copy_folder(APP_DIR . '/modules/' . $moduleName, $tmpModuleDirFull . 'app/');
$fileHelper->copy_folder(KERNEL_APP_MODULES_DIR . '/' . $moduleName, $tmpModuleDirFull . 'kernel/'); $fileHelper->copy_folder(KERNEL_APP_MODULES_DIR . '/' . $moduleName, $tmpModuleDirFull . 'kernel/');
if (!is_dir(RESOURCES_DIR . '/tmp/module')) {
mkdir(RESOURCES_DIR . '/tmp/modules', 0777, true);
}
$fileHelper->pack($tmpModuleDirFull, RESOURCES_DIR . '/tmp/modules/' . $moduleName . '.itguild'); $fileHelper->pack($tmpModuleDirFull, RESOURCES_DIR . '/tmp/modules/' . $moduleName . '.itguild');
$fileHelper->recursiveRemoveDir($tmpModuleDirFull); $fileHelper->recursiveRemoveDir($tmpModuleDirFull);