admin theme to ms
This commit is contained in:
parent
483fe35561
commit
219ca30608
@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\modules\module_shop\controllers;
|
||||||
|
|
||||||
|
use app\modules\module_shop\models\forms\CreateAdminThemeShopForm;
|
||||||
|
use app\modules\module_shop\services\ModuleShopService;
|
||||||
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
|
use kernel\AdminController;
|
||||||
|
use kernel\FileUpload;
|
||||||
|
use kernel\Flash;
|
||||||
|
use kernel\helpers\Debug;
|
||||||
|
use kernel\helpers\Files;
|
||||||
|
use ZipArchive;
|
||||||
|
|
||||||
|
class AdminThemeShopController extends AdminController
|
||||||
|
{
|
||||||
|
protected ModuleShopService $moduleShopService;
|
||||||
|
protected Files $files;
|
||||||
|
|
||||||
|
protected function init(): void
|
||||||
|
{
|
||||||
|
parent::init();
|
||||||
|
$this->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", "Ошибка добавления темы админ-панели: <br>" . $adminThemeShopForm->getErrorsStr());
|
||||||
|
$this->redirect("/admin/module_shop/admin_theme/create");
|
||||||
|
}
|
||||||
|
}
|
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
namespace app\modules\module_shop\controllers;
|
namespace app\modules\module_shop\controllers;
|
||||||
|
|
||||||
use app\modules\module_shop\models\forms\CreateModuleShopForm;
|
use app\modules\module_shop\models\forms\CreateKernelShopForm;
|
||||||
use app\modules\module_shop\models\ModuleShop;
|
|
||||||
use app\modules\module_shop\services\ModuleShopService;
|
use app\modules\module_shop\services\ModuleShopService;
|
||||||
use JetBrains\PhpStorm\NoReturn;
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
use kernel\AdminController;
|
use kernel\AdminController;
|
||||||
@ -11,7 +10,6 @@ use kernel\FileUpload;
|
|||||||
use kernel\Flash;
|
use kernel\Flash;
|
||||||
use kernel\helpers\Debug;
|
use kernel\helpers\Debug;
|
||||||
use kernel\helpers\Files;
|
use kernel\helpers\Files;
|
||||||
use kernel\services\ModuleService;
|
|
||||||
use ZipArchive;
|
use ZipArchive;
|
||||||
|
|
||||||
class KernelShopController extends AdminController
|
class KernelShopController extends AdminController
|
||||||
@ -37,18 +35,18 @@ class KernelShopController extends AdminController
|
|||||||
*/
|
*/
|
||||||
#[NoReturn] public function actionAdd(): void
|
#[NoReturn] public function actionAdd(): void
|
||||||
{
|
{
|
||||||
$moduleShopForm = new CreateModuleShopForm();
|
$kernelShopForm = new CreateKernelShopForm();
|
||||||
$moduleShopForm->load($_REQUEST);
|
$kernelShopForm->load($_REQUEST);
|
||||||
|
|
||||||
if (isset($_FILES['path_to_archive']) && $_FILES['path_to_archive']['error'] === UPLOAD_ERR_OK) {
|
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 = new FileUpload($_FILES['path_to_archive'], ['zip', 'rar', 'igk']);
|
||||||
$file->upload();
|
$file->upload();
|
||||||
$moduleShopForm->setItem('path_to_archive', $file->getUploadFile());
|
$kernelShopForm->setItem('path_to_archive', $file->getUploadFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
$tmpKernelDir = md5(time());
|
$tmpKernelDir = md5(time());
|
||||||
$zip = new ZipArchive;
|
$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 ($res === TRUE) {
|
||||||
if (!is_dir(RESOURCES_DIR . '/tmp/ms/')) {
|
if (!is_dir(RESOURCES_DIR . '/tmp/ms/')) {
|
||||||
mkdir(RESOURCES_DIR . '/tmp/ms/');
|
mkdir(RESOURCES_DIR . '/tmp/ms/');
|
||||||
@ -59,7 +57,7 @@ class KernelShopController extends AdminController
|
|||||||
|
|
||||||
if (file_exists($tmpModuleShopDirFull . "kernel/manifest.json")){
|
if (file_exists($tmpModuleShopDirFull . "kernel/manifest.json")){
|
||||||
$kernelInfo = $this->moduleShopService->getModuleInfo($tmpModuleShopDirFull . "kernel");
|
$kernelInfo = $this->moduleShopService->getModuleInfo($tmpModuleShopDirFull . "kernel");
|
||||||
$moduleShopForm->load($kernelInfo);
|
$kernelShopForm->load($kernelInfo);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new \Exception("Manifest.json file not found");
|
throw new \Exception("Manifest.json file not found");
|
||||||
@ -71,14 +69,14 @@ class KernelShopController extends AdminController
|
|||||||
throw new \Exception("zip not found");
|
throw new \Exception("zip not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($moduleShopForm->validate()) {
|
if ($kernelShopForm->validate()) {
|
||||||
$kernel = $this->moduleShopService->create($moduleShopForm);
|
$kernel = $this->moduleShopService->create($kernelShopForm);
|
||||||
if ($kernel) {
|
if ($kernel) {
|
||||||
Flash::setMessage("success", "Ядро добавлено.");
|
Flash::setMessage("success", "Ядро добавлено.");
|
||||||
$this->redirect("/admin/module_shop/view/" . $kernel->id);
|
$this->redirect("/admin/module_shop/view/" . $kernel->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Flash::setMessage("error", "Ошибка добавления ядра: <br>" . $moduleShopForm->getErrorsStr());
|
Flash::setMessage("error", "Ошибка добавления ядра: <br>" . $kernelShopForm->getErrorsStr());
|
||||||
$this->redirect("/admin/module_shop/kernel/create");
|
$this->redirect("/admin/module_shop/kernel/create");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,12 +7,10 @@ use app\modules\module_shop\models\ModuleShop;
|
|||||||
use app\modules\module_shop\services\ModuleShopService;
|
use app\modules\module_shop\services\ModuleShopService;
|
||||||
use JetBrains\PhpStorm\NoReturn;
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
use kernel\AdminController;
|
use kernel\AdminController;
|
||||||
use kernel\app_modules\tag\services\TagService;
|
|
||||||
use kernel\FileUpload;
|
use kernel\FileUpload;
|
||||||
use kernel\Flash;
|
use kernel\Flash;
|
||||||
use kernel\helpers\Debug;
|
use kernel\helpers\Debug;
|
||||||
use kernel\helpers\Files;
|
use kernel\helpers\Files;
|
||||||
use kernel\services\ModuleService;
|
|
||||||
use ZipArchive;
|
use ZipArchive;
|
||||||
|
|
||||||
class ModuleShopController extends AdminController
|
class ModuleShopController extends AdminController
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\modules\module_shop\models\forms;
|
||||||
|
|
||||||
|
use kernel\FormModel;
|
||||||
|
|
||||||
|
class CreateAdminThemeShopForm extends FormModel
|
||||||
|
{
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => 'required|min-str-len:3',
|
||||||
|
'version' => 'required',
|
||||||
|
'description' => '',
|
||||||
|
'author' => 'required',
|
||||||
|
'status' => 'required',
|
||||||
|
'slug' => 'required',
|
||||||
|
'type' => 'required',
|
||||||
|
'path_to_archive' => 'required',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\modules\module_shop\models\forms;
|
||||||
|
|
||||||
|
use kernel\FormModel;
|
||||||
|
|
||||||
|
class CreateKernelShopForm extends FormModel
|
||||||
|
{
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => 'required',
|
||||||
|
'version' => 'required',
|
||||||
|
'author' => 'required',
|
||||||
|
'status' => 'required',
|
||||||
|
'slug' => 'required',
|
||||||
|
'type' => 'required',
|
||||||
|
'description' => '',
|
||||||
|
'path_to_archive' => 'required',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -8,26 +8,15 @@ class CreateModuleShopForm extends FormModel
|
|||||||
{
|
{
|
||||||
public function rules(): array
|
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 [
|
return [
|
||||||
'name' => '',
|
'name' => 'required|min-str-len:3',
|
||||||
'version' => '',
|
'version' => 'required',
|
||||||
'description' => '',
|
'description' => 'required|min-str-len:10',
|
||||||
'author' => '',
|
'author' => 'required',
|
||||||
'status' => '',
|
'status' => 'required',
|
||||||
'slug' => '',
|
'slug' => 'required',
|
||||||
'type' => '',
|
'type' => 'required',
|
||||||
'path_to_archive' => '',
|
'path_to_archive' => 'required',
|
||||||
'dependence' => '',
|
'dependence' => '',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -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->get('/create', [\app\modules\module_shop\controllers\KernelShopController::class, 'actionCreate']);
|
||||||
App::$collector->post("/", [\app\modules\module_shop\controllers\KernelShopController::class, 'actionAdd']);
|
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']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
51
app/modules/module_shop/views/admin_theme/form.php
Normal file
51
app/modules/module_shop/views/admin_theme/form.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var ModuleShop $model
|
||||||
|
*/
|
||||||
|
|
||||||
|
use app\modules\module_shop\models\ModuleShop;
|
||||||
|
|
||||||
|
$form = new \itguild\forms\ActiveForm();
|
||||||
|
$form->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();
|
||||||
|
|
||||||
|
?>
|
||||||
|
<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();
|
@ -24,8 +24,9 @@ $table->columns([
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
$table->beforePrint(function () {
|
$table->beforePrint(function () {
|
||||||
$btn = PrimaryBtn::create("Добавить модуль", "/admin/module_shop/module/create", width: '200px')->fetch();
|
$btn = PrimaryBtn::create("Добавить модуль", "/admin/module_shop/module/create", width: '250px')->fetch();
|
||||||
$btn .= PrimaryBtn::create("Добавить ядро", "/admin/module_shop/kernel/create", '200px')->fetch();
|
$btn .= PrimaryBtn::create("Добавить ядро", "/admin/module_shop/kernel/create", '250px')->fetch();
|
||||||
|
$btn .= PrimaryBtn::create("Добавить тему админ-панели", "/admin/module_shop/admin_theme/create", '250px')->fetch();
|
||||||
return $btn;
|
return $btn;
|
||||||
});
|
});
|
||||||
$table->addAction(ViewActionColumn::class);
|
$table->addAction(ViewActionColumn::class);
|
||||||
|
@ -12,10 +12,10 @@ $form->beginForm("/admin/module_shop/kernel", enctype: 'multipart/form-data');
|
|||||||
|
|
||||||
$form->field(class: \itguild\forms\inputs\File::class, name: "path_to_archive", params: [
|
$form->field(class: \itguild\forms\inputs\File::class, name: "path_to_archive", params: [
|
||||||
'class' => "form-control",
|
'class' => "form-control",
|
||||||
'placeholder' => 'Путь к файлу модуля',
|
'placeholder' => 'Путь к ядра',
|
||||||
'value' => $model->path_to_archive ?? ''
|
'value' => $model->path_to_archive ?? ''
|
||||||
])
|
])
|
||||||
->setLabel("Путь к файлу модуля")
|
->setLabel("Путь к файлу ядра")
|
||||||
->render();
|
->render();
|
||||||
|
|
||||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "status", params: [
|
$form->field(class: \itguild\forms\inputs\Select::class, name: "status", params: [
|
||||||
|
@ -8,7 +8,7 @@ class PrimaryBtn
|
|||||||
|
|
||||||
public function __construct(string $title, string $url, $width)
|
public function __construct(string $title, string $url, $width)
|
||||||
{
|
{
|
||||||
$this->btn = "<a class='btn btn-primary' href='$url' style='margin: 3px; width: '$width >$title</a>";
|
$this->btn = "<a class='btn btn-primary' href='$url' style='margin: 3px; width: $width;' >$title</a>";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetch(): string
|
public function fetch(): string
|
||||||
|
Loading…
Reference in New Issue
Block a user