diff --git a/app/modules/module_shop/controllers/AdminThemeShopController.php b/app/modules/module_shop/controllers/AdminThemeShopController.php
new file mode 100644
index 0000000..f0065b2
--- /dev/null
+++ b/app/modules/module_shop/controllers/AdminThemeShopController.php
@@ -0,0 +1,84 @@
+cgView->viewPath = APP_DIR . "/modules/module_shop/views/admin_theme/";
+ $this->moduleShopService = new ModuleShopService();
+ $this->files = new Files();
+ }
+
+ public function actionCreate(): void
+ {
+ $this->cgView->render("form.php");
+ }
+
+ /**
+ * @throws \Exception
+ */
+ #[NoReturn] public function actionAdd(): void
+ {
+ $adminThemeShopForm = new CreateAdminThemeShopForm();
+ $adminThemeShopForm->load($_REQUEST);
+
+ if (isset($_FILES['path_to_archive']) && $_FILES['path_to_archive']['error'] === UPLOAD_ERR_OK) {
+ $file = new FileUpload($_FILES['path_to_archive'], ['zip', 'rar', 'igt']);
+ $file->upload();
+ $adminThemeShopForm->setItem('path_to_archive', $file->getUploadFile());
+ }
+
+ $tmpThemeDir = md5(time());
+ $zip = new ZipArchive;
+ $res = $zip->open(ROOT_DIR . $adminThemeShopForm->getItem('path_to_archive'));
+ if ($res === TRUE) {
+ if (!is_dir(RESOURCES_DIR . '/tmp/ms/')) {
+ $oldMask = umask(0);
+ mkdir(RESOURCES_DIR . '/tmp/ms/', 0775, true);
+ umask($oldMask);
+ }
+ $tmpModuleShopDirFull = RESOURCES_DIR . '/tmp/ms/' . $tmpThemeDir . "/";
+ $zip->extractTo($tmpModuleShopDirFull);
+ $zip->close();
+
+ if (file_exists($tmpModuleShopDirFull . "meta/manifest.json")){
+ $themeInfo = $this->moduleShopService->getModuleInfo($tmpModuleShopDirFull . "meta");
+ $adminThemeShopForm->load($themeInfo);
+ }
+ else {
+ throw new \Exception("Manifest.json file not found");
+ }
+ $this->files->recursiveRemoveDir($tmpModuleShopDirFull);
+
+ }
+ else {
+ throw new \Exception("zip not found");
+ }
+
+ if ($adminThemeShopForm->validate()) {
+ $theme = $this->moduleShopService->create($adminThemeShopForm);
+ if ($theme) {
+ Flash::setMessage("success", "Тема админ-панели добавлена.");
+ $this->redirect("/admin/module_shop/view/" . $theme->id);
+ }
+ }
+ Flash::setMessage("error", "Ошибка добавления темы админ-панели:
" . $adminThemeShopForm->getErrorsStr());
+ $this->redirect("/admin/module_shop/admin_theme/create");
+ }
+}
\ No newline at end of file
diff --git a/app/modules/module_shop/controllers/KernelShopController.php b/app/modules/module_shop/controllers/KernelShopController.php
index 6142226..78e0d65 100644
--- a/app/modules/module_shop/controllers/KernelShopController.php
+++ b/app/modules/module_shop/controllers/KernelShopController.php
@@ -2,8 +2,7 @@
namespace app\modules\module_shop\controllers;
-use app\modules\module_shop\models\forms\CreateModuleShopForm;
-use app\modules\module_shop\models\ModuleShop;
+use app\modules\module_shop\models\forms\CreateKernelShopForm;
use app\modules\module_shop\services\ModuleShopService;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
@@ -11,7 +10,6 @@ use kernel\FileUpload;
use kernel\Flash;
use kernel\helpers\Debug;
use kernel\helpers\Files;
-use kernel\services\ModuleService;
use ZipArchive;
class KernelShopController extends AdminController
@@ -37,18 +35,18 @@ class KernelShopController extends AdminController
*/
#[NoReturn] public function actionAdd(): void
{
- $moduleShopForm = new CreateModuleShopForm();
- $moduleShopForm->load($_REQUEST);
+ $kernelShopForm = new CreateKernelShopForm();
+ $kernelShopForm->load($_REQUEST);
if (isset($_FILES['path_to_archive']) && $_FILES['path_to_archive']['error'] === UPLOAD_ERR_OK) {
$file = new FileUpload($_FILES['path_to_archive'], ['zip', 'rar', 'igk']);
$file->upload();
- $moduleShopForm->setItem('path_to_archive', $file->getUploadFile());
+ $kernelShopForm->setItem('path_to_archive', $file->getUploadFile());
}
$tmpKernelDir = md5(time());
$zip = new ZipArchive;
- $res = $zip->open(ROOT_DIR . $moduleShopForm->getItem('path_to_archive'));
+ $res = $zip->open(ROOT_DIR . $kernelShopForm->getItem('path_to_archive'));
if ($res === TRUE) {
if (!is_dir(RESOURCES_DIR . '/tmp/ms/')) {
mkdir(RESOURCES_DIR . '/tmp/ms/');
@@ -59,7 +57,7 @@ class KernelShopController extends AdminController
if (file_exists($tmpModuleShopDirFull . "kernel/manifest.json")){
$kernelInfo = $this->moduleShopService->getModuleInfo($tmpModuleShopDirFull . "kernel");
- $moduleShopForm->load($kernelInfo);
+ $kernelShopForm->load($kernelInfo);
}
else {
throw new \Exception("Manifest.json file not found");
@@ -71,14 +69,14 @@ class KernelShopController extends AdminController
throw new \Exception("zip not found");
}
- if ($moduleShopForm->validate()) {
- $kernel = $this->moduleShopService->create($moduleShopForm);
+ if ($kernelShopForm->validate()) {
+ $kernel = $this->moduleShopService->create($kernelShopForm);
if ($kernel) {
Flash::setMessage("success", "Ядро добавлено.");
$this->redirect("/admin/module_shop/view/" . $kernel->id);
}
}
- Flash::setMessage("error", "Ошибка добавления ядра:
" . $moduleShopForm->getErrorsStr());
+ Flash::setMessage("error", "Ошибка добавления ядра:
" . $kernelShopForm->getErrorsStr());
$this->redirect("/admin/module_shop/kernel/create");
}
}
\ No newline at end of file
diff --git a/app/modules/module_shop/controllers/ModuleShopController.php b/app/modules/module_shop/controllers/ModuleShopController.php
index 02d48aa..9d92e6e 100644
--- a/app/modules/module_shop/controllers/ModuleShopController.php
+++ b/app/modules/module_shop/controllers/ModuleShopController.php
@@ -7,12 +7,10 @@ use app\modules\module_shop\models\ModuleShop;
use app\modules\module_shop\services\ModuleShopService;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
-use kernel\app_modules\tag\services\TagService;
use kernel\FileUpload;
use kernel\Flash;
use kernel\helpers\Debug;
use kernel\helpers\Files;
-use kernel\services\ModuleService;
use ZipArchive;
class ModuleShopController extends AdminController
diff --git a/app/modules/module_shop/models/forms/CreateAdminThemeShopForm.php b/app/modules/module_shop/models/forms/CreateAdminThemeShopForm.php
new file mode 100644
index 0000000..b41221c
--- /dev/null
+++ b/app/modules/module_shop/models/forms/CreateAdminThemeShopForm.php
@@ -0,0 +1,22 @@
+ 'required|min-str-len:3',
+ 'version' => 'required',
+ 'description' => '',
+ 'author' => 'required',
+ 'status' => 'required',
+ 'slug' => 'required',
+ 'type' => 'required',
+ 'path_to_archive' => 'required',
+ ];
+ }
+}
\ No newline at end of file
diff --git a/app/modules/module_shop/models/forms/CreateKernelShopForm.php b/app/modules/module_shop/models/forms/CreateKernelShopForm.php
new file mode 100644
index 0000000..3505bcf
--- /dev/null
+++ b/app/modules/module_shop/models/forms/CreateKernelShopForm.php
@@ -0,0 +1,22 @@
+ 'required',
+ 'version' => 'required',
+ 'author' => 'required',
+ 'status' => 'required',
+ 'slug' => 'required',
+ 'type' => 'required',
+ 'description' => '',
+ 'path_to_archive' => 'required',
+ ];
+ }
+}
\ No newline at end of file
diff --git a/app/modules/module_shop/models/forms/CreateModuleShopForm.php b/app/modules/module_shop/models/forms/CreateModuleShopForm.php
index 2c1d5db..0b7cab5 100644
--- a/app/modules/module_shop/models/forms/CreateModuleShopForm.php
+++ b/app/modules/module_shop/models/forms/CreateModuleShopForm.php
@@ -8,26 +8,15 @@ class CreateModuleShopForm extends FormModel
{
public function rules(): array
{
-// return [
-// 'name' => 'required|min-str-len:3',
-// 'version' => 'required',
-// 'description' => 'required|min-str-len:10',
-// 'author' => 'required',
-// 'status' => 'required',
-// 'slug' => 'required',
-// 'type' => 'required',
-// 'path_to_archive' => 'required',
-// 'dependence' => '',
-// ];
return [
- 'name' => '',
- 'version' => '',
- 'description' => '',
- 'author' => '',
- 'status' => '',
- 'slug' => '',
- 'type' => '',
- 'path_to_archive' => '',
+ 'name' => 'required|min-str-len:3',
+ 'version' => 'required',
+ 'description' => 'required|min-str-len:10',
+ 'author' => 'required',
+ 'status' => 'required',
+ 'slug' => 'required',
+ 'type' => 'required',
+ 'path_to_archive' => 'required',
'dependence' => '',
];
}
diff --git a/app/modules/module_shop/routs/ms.php b/app/modules/module_shop/routs/ms.php
index c97c2c9..809c66b 100644
--- a/app/modules/module_shop/routs/ms.php
+++ b/app/modules/module_shop/routs/ms.php
@@ -23,6 +23,10 @@ App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router
App::$collector->get('/create', [\app\modules\module_shop\controllers\KernelShopController::class, 'actionCreate']);
App::$collector->post("/", [\app\modules\module_shop\controllers\KernelShopController::class, 'actionAdd']);
});
+ App::$collector->group(["prefix" => "admin_theme"], function (CgRouteCollector $router) {
+ App::$collector->get('/create', [\app\modules\module_shop\controllers\AdminThemeShopController::class, 'actionCreate']);
+ App::$collector->post("/", [\app\modules\module_shop\controllers\AdminThemeShopController::class, 'actionAdd']);
+ });
});
});
diff --git a/app/modules/module_shop/views/admin_theme/form.php b/app/modules/module_shop/views/admin_theme/form.php
new file mode 100644
index 0000000..3c02932
--- /dev/null
+++ b/app/modules/module_shop/views/admin_theme/form.php
@@ -0,0 +1,51 @@
+beginForm("/admin/module_shop/admin_theme", enctype: 'multipart/form-data');
+
+$form->field(class: \itguild\forms\inputs\File::class, name: "path_to_archive", params: [
+ 'class' => "form-control",
+ 'placeholder' => 'Путь к файлу темы админ-панели',
+ 'value' => $model->path_to_archive ?? ''
+])
+ ->setLabel("Путь к файлу темы админ-панели")
+ ->render();
+
+$form->field(class: \itguild\forms\inputs\Select::class, name: "status", params: [
+ 'class' => "form-control",
+ 'value' => $model->status ?? ''
+])
+ ->setLabel("Статус")
+ ->setOptions(ModuleShop::getStatus())
+ ->render();
+
+?>
+