diff --git a/app/modules/module_shop/controllers/ThemeShopController.php b/app/modules/module_shop/controllers/ThemeShopController.php new file mode 100644 index 0000000..4ec7325 --- /dev/null +++ b/app/modules/module_shop/controllers/ThemeShopController.php @@ -0,0 +1,84 @@ +cgView->viewPath = APP_DIR . "/modules/module_shop/views/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 + { + $themeShopForm = new CreateThemeShopForm(); + $themeShopForm->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(); + $themeShopForm->setItem('path_to_archive', $file->getUploadFile()); + } + + $tmpThemeDir = md5(time()); + $zip = new ZipArchive; + $res = $zip->open(ROOT_DIR . $themeShopForm->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"); + $themeShopForm->load($themeInfo); + } + else { + throw new \Exception("Manifest.json file not found"); + } + $this->files->recursiveRemoveDir($tmpModuleShopDirFull); + + } + else { + throw new \Exception("zip not found"); + } + + if ($themeShopForm->validate()) { + $theme = $this->moduleShopService->create($themeShopForm); + if ($theme) { + Flash::setMessage("success", "Тема сайта добавлена."); + $this->redirect("/admin/module_shop/view/" . $theme->id); + } + } + Flash::setMessage("error", "Ошибка добавления темы сайта:
" . $themeShopForm->getErrorsStr()); + $this->redirect("/admin/module_shop/theme/create"); + } +} \ No newline at end of file diff --git a/app/modules/module_shop/models/forms/CreateThemeShopForm.php b/app/modules/module_shop/models/forms/CreateThemeShopForm.php new file mode 100644 index 0000000..1b478e3 --- /dev/null +++ b/app/modules/module_shop/models/forms/CreateThemeShopForm.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/views/theme/form.php b/app/modules/module_shop/views/theme/form.php new file mode 100644 index 0000000..ad51235 --- /dev/null +++ b/app/modules/module_shop/views/theme/form.php @@ -0,0 +1,51 @@ +beginForm("/admin/module_shop/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(); + +?> +
+
+ 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/bootstrap/db.php b/bootstrap/db.php old mode 100644 new mode 100755 diff --git a/bootstrap/header.php b/bootstrap/header.php old mode 100644 new mode 100755 diff --git a/bootstrap/secure.php b/bootstrap/secure.php old mode 100644 new mode 100755 diff --git a/kernel/AdminController.php b/kernel/AdminController.php old mode 100644 new mode 100755 diff --git a/kernel/App.php b/kernel/App.php old mode 100644 new mode 100755 diff --git a/kernel/CgRouteCollector.php b/kernel/CgRouteCollector.php old mode 100644 new mode 100755 diff --git a/kernel/CgView.php b/kernel/CgView.php old mode 100644 new mode 100755 diff --git a/kernel/Controller.php b/kernel/Controller.php old mode 100644 new mode 100755 diff --git a/kernel/Database.php b/kernel/Database.php old mode 100644 new mode 100755 diff --git a/kernel/EntityRelation.php b/kernel/EntityRelation.php old mode 100644 new mode 100755 diff --git a/kernel/FileUpload.php b/kernel/FileUpload.php old mode 100644 new mode 100755 index 7a1705b..a61893c --- a/kernel/FileUpload.php +++ b/kernel/FileUpload.php @@ -36,7 +36,9 @@ class FileUpload $newFileName = md5(time() . $this->fileName) . '.' . $this->fileExtension; if (in_array($this->fileExtension, $this->allowedFileExtensions)) { $this->uploadDir = $uploadDir . mb_substr($newFileName, 0, 2) . '/' . mb_substr($newFileName, 2, 2) . '/'; - mkdir(ROOT_DIR . $this->uploadDir, 0777, true); + $oldMask = umask(0); + mkdir(ROOT_DIR . $this->uploadDir, 0775, true); + umask($oldMask); $uploadFileDir = ROOT_DIR . $this->uploadDir; $this->destPath = $uploadFileDir . $newFileName; $this->uploadFile = $this->uploadDir . $newFileName; @@ -49,7 +51,9 @@ class FileUpload } else { if (in_array($this->fileExtension, $this->allowedFileExtensions)) { $this->uploadDir = $uploadDir; - mkdir(ROOT_DIR . $this->uploadDir, 0777, true); + $oldMask = umask(0); + mkdir(ROOT_DIR . $this->uploadDir, 0775, true); + umask($oldMask); $uploadFileDir = ROOT_DIR . $this->uploadDir; $this->destPath = $uploadFileDir . $this->fileName; $this->uploadFile = $this->uploadDir . $this->fileName; diff --git a/kernel/Flash.php b/kernel/Flash.php old mode 100644 new mode 100755 diff --git a/kernel/FormModel.php b/kernel/FormModel.php old mode 100644 new mode 100755 diff --git a/kernel/Header.php b/kernel/Header.php old mode 100644 new mode 100755 diff --git a/kernel/IGTabel/action_column/DeleteActionColumn.php b/kernel/IGTabel/action_column/DeleteActionColumn.php old mode 100644 new mode 100755 diff --git a/kernel/IGTabel/action_column/EditActionColumn.php b/kernel/IGTabel/action_column/EditActionColumn.php old mode 100644 new mode 100755 diff --git a/kernel/IGTabel/action_column/InstallActionColumn.php b/kernel/IGTabel/action_column/InstallActionColumn.php old mode 100644 new mode 100755 diff --git a/kernel/IGTabel/action_column/ViewActionColumn.php b/kernel/IGTabel/action_column/ViewActionColumn.php old mode 100644 new mode 100755 diff --git a/kernel/IGTabel/btn/DangerBtn.php b/kernel/IGTabel/btn/DangerBtn.php old mode 100644 new mode 100755 diff --git a/kernel/IGTabel/btn/PrimaryBtn.php b/kernel/IGTabel/btn/PrimaryBtn.php old mode 100644 new mode 100755 index 2abe09e..b389401 --- a/kernel/IGTabel/btn/PrimaryBtn.php +++ b/kernel/IGTabel/btn/PrimaryBtn.php @@ -8,7 +8,7 @@ class PrimaryBtn public function __construct(string $title, string $url, $width) { - $this->btn = "$title"; + $this->btn = "$title"; } public function fetch(): string diff --git a/kernel/IGTabel/btn/SuccessBtn.php b/kernel/IGTabel/btn/SuccessBtn.php old mode 100644 new mode 100755 diff --git a/kernel/Mailing.php b/kernel/Mailing.php old mode 100644 new mode 100755 diff --git a/kernel/Middleware.php b/kernel/Middleware.php old mode 100644 new mode 100755 diff --git a/kernel/Module.php b/kernel/Module.php old mode 100644 new mode 100755 diff --git a/kernel/Request.php b/kernel/Request.php old mode 100644 new mode 100755 diff --git a/kernel/ResponseType.php b/kernel/ResponseType.php old mode 100644 new mode 100755 diff --git a/kernel/RestController.php b/kernel/RestController.php old mode 100644 new mode 100755 index 0da92ff..2d7596d --- a/kernel/RestController.php +++ b/kernel/RestController.php @@ -94,7 +94,9 @@ class RestController $model = $this->model->where('id', $id)->first(); foreach ($model->getFillable() as $item){ - $model->{$item} = $data[$item] ?? null; + if (!empty($data[$item])){ + $model->{$item} = $data[$item] ?? null; + } } $model->save(); diff --git a/kernel/Widget.php b/kernel/Widget.php old mode 100644 new mode 100755 diff --git a/kernel/admin_themes/default/layout/login.php b/kernel/admin_themes/default/layout/login.php old mode 100644 new mode 100755 diff --git a/kernel/admin_themes/default/layout/main.php b/kernel/admin_themes/default/layout/main.php old mode 100644 new mode 100755 index db00106..98be7fb --- a/kernel/admin_themes/default/layout/main.php +++ b/kernel/admin_themes/default/layout/main.php @@ -26,10 +26,13 @@
-
- - -
+
+ + +
- +
diff --git a/kernel/admin_themes/default/manifest.json b/kernel/admin_themes/default/manifest.json old mode 100644 new mode 100755 diff --git a/kernel/admin_themes/simple/layout/main.php b/kernel/admin_themes/simple/layout/main.php old mode 100644 new mode 100755 diff --git a/kernel/admin_themes/simple/manifest.json b/kernel/admin_themes/simple/manifest.json old mode 100644 new mode 100755 diff --git a/kernel/console/CgMigrationCreator.php b/kernel/console/CgMigrationCreator.php old mode 100644 new mode 100755 diff --git a/kernel/console/ConsoleApp.php b/kernel/console/ConsoleApp.php old mode 100644 new mode 100755 diff --git a/kernel/console/ConsoleController.php b/kernel/console/ConsoleController.php old mode 100644 new mode 100755 diff --git a/kernel/console/Out.php b/kernel/console/Out.php old mode 100644 new mode 100755 diff --git a/kernel/console/controllers/AdminConsoleController.php b/kernel/console/controllers/AdminConsoleController.php old mode 100644 new mode 100755 diff --git a/kernel/console/controllers/AdminThemeController.php b/kernel/console/controllers/AdminThemeController.php old mode 100644 new mode 100755 index 2fc1739..d33d44b --- a/kernel/console/controllers/AdminThemeController.php +++ b/kernel/console/controllers/AdminThemeController.php @@ -18,31 +18,15 @@ class AdminThemeController extends ConsoleController throw new \Exception('Missing admin theme path "--path" specified'); } - $zip = new ZipArchive; - $tmpThemeDir = md5(time()); - $res = $zip->open(ROOT_DIR . $this->argv['path']); - if ($res === TRUE) { - $tmpThemeDirFull = RESOURCES_DIR . '/tmp/ad/' . $tmpThemeDir . "/"; - $zip->extractTo($tmpThemeDirFull); - $zip->close(); - $this->out->r('Архив распакован', 'green'); + if (file_exists(ROOT_DIR . $this->argv['path'])) { + $adminThemeService = new AdminThemeService(); + if ($adminThemeService->install($this->argv['path'])) { + $this->out->r("Тема админ-панели установлена", 'green'); + } else { + $this->out->r("Ошибка установки темы админ-панели", 'red'); + } } else { - $this->out->r('Message: Ошибка чтения архива', 'red'); - } - - if (file_exists($tmpThemeDirFull . "meta/manifest.json")){ - $manifestJson = getConst(file_get_contents($tmpThemeDirFull . "meta/manifest.json")); - $manifest = Manifest::getWithVars($manifestJson); - $this->out->r('manifest.json инициализирован', 'green'); - - $fileHelper = new Files(); - $fileHelper->copy_folder($tmpThemeDirFull . "meta", $manifest['theme_path']); - $fileHelper->copy_folder($tmpThemeDirFull . "resources", $manifest['resource_path']); - - $this->out->r("Удаляем временные файлы", 'green'); - $fileHelper->recursiveRemoveDir($tmpThemeDirFull); - - $this->out->r("Тема " . $manifest['name'] . " установлена", 'green'); + $this->out->r("Тема админ-панели не найдена", 'red'); } } @@ -53,17 +37,11 @@ class AdminThemeController extends ConsoleController } if (file_exists(ROOT_DIR . $this->argv['path'])) { - $themeName = basename($this->argv['path']); - $active_admin_theme = Option::where("key", "active_admin_theme")->first(); - if ($active_admin_theme->value === ROOT_DIR . $this->argv['path']) { - $this->out->r("Меняем тему на базовую", 'green'); - $adminThemeService = new AdminThemeService(); - $adminThemeService->setActiveAdminTheme(KERNEL_ADMIN_THEMES_DIR . '/default'); - $this->out->r("Тема изменена", 'green'); - } - $fileHelper = new Files(); - $fileHelper->recursiveRemoveDir(ROOT_DIR . $this->argv['path']); - $fileHelper->recursiveRemoveDir(RESOURCES_DIR . '/' . $themeName); + $adminThemeService = new AdminThemeService(); + $adminThemeService->uninstall($this->argv['path']); + + + $this->out->r("Тема удалена", 'green'); } else { @@ -71,4 +49,22 @@ class AdminThemeController extends ConsoleController } } + /** + * @throws \Exception + */ + public function actionPackTheme(): void + { + if (!isset($this->argv['path'])) { + throw new \Exception('Missing admin theme path "--path" specified'); + } + + if (file_exists(ROOT_DIR . $this->argv['path'])) { + $adminThemeService = new AdminThemeService(); + $adminThemeService->pack($this->argv['path']); + $this->out->r("Тема админ-панели заархивирована", 'green'); + } else { + $this->out->r("Тема админ-панели не найдена", 'red'); + } + } + } \ No newline at end of file diff --git a/kernel/console/controllers/KernelController.php b/kernel/console/controllers/KernelController.php old mode 100644 new mode 100755 diff --git a/kernel/console/controllers/MainController.php b/kernel/console/controllers/MainController.php old mode 100644 new mode 100755 diff --git a/kernel/console/controllers/MigrationController.php b/kernel/console/controllers/MigrationController.php old mode 100644 new mode 100755 diff --git a/kernel/console/controllers/ModuleController.php b/kernel/console/controllers/ModuleController.php old mode 100644 new mode 100755 diff --git a/kernel/console/controllers/SecureController.php b/kernel/console/controllers/SecureController.php old mode 100644 new mode 100755 diff --git a/kernel/console/migrations/stubs/blank.stub b/kernel/console/migrations/stubs/blank.stub old mode 100644 new mode 100755 diff --git a/kernel/console/migrations/stubs/create.stub b/kernel/console/migrations/stubs/create.stub old mode 100644 new mode 100755 diff --git a/kernel/console/migrations/stubs/migration.create.stub b/kernel/console/migrations/stubs/migration.create.stub old mode 100644 new mode 100755 diff --git a/kernel/console/migrations/stubs/migration.stub b/kernel/console/migrations/stubs/migration.stub old mode 100644 new mode 100755 diff --git a/kernel/console/migrations/stubs/migration.update.stub b/kernel/console/migrations/stubs/migration.update.stub old mode 100644 new mode 100755 diff --git a/kernel/console/migrations/stubs/update.stub b/kernel/console/migrations/stubs/update.stub old mode 100644 new mode 100755 diff --git a/kernel/console/routs/cli.php b/kernel/console/routs/cli.php old mode 100644 new mode 100755 index d0f1032..4676cc7 --- a/kernel/console/routs/cli.php +++ b/kernel/console/routs/cli.php @@ -35,6 +35,10 @@ App::$collector->group(["prefix" => "admin-theme"], callback: function (RouteCol [\kernel\console\controllers\AdminThemeController::class, 'actionUninstallTheme'], additionalInfo: ['description' => 'Удалить тему админ-панели', 'params' => ['--path' => 'Путь к удаляемой теме']] ); + App::$collector->console('pack', + [\kernel\console\controllers\AdminThemeController::class, 'actionPackTheme'], + additionalInfo: ['description' => 'Заархивировать тему админ-панели', 'params' => ['--path' => 'Путь к теме, которую нужно заархивировать']] + ); }); App::$collector->group(["prefix" => "secure"], callback: function (RouteCollector $router){ diff --git a/kernel/controllers/ModuleController.php b/kernel/controllers/ModuleController.php old mode 100644 new mode 100755 diff --git a/kernel/filters/BootstrapSelectFilter.php b/kernel/filters/BootstrapSelectFilter.php new file mode 100755 index 0000000..86daceb --- /dev/null +++ b/kernel/filters/BootstrapSelectFilter.php @@ -0,0 +1,23 @@ +name, [ + 'class' => 'form-control', + 'options' => $this->params['options'], + 'value' => $this->value, + 'prompt' => $this->params['prompt'] ?? null, + ]); + + return "" . $select->create()->fetch() . ""; + } +} \ No newline at end of file diff --git a/kernel/filters/BootstrapTextFilter.php b/kernel/filters/BootstrapTextFilter.php new file mode 100755 index 0000000..32aec8b --- /dev/null +++ b/kernel/filters/BootstrapTextFilter.php @@ -0,0 +1,21 @@ +name, [ + 'value' => $this->value, + 'class' => "form-control" + ]); + + return "" . $textInput->create()->fetch() . ""; + + } +} \ No newline at end of file diff --git a/kernel/helpers/Debug.php b/kernel/helpers/Debug.php old mode 100644 new mode 100755 diff --git a/kernel/helpers/Files.php b/kernel/helpers/Files.php old mode 100644 new mode 100755 diff --git a/kernel/helpers/Html.php b/kernel/helpers/Html.php old mode 100644 new mode 100755 diff --git a/kernel/helpers/Manifest.php b/kernel/helpers/Manifest.php old mode 100644 new mode 100755 diff --git a/kernel/helpers/RESTClient.php b/kernel/helpers/RESTClient.php old mode 100644 new mode 100755 diff --git a/kernel/helpers/SMTP.php b/kernel/helpers/SMTP.php old mode 100644 new mode 100755 diff --git a/kernel/helpers/Slug.php b/kernel/helpers/Slug.php old mode 100644 new mode 100755 diff --git a/kernel/helpers/Version.php b/kernel/helpers/Version.php old mode 100644 new mode 100755 diff --git a/kernel/manifest.json b/kernel/manifest.json old mode 100644 new mode 100755 diff --git a/kernel/middlewares/AuthMiddleware.php b/kernel/middlewares/AuthMiddleware.php old mode 100644 new mode 100755 diff --git a/kernel/models/Menu.php b/kernel/models/Menu.php old mode 100644 new mode 100755 diff --git a/kernel/models/Option.php b/kernel/models/Option.php old mode 100644 new mode 100755 diff --git a/kernel/modules/admin_themes/AdminThemesModule.php b/kernel/modules/admin_themes/AdminThemesModule.php old mode 100644 new mode 100755 diff --git a/kernel/modules/admin_themes/controllers/AdminThemeController.php b/kernel/modules/admin_themes/controllers/AdminThemeController.php old mode 100644 new mode 100755 diff --git a/kernel/modules/admin_themes/manifest.json b/kernel/modules/admin_themes/manifest.json old mode 100644 new mode 100755 diff --git a/kernel/modules/admin_themes/routs/adminThemes.php b/kernel/modules/admin_themes/routs/adminThemes.php old mode 100644 new mode 100755 diff --git a/kernel/modules/admin_themes/views/index.php b/kernel/modules/admin_themes/views/index.php old mode 100644 new mode 100755 diff --git a/kernel/modules/admin_themes/views/view.php b/kernel/modules/admin_themes/views/view.php old mode 100644 new mode 100755 diff --git a/kernel/modules/menu/MenuModule.php b/kernel/modules/menu/MenuModule.php old mode 100644 new mode 100755 diff --git a/kernel/modules/menu/controllers/MenuController.php b/kernel/modules/menu/controllers/MenuController.php old mode 100644 new mode 100755 diff --git a/kernel/modules/menu/controllers/MenuRestController.php b/kernel/modules/menu/controllers/MenuRestController.php old mode 100644 new mode 100755 diff --git a/kernel/modules/menu/manifest.json b/kernel/modules/menu/manifest.json old mode 100644 new mode 100755 diff --git a/kernel/modules/menu/migrations/2024_09_23_125545_create_menu_table.php b/kernel/modules/menu/migrations/2024_09_23_125545_create_menu_table.php old mode 100644 new mode 100755 diff --git a/kernel/modules/menu/models/Menu.php b/kernel/modules/menu/models/Menu.php old mode 100644 new mode 100755 diff --git a/kernel/modules/menu/models/forms/CreateMenuForm.php b/kernel/modules/menu/models/forms/CreateMenuForm.php old mode 100644 new mode 100755 diff --git a/kernel/modules/menu/routs/menu.php b/kernel/modules/menu/routs/menu.php old mode 100644 new mode 100755 diff --git a/kernel/modules/menu/service/MenuService.php b/kernel/modules/menu/service/MenuService.php old mode 100644 new mode 100755 diff --git a/kernel/modules/menu/table/columns/MenuDeleteActionColumn.php b/kernel/modules/menu/table/columns/MenuDeleteActionColumn.php old mode 100644 new mode 100755 diff --git a/kernel/modules/menu/table/columns/MenuEditActionColumn.php b/kernel/modules/menu/table/columns/MenuEditActionColumn.php old mode 100644 new mode 100755 diff --git a/kernel/modules/menu/table/columns/MenuViewActionColumn.php b/kernel/modules/menu/table/columns/MenuViewActionColumn.php old mode 100644 new mode 100755 diff --git a/kernel/modules/menu/views/form.php b/kernel/modules/menu/views/form.php old mode 100644 new mode 100755 diff --git a/kernel/modules/menu/views/index.php b/kernel/modules/menu/views/index.php old mode 100644 new mode 100755 index 0cad83d..d3bbfcd --- a/kernel/modules/menu/views/index.php +++ b/kernel/modules/menu/views/index.php @@ -19,12 +19,15 @@ $table = new ListEloquentTable(new EloquentDataProvider(Menu::class, [ 'baseUrl' => "/admin/settings/menu", ])); $table->columns([ - 'parent_id' => (function ($data) { + 'parent_id' => function ($data) { if ($data == 0) return null; return Menu::find($data)->label; - }), + }, 'icon_file' => function ($data) { return $data ? "" : ""; + }, + 'status' => function ($data) { + return Menu::getStatus()[$data]; } ]); $table->beforePrint(function () { diff --git a/kernel/modules/menu/views/view.php b/kernel/modules/menu/views/view.php old mode 100644 new mode 100755 diff --git a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php old mode 100644 new mode 100755 index d4d4102..13c4e6c --- a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php +++ b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php @@ -10,14 +10,12 @@ use kernel\Flash; use kernel\helpers\Debug; use kernel\helpers\Files; use kernel\helpers\RESTClient; -use kernel\helpers\SMTP; -use kernel\Mailing; +use kernel\modules\module_shop_client\services\ModuleShopClientService; use kernel\Request; use kernel\services\AdminThemeService; use kernel\services\KernelService; use kernel\services\ModuleService; use kernel\services\ModuleShopService; -use kernel\services\TokenService; use PHPMailer\PHPMailer\Exception; class ModuleShopClientController extends AdminController @@ -26,6 +24,7 @@ class ModuleShopClientController extends AdminController protected Client $client; protected ModuleService $moduleService; protected KernelService $kernelService; + protected ModuleShopClientService $moduleShopClientService; protected function init(): void { @@ -35,6 +34,7 @@ class ModuleShopClientController extends AdminController $this->client = new Client(); $this->moduleService = new ModuleService(); $this->kernelService = new KernelService(); + $this->moduleShopClientService = new ModuleShopClientService(); } /** @@ -42,7 +42,6 @@ class ModuleShopClientController extends AdminController */ public function actionIndex(int $page_number = 1): void { - if ($this->moduleService->issetModuleShopToken()) { if ($this->moduleService->isServerAvailable()) { @@ -157,24 +156,71 @@ class ModuleShopClientController extends AdminController $this->redirect('/admin/module_shop_client', 302); } +// public function actionSearch(int $page_number = 1): void +// { +// $request = new Request(); +// $filters = $request->get(); +//// Debug::dd($filters); +// if ($this->moduleService->issetModuleShopToken()) { +// if ($this->moduleService->isServerAvailable()) { +// $modules_info = []; +// $per_page = 8; +// $modules = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); +// $modules = json_decode($modules->getBody()->getContents(), true); +// foreach ($modules as $module) { +// foreach ($filters as $key => $value) { +// if ($value === '') continue; +// if ($module[$key] !== $value) { +// break; +// } +// +// $modules_info[] = $module; +// } +// } +// $module_count = count($modules_info); +// $modules_info = array_slice($modules_info, $per_page * ($page_number - 1), $per_page); +// +// $this->cgView->render("index.php", [ +// 'modules_info' => $modules_info, +// 'moduleService' => $this->moduleService, +// 'page_number' => $page_number, +// 'module_count' => $module_count, +// 'per_page' => $per_page, +// 'kernelService' => new KernelService(), +// 'adminThemeService' => new AdminThemeService(), +// 'filterValues' => $filters +// ]); +// } else { +// $this->cgView->render("module_shop_error_connection.php"); +// } +// +// } else { +// $this->cgView->render("login_at_module_shop.php"); +// } +// } + public function actionSearch(int $page_number = 1): void { $request = new Request(); $filters = $request->get(); if ($this->moduleService->issetModuleShopToken()) { if ($this->moduleService->isServerAvailable()) { - $modules_info = []; +// $modules_info = []; $per_page = 8; - $modules = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); - $modules = json_decode($modules->getBody()->getContents(), true); - foreach ($modules as $module) { - foreach ($filters as $key => $value) { + $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); + $modules_info = json_decode($modules_info->getBody()->getContents(), true); + foreach ($modules_info as $key => $module) { + foreach ($filters as $column => $value) { if ($value === '') continue; - if ($module[$key] !== $value) { - break; + if (is_numeric($value)) { + if ($module[$column] !== $value) { + unset($modules_info[$key]); + } + } elseif (is_string($value)) { + if (!str_contains($module[$column], $value)) { + unset($modules_info[$key]); + } } - - $modules_info[] = $module; } } $module_count = count($modules_info); @@ -188,6 +234,7 @@ class ModuleShopClientController extends AdminController 'per_page' => $per_page, 'kernelService' => new KernelService(), 'adminThemeService' => new AdminThemeService(), + 'filterValues' => $filters ]); } else { $this->cgView->render("module_shop_error_connection.php"); @@ -209,7 +256,7 @@ class ModuleShopClientController extends AdminController $moduleShopService = new ModuleShopService(); $result = $moduleShopService->email_auth($address); - if ($result['status'] == 'success'){ + if ($result['status'] == 'success') { $this->cgView->render('enter_code.php', ['email' => $address]); } @@ -224,7 +271,7 @@ class ModuleShopClientController extends AdminController $moduleShopService = new ModuleShopService(); $result = $moduleShopService->code_check($code); - if (isset($result['access_token'])){ + if (isset($result['access_token'])) { $envFile = \EnvEditor\EnvFile::loadFrom(ROOT_DIR . "/.env"); diff --git a/kernel/modules/module_shop_client/manifest.json b/kernel/modules/module_shop_client/manifest.json old mode 100644 new mode 100755 diff --git a/kernel/modules/module_shop_client/routs/module_shop_client.php b/kernel/modules/module_shop_client/routs/module_shop_client.php old mode 100644 new mode 100755 diff --git a/kernel/modules/module_shop_client/services/ModuleShopClientService.php b/kernel/modules/module_shop_client/services/ModuleShopClientService.php new file mode 100755 index 0000000..d86afca --- /dev/null +++ b/kernel/modules/module_shop_client/services/ModuleShopClientService.php @@ -0,0 +1,22 @@ +getBody()->getContents(), true); +// return array_slice($modules_info, $perPage * ($pageNumber - 1), $perPage); +// } +// +// public function getModulesInfoWithFilters(string $url, int $perPage, int $pageNumber): \Psr\Http\Message\ResponseInterface +// { +// $modules_info = RESTClient::request($url); +// $modules_info = json_decode($modules_info->getBody()->getContents(), true); +// return array_slice($modules_info, $perPage * ($pageNumber - 1), $perPage); +// } +} \ No newline at end of file diff --git a/kernel/modules/module_shop_client/views/enter_code.php b/kernel/modules/module_shop_client/views/enter_code.php old mode 100644 new mode 100755 diff --git a/kernel/modules/module_shop_client/views/index.php b/kernel/modules/module_shop_client/views/index.php old mode 100644 new mode 100755 index aa5ae3e..f3474d4 --- a/kernel/modules/module_shop_client/views/index.php +++ b/kernel/modules/module_shop_client/views/index.php @@ -7,6 +7,7 @@ * @var \kernel\services\ModuleService $moduleService * @var \kernel\services\KernelService $kernelService * @var \kernel\services\AdminThemeService $adminThemeService + * @var array $filterValues */ use Itguild\Tables\ListJsonTable; @@ -30,7 +31,6 @@ $meta['total'] = $module_count; $info_to_table['meta'] = $meta; $info_to_table['data'] = $modules_info; -$info_to_table['filters'] = ['type']; $table = new ListJsonTable(json_encode($info_to_table, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); @@ -40,8 +40,24 @@ $table->addAction(function ($row, $url) use ($moduleService) { return \kernel\widgets\IconBtn\IconBtnViewWidget::create(['url' => $url])->run(); }); -$table->addAction(function ($row, $url) use ($moduleService){ - if ($row['slug'] !== 'kernel') { +$table->columns([ + 'type' => [ + 'filter' => [ + 'class' => \kernel\filters\BootstrapSelectFilter::class, + 'params' => [ + 'options' => [ + 'kernel' => 'kernel', + 'entity' => 'entity', + ], + 'prompt' => 'Не выбрано' + ], + 'value' => $filterValues['type'] ?? '' + ], + ] +]); + +$table->addAction(function ($row, $url) use ($moduleService) { + if ($row['type'] === 'entity' || $row['type'] === 'additional_property') { if ($moduleService->isInstall($row['slug'])) { $url = "$url/delete/?slug=" . $row['slug']; @@ -52,16 +68,19 @@ $table->addAction(function ($row, $url) use ($moduleService){ return \kernel\widgets\IconBtn\IconBtnInstallWidget::create(['url' => $url])->run(); } } - return null; + + return false; }); $table->addAction(function ($row, $url) use ($moduleService) { - $slug = $row['slug']; - if ($moduleService->isInstall($slug)) { - if (!$moduleService->isLastVersion($slug)) { - $url = "$url/update/?slug=" . $slug; + if ($row['type'] === 'entity' || $row['type'] === 'additional_property') { + $slug = $row['slug']; + if ($moduleService->isInstall($slug)) { + if (!$moduleService->isLastVersion($slug)) { + $url = "$url/update/?slug=" . $slug; - return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run(); + return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run(); + } } } @@ -69,8 +88,7 @@ $table->addAction(function ($row, $url) use ($moduleService) { }); $table->addAction(function ($row, $url) use ($kernelService) { - $slug = $row['slug']; - if ($slug === 'kernel') { + if ($row['type'] === 'kernel') { if (!$kernelService->isLastVersion()) { $url = "$url/kernel/update_form/"; @@ -82,9 +100,8 @@ $table->addAction(function ($row, $url) use ($kernelService) { }); $table->addAction(function ($row, $url) use ($adminThemeService) { - $type = $row['type']; - $slug = $row['slug']; - if ($type === 'admin_theme') { + if ($row['type'] === 'admin_theme') { + $slug = $row['slug']; if ($adminThemeService->isInstall($slug)) { if (!$adminThemeService->isLastVersion($slug)) { $url = "$url/admin_theme/update/"; diff --git a/kernel/modules/module_shop_client/views/kernel_update.php b/kernel/modules/module_shop_client/views/kernel_update.php old mode 100644 new mode 100755 diff --git a/kernel/modules/module_shop_client/views/login_at_module_shop.php b/kernel/modules/module_shop_client/views/login_at_module_shop.php old mode 100644 new mode 100755 diff --git a/kernel/modules/module_shop_client/views/module_shop_error_connection.php b/kernel/modules/module_shop_client/views/module_shop_error_connection.php old mode 100644 new mode 100755 diff --git a/kernel/modules/module_shop_client/views/success_login.php b/kernel/modules/module_shop_client/views/success_login.php old mode 100644 new mode 100755 diff --git a/kernel/modules/module_shop_client/views/view.php b/kernel/modules/module_shop_client/views/view.php old mode 100644 new mode 100755 diff --git a/kernel/modules/option/OptionModule.php b/kernel/modules/option/OptionModule.php old mode 100644 new mode 100755 diff --git a/kernel/modules/option/controllers/OptionController.php b/kernel/modules/option/controllers/OptionController.php old mode 100644 new mode 100755 diff --git a/kernel/modules/option/manifest.json b/kernel/modules/option/manifest.json old mode 100644 new mode 100755 diff --git a/kernel/modules/option/migrations/2024_09_23_125716_create_option_table.php b/kernel/modules/option/migrations/2024_09_23_125716_create_option_table.php old mode 100644 new mode 100755 diff --git a/kernel/modules/option/models/Option.php b/kernel/modules/option/models/Option.php old mode 100644 new mode 100755 diff --git a/kernel/modules/option/models/forms/CreateOptionForm.php b/kernel/modules/option/models/forms/CreateOptionForm.php old mode 100644 new mode 100755 diff --git a/kernel/modules/option/routs/option.php b/kernel/modules/option/routs/option.php old mode 100644 new mode 100755 diff --git a/kernel/modules/option/service/OptionService.php b/kernel/modules/option/service/OptionService.php old mode 100644 new mode 100755 diff --git a/kernel/modules/option/table/columns/OptionDeleteActionColumn.php b/kernel/modules/option/table/columns/OptionDeleteActionColumn.php old mode 100644 new mode 100755 diff --git a/kernel/modules/option/table/columns/OptionEditActionColumn.php b/kernel/modules/option/table/columns/OptionEditActionColumn.php old mode 100644 new mode 100755 diff --git a/kernel/modules/option/table/columns/OptionViewActionColumn.php b/kernel/modules/option/table/columns/OptionViewActionColumn.php old mode 100644 new mode 100755 diff --git a/kernel/modules/option/views/form.php b/kernel/modules/option/views/form.php old mode 100644 new mode 100755 diff --git a/kernel/modules/option/views/index.php b/kernel/modules/option/views/index.php old mode 100644 new mode 100755 diff --git a/kernel/modules/option/views/view.php b/kernel/modules/option/views/view.php old mode 100644 new mode 100755 diff --git a/kernel/modules/post/PostModule.php b/kernel/modules/post/PostModule.php old mode 100644 new mode 100755 diff --git a/kernel/modules/post/controllers/PostController.php b/kernel/modules/post/controllers/PostController.php old mode 100644 new mode 100755 diff --git a/kernel/modules/post/controllers/PostRestController.php b/kernel/modules/post/controllers/PostRestController.php old mode 100644 new mode 100755 diff --git a/kernel/modules/post/manifest.json b/kernel/modules/post/manifest.json old mode 100644 new mode 100755 diff --git a/kernel/modules/post/migrations/2024_09_23_130017_create_post_table.php b/kernel/modules/post/migrations/2024_09_23_130017_create_post_table.php old mode 100644 new mode 100755 diff --git a/kernel/modules/post/models/Post.php b/kernel/modules/post/models/Post.php old mode 100644 new mode 100755 diff --git a/kernel/modules/post/models/forms/CreatePostForm.php b/kernel/modules/post/models/forms/CreatePostForm.php old mode 100644 new mode 100755 diff --git a/kernel/modules/post/routs/post.php b/kernel/modules/post/routs/post.php old mode 100644 new mode 100755 diff --git a/kernel/modules/post/service/PostService.php b/kernel/modules/post/service/PostService.php old mode 100644 new mode 100755 diff --git a/kernel/modules/post/views/form.php b/kernel/modules/post/views/form.php old mode 100644 new mode 100755 diff --git a/kernel/modules/post/views/index.php b/kernel/modules/post/views/index.php old mode 100644 new mode 100755 index 045feb1..4b47124 --- a/kernel/modules/post/views/index.php +++ b/kernel/modules/post/views/index.php @@ -15,11 +15,15 @@ use kernel\widgets\IconBtn\IconBtnDeleteWidget; use kernel\widgets\IconBtn\IconBtnEditWidget; use kernel\widgets\IconBtn\IconBtnViewWidget; +$get = (new \kernel\Request())->get(); + $table = new ListEloquentTable(new EloquentDataProvider(Post::class, [ 'currentPage' => $page_number, 'perPage' => 3, 'params' => ["class" => "table table-bordered", "border" => "2"], - 'baseUrl' => "/admin/post" + 'baseUrl' => "/admin/post", + 'searchPrefix' => "", + 'searchParams' => $get, ])); $view->setTitle("Список постов"); @@ -36,36 +40,57 @@ foreach ($additionals as $additional) { }); } +//\kernel\helpers\Debug::dd($request); + $table->columns([ - 'created_at' => function ($data) { - if (!$data){ - return null; - } - - return (new DateTimeImmutable($data))->format("d-m-Y"); - }, + 'title' => [ + 'filter' => [ + 'class' => \kernel\filters\BootstrapTextFilter::class, + 'value' => $get['title'] ?? '' + ] + ], + 'content' => [ + 'filter' => [ + 'class' => \kernel\filters\BootstrapTextFilter::class, + 'value' => $get['content'] ?? '' + ] + ], + 'created_at' => [ + 'format' => 'date:d-m-Y', + ], 'updated_at' => function ($data) { - if (!$data){ + if (!$data) { return null; } return (new DateTimeImmutable($data))->format("d-m-Y"); }, - 'user_id' => (function ($data) { - return User::find($data)->username; - }) + 'user_id' => [ + 'value' => function ($data) { + return User::find($data)->username; + }, + 'filter' => [ + 'class' => \kernel\filters\BootstrapSelectFilter::class, + 'params' => [ + 'options' => \kernel\modules\user\service\UserService::createUsernameArr(), + 'prompt' => 'Не выбрано' + ], + 'value' => $get['user_id'] ?? '', + ], + ] ]); + $table->beforePrint(function () { return IconBtnCreateWidget::create(['url' => '/admin/post/create'])->run(); }); -$table->addAction(function($row) { +$table->addAction(function ($row) { return IconBtnViewWidget::create(['url' => '/admin/post/view/' . $row['id']])->run(); }); -$table->addAction(function($row) { +$table->addAction(function ($row) { return IconBtnEditWidget::create(['url' => '/admin/post/update/' . $row['id']])->run(); }); -$table->addAction(function($row) { +$table->addAction(function ($row) { return IconBtnDeleteWidget::create(['url' => '/admin/post/delete/' . $row['id']])->run(); }); $table->create(); diff --git a/kernel/modules/post/views/view.php b/kernel/modules/post/views/view.php old mode 100644 new mode 100755 diff --git a/kernel/modules/secure/controllers/SecureController.php b/kernel/modules/secure/controllers/SecureController.php old mode 100644 new mode 100755 diff --git a/kernel/modules/secure/controllers/SecureRestController.php b/kernel/modules/secure/controllers/SecureRestController.php old mode 100644 new mode 100755 diff --git a/kernel/modules/secure/manifest.json b/kernel/modules/secure/manifest.json old mode 100644 new mode 100755 diff --git a/kernel/modules/secure/middlewares/BearerAuthMiddleware.php b/kernel/modules/secure/middlewares/BearerAuthMiddleware.php old mode 100644 new mode 100755 diff --git a/kernel/modules/secure/migrations/2024_12_09_081420_create_secret_code_table.php b/kernel/modules/secure/migrations/2024_12_09_081420_create_secret_code_table.php old mode 100644 new mode 100755 diff --git a/kernel/modules/secure/models/SecretCode.php b/kernel/modules/secure/models/SecretCode.php old mode 100644 new mode 100755 diff --git a/kernel/modules/secure/models/forms/LoginEmailForm.php b/kernel/modules/secure/models/forms/LoginEmailForm.php old mode 100644 new mode 100755 diff --git a/kernel/modules/secure/models/forms/LoginForm.php b/kernel/modules/secure/models/forms/LoginForm.php old mode 100644 new mode 100755 diff --git a/kernel/modules/secure/models/forms/RegisterForm.php b/kernel/modules/secure/models/forms/RegisterForm.php old mode 100644 new mode 100755 diff --git a/kernel/modules/secure/routs/secure.php b/kernel/modules/secure/routs/secure.php old mode 100644 new mode 100755 diff --git a/kernel/modules/secure/services/SecureService.php b/kernel/modules/secure/services/SecureService.php old mode 100644 new mode 100755 diff --git a/kernel/modules/secure/views/email_login.php b/kernel/modules/secure/views/email_login.php old mode 100644 new mode 100755 diff --git a/kernel/modules/secure/views/enter_code.php b/kernel/modules/secure/views/enter_code.php old mode 100644 new mode 100755 diff --git a/kernel/modules/secure/views/login.php b/kernel/modules/secure/views/login.php old mode 100644 new mode 100755 diff --git a/kernel/modules/secure/views/register.php b/kernel/modules/secure/views/register.php old mode 100644 new mode 100755 diff --git a/kernel/modules/user/UserModule.php b/kernel/modules/user/UserModule.php old mode 100644 new mode 100755 diff --git a/kernel/modules/user/controllers/UserController.php b/kernel/modules/user/controllers/UserController.php old mode 100644 new mode 100755 index fdd8534..60a6028 --- a/kernel/modules/user/controllers/UserController.php +++ b/kernel/modules/user/controllers/UserController.php @@ -6,6 +6,8 @@ use Exception; use JetBrains\PhpStorm\NoReturn; use kernel\AdminController; use kernel\EntityRelation; +use kernel\FileUpload; +use kernel\helpers\Debug; use kernel\modules\user\models\forms\CreateUserForm; use kernel\modules\user\models\User; use kernel\modules\user\service\UserService; @@ -35,10 +37,17 @@ class UserController extends AdminController { $userForm = new CreateUserForm(); $userForm->load($_REQUEST); + + + if (isset($_FILES['user_photo']) && $_FILES['user_photo']['error'] === UPLOAD_ERR_OK) { + $file = new FileUpload($_FILES['user_photo'], ['jpg', 'jpeg', 'png']); + $file->upload(); + $userForm->setItem('user_photo', $file->getUploadFile()); + } + if ($userForm->validate()){ $user = $this->userService->create($userForm); - $entityRelation = new EntityRelation(); $entityRelation->saveEntityRelation(entity: "user", model: $user, request: new Request()); @@ -98,6 +107,13 @@ class UserController extends AdminController $userForm = new CreateUserForm(); $userService = new UserService(); $userForm->load($_REQUEST); + + if (isset($_FILES['user_photo']) && $_FILES['user_photo']['error'] === UPLOAD_ERR_OK) { + $file = new FileUpload($_FILES['user_photo'], ['jpg', 'jpeg', 'png']); + $file->upload(); + $userForm->setItem('user_photo', $file->getUploadFile()); + } + if ($userForm->validateForUpdate()){ $user = $userService->update($userForm, $user); @@ -128,4 +144,53 @@ class UserController extends AdminController $this->redirect("/admin/user/"); } + public function actionProfile(): void + { + $user = UserService::getAuthUser(); + if (!$user){ + throw new Exception(message: "The user not found"); + } + $this->cgView->render("view_profile.php", ['user' => $user]); + } + + public function actionProfileUpdate(): void + { + $model = UserService::getAuthUser(); + if (!$model){ + throw new Exception(message: "The user not found"); + } + + $this->cgView->render("form_profile.php", ['model' => $model]); + } + + public function actionProfileEdit(): void + { + $user = UserService::getAuthUser(); + if (!$user){ + throw new Exception(message: "The user not found"); + } + + $userForm = new CreateUserForm(); + $userService = new UserService(); + $userForm->load($_REQUEST); + + if (isset($_FILES['user_photo']) && $_FILES['user_photo']['error'] === UPLOAD_ERR_OK) { + $file = new FileUpload($_FILES['user_photo'], ['jpg', 'jpeg', 'png']); + $file->upload(); + $userForm->setItem('user_photo', $file->getUploadFile()); + } + + if ($userForm->validateForUpdate()){ + $user = $userService->update($userForm, $user); + + $entityRelation = new EntityRelation(); + $entityRelation->saveEntityRelation(entity: "user", model: $user, request: new Request()); + + if ($user){ + $this->redirect("/admin/user/profile"); + } + } + $this->redirect("/admin/user/profile/update"); + } + } \ No newline at end of file diff --git a/kernel/modules/user/manifest.json b/kernel/modules/user/manifest.json old mode 100644 new mode 100755 diff --git a/kernel/modules/user/migrations/2024_09_23_125827_create_user_table.php b/kernel/modules/user/migrations/2024_09_23_125827_create_user_table.php old mode 100644 new mode 100755 index a762579..2b2ab0f --- a/kernel/modules/user/migrations/2024_09_23_125827_create_user_table.php +++ b/kernel/modules/user/migrations/2024_09_23_125827_create_user_table.php @@ -20,6 +20,7 @@ return new class extends Migration $table->string('username', 255)->nullable(false); $table->string('email', 255); $table->string('password_hash', 255); + $table->string('user_photo', 255)->nullable(); $table->integer('role')->default(1); $table->string('access_token', 255)->nullable(true); $table->dateTime('access_token_expires_at')->nullable(true); diff --git a/kernel/modules/user/models/User.php b/kernel/modules/user/models/User.php old mode 100644 new mode 100755 index 3dd03c1..78afe96 --- a/kernel/modules/user/models/User.php +++ b/kernel/modules/user/models/User.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model; * @property string $username * @property string $email * @property string $password_hash + * @property string $user_photo * @property string $access_token * @property string $access_token_expires_at * @method static find($id) @@ -17,7 +18,7 @@ class User extends Model { const ADMIN_USER_ROLE = 9; protected $table = 'user'; - protected $fillable = ['username', 'email', 'password_hash', 'role', 'access_token', 'access_token_expires_at']; + protected $fillable = ['username', 'email', 'password_hash', 'user_photo', 'role', 'access_token', 'access_token_expires_at']; protected array $dates = ['deleted at']; public static function labels(): array @@ -25,6 +26,7 @@ class User extends Model { return [ 'username' => 'Логин', 'email' => 'Email', + 'user_photo' => 'Фото профиля', 'created_at' => 'Создан', 'updated_at' => 'Обновлен', ]; diff --git a/kernel/modules/user/models/forms/CreateUserForm.php b/kernel/modules/user/models/forms/CreateUserForm.php old mode 100644 new mode 100755 index 73c5f77..bcf37df --- a/kernel/modules/user/models/forms/CreateUserForm.php +++ b/kernel/modules/user/models/forms/CreateUserForm.php @@ -12,7 +12,8 @@ class CreateUserForm extends FormModel return [ 'username' => 'required|min-str-len:5|max-str-len:30', 'password' => 'required|min-str-len:5|max-str-len:30', - 'email' => 'required|email' + 'email' => 'required|email', + 'user_photo' => '' ]; } @@ -21,7 +22,9 @@ class CreateUserForm extends FormModel return [ 'username' => 'required|min-str-len:5|max-str-len:30', 'password' => '', - 'email' => 'required|email' + 'email' => 'required|email', + 'user_photo' => '' + ]; } diff --git a/kernel/modules/user/routs/user.php b/kernel/modules/user/routs/user.php old mode 100644 new mode 100755 index 5572c92..25eda62 --- a/kernel/modules/user/routs/user.php +++ b/kernel/modules/user/routs/user.php @@ -17,6 +17,11 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ App::$collector->any('/update/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionUpdate']); App::$collector->any("/edit/{id}", [\kernel\modules\user\controllers\UserController::class, 'actionEdit']); App::$collector->get('/delete/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionDelete']); + App::$collector->group(["prefix" => "profile"], callback: function (RouteCollector $router) { + App::$collector->get('/', [\kernel\modules\user\controllers\UserController::class, 'actionProfile']); + App::$collector->get('/update', [\kernel\modules\user\controllers\UserController::class, 'actionProfileUpdate']); + App::$collector->post('/edit', [\kernel\modules\user\controllers\UserController::class, 'actionProfileEdit']); + }); }); }); }); \ No newline at end of file diff --git a/kernel/modules/user/service/UserService.php b/kernel/modules/user/service/UserService.php old mode 100644 new mode 100755 index 9e8dd5d..9915c2a --- a/kernel/modules/user/service/UserService.php +++ b/kernel/modules/user/service/UserService.php @@ -15,6 +15,7 @@ class UserService $model->username = $form_model->getItem('username'); $model->email = $form_model->getItem('email'); $model->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT); + $model->user_photo = $form_model->getItem('user_photo'); if ($model->save()){ return $model; } @@ -29,6 +30,7 @@ class UserService if ($form_model->getItem('password')) { $user->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT); } + $user->user_photo = $form_model->getItem('user_photo'); if ($user->save()){ return $user; } @@ -80,6 +82,28 @@ class UserService return ''; } + public static function getAuthUserId(): string + { + $user = self::getAuthUser(); + if ($user){ + return $user->id; + } + + return ''; + } + + public static function getAuthUserPhoto(): string|null + { + $user = self::getAuthUser(); + if ($user){ + if ($user->user_photo) { + return $user->user_photo; + } + } + + return null; + } + public function getByAccessToken(string $token) { return $this->getByField("access_token", $token); diff --git a/kernel/modules/user/table/columns/UserDeleteActionColumn.php b/kernel/modules/user/table/columns/UserDeleteActionColumn.php old mode 100644 new mode 100755 diff --git a/kernel/modules/user/table/columns/UserEditActionColumn.php b/kernel/modules/user/table/columns/UserEditActionColumn.php old mode 100644 new mode 100755 diff --git a/kernel/modules/user/table/columns/UserViewActionColumn.php b/kernel/modules/user/table/columns/UserViewActionColumn.php old mode 100644 new mode 100755 diff --git a/kernel/modules/user/views/form.php b/kernel/modules/user/views/form.php old mode 100644 new mode 100755 index e32d35f..89f94d2 --- a/kernel/modules/user/views/form.php +++ b/kernel/modules/user/views/form.php @@ -32,6 +32,16 @@ $form->field(class: \itguild\forms\inputs\TextInput::class, name: "email", param ->setLabel("Email") ->render(); +if (!empty($model->user_photo)){ + echo "
"; +} +$form->field(class: \itguild\forms\inputs\File::class, name: "user_photo", params: [ + 'class' => "form-control", + 'value' => $model->user_photo ?? '' +]) + ->setLabel("Фото профиля") + ->render(); + $entityRelations = new \kernel\EntityRelation(); if (!isset($model)) { $model = new User(); diff --git a/kernel/modules/user/views/form_profile.php b/kernel/modules/user/views/form_profile.php new file mode 100755 index 0000000..0c9ca1a --- /dev/null +++ b/kernel/modules/user/views/form_profile.php @@ -0,0 +1,74 @@ +beginForm("/admin/user/profile/edit", enctype: 'multipart/form-data'); + +$form->field(class: \itguild\forms\inputs\TextInput::class, name: "username", params: [ + 'class' => "form-control", + 'placeholder' => 'Логин', + 'value' => $model->username ?? '' +]) + ->setLabel("Логин") + ->render(); + +$form->field(class: \itguild\forms\inputs\TextInput::class, name: "password", params: [ + 'class' => "form-control", + 'type' => "password", +]) + ->setLabel("Пароль") + ->render(); + +$form->field(class: \itguild\forms\inputs\TextInput::class, name: "email", params: [ + 'class' => "form-control", + 'type' => "email", + 'placeholder' => 'test@mail.ru', + 'value' => $model->email ?? '' +]) + ->setLabel("Email") + ->render(); + +if (!empty($model->user_photo)){ + echo "
"; +} +$form->field(class: \itguild\forms\inputs\File::class, name: "user_photo", params: [ + 'class' => "form-control", + 'value' => $model->user_photo ?? '' +]) + ->setLabel("Фото профиля") + ->render(); + +$entityRelations = new \kernel\EntityRelation(); +if (!isset($model)) { + $model = new User(); +} +$entityRelations->renderEntityAdditionalPropertyFormBySlug("user", $model); +?> +
+
+ 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/modules/user/views/index.php b/kernel/modules/user/views/index.php old mode 100644 new mode 100755 index e492f5e..abfce5b --- a/kernel/modules/user/views/index.php +++ b/kernel/modules/user/views/index.php @@ -17,13 +17,15 @@ use kernel\widgets\IconBtn\IconBtnDeleteWidget; use kernel\widgets\IconBtn\IconBtnEditWidget; use kernel\widgets\IconBtn\IconBtnViewWidget; +$get = (new \kernel\Request())->get(); + $table = new ListEloquentTable(new EloquentDataProvider(User::class, [ 'currentPage' => $page_number, 'perPage' => 3, 'params' => ["class" => "table table-bordered", "border" => "2"], 'baseUrl' => "/admin/user", - 'filters' => ['email'], -])); + 'searchPrefix' => "", + 'searchParams' => $get,])); $entityRelation = new \kernel\EntityRelation(); $additionals = $entityRelation->getEntityRelationsBySlug("user"); @@ -37,9 +39,13 @@ foreach ($additionals as $additional) { $table->columns([ 'username' => [ "filter" => [ - 'class' => \Itguild\Tables\Filter\InputTextFilter::class + 'class' => \kernel\filters\BootstrapTextFilter::class, + 'value' => $get['username'] ?? null, ] ], + 'user_photo' => function ($data) { + return $data ? "" : ""; + }, 'created_at' => function ($data) { if (!$data){ return null; diff --git a/kernel/modules/user/views/view.php b/kernel/modules/user/views/view.php old mode 100644 new mode 100755 index 856186f..f234627 --- a/kernel/modules/user/views/view.php +++ b/kernel/modules/user/views/view.php @@ -35,6 +35,9 @@ foreach ($additionals as $key => $additional) { } $table->rows([ + 'user_photo' => function ($data) { + return $data ? "" : ""; + }, 'created_at' => function ($data) { if (!$data){ return null; diff --git a/kernel/modules/user/views/view_profile.php b/kernel/modules/user/views/view_profile.php new file mode 100755 index 0000000..b9b027f --- /dev/null +++ b/kernel/modules/user/views/view_profile.php @@ -0,0 +1,56 @@ + ["class" => "table table-bordered", "border" => "2"], + 'baseUrl' => "/admin/user", +])); +$table->beforePrint(function () use ($user) { + $btn = IconBtnEditWidget::create(['url' => '/admin/user/profile/edit'])->run(); + $btn .= IconBtnDeleteWidget::create(['url' => '/admin/user/delete/' . $user->id])->run(); + return $btn; +}); + +$entityRelation = new \kernel\EntityRelation(); +$additionals = $entityRelation->getEntityAdditionalProperty("user", $user); + +foreach ($additionals as $key => $additional) { + $table->addRow($key, function () use ($additional) { + return $additional; + }, ['after' => 'email']); +} + +$table->rows([ + 'user_photo' => function ($data) { + return $data ? "" : ""; + }, + 'created_at' => function ($data) { + if (!$data){ + return null; + } + + return (new DateTimeImmutable($data))->format("d-m-Y"); + }, + 'updated_at' => function ($data) { + if (!$data){ + return null; + } + + return (new DateTimeImmutable($data))->format("d-m-Y"); + } +]); +$table->create(); +$table->render(); \ No newline at end of file diff --git a/kernel/routs/admin.php b/kernel/routs/admin.php old mode 100644 new mode 100755 diff --git a/kernel/services/AdminThemeService.php b/kernel/services/AdminThemeService.php old mode 100644 new mode 100755 index 457fa02..f8d5aea --- a/kernel/services/AdminThemeService.php +++ b/kernel/services/AdminThemeService.php @@ -4,12 +4,16 @@ namespace kernel\services; use DirectoryIterator; use kernel\helpers\Debug; +use kernel\helpers\Files; use kernel\helpers\Manifest; use kernel\helpers\RESTClient; use kernel\models\Option; +use ZipArchive; class AdminThemeService { + protected array $errors = []; + protected Option $option; protected string $active_theme; protected ModuleService $moduleService; @@ -22,6 +26,24 @@ class AdminThemeService $this->moduleService = new ModuleService(); } + /** + * @return array + */ + public function getErrors(): array + { + return $this->errors; + } + + /** + * @param $msg + * @return void + */ + public function addError($msg): void + { + $this->errors[] = $msg; + } + + public function findActiveAdminTheme(): void { $model = Option::where("key", "active_admin_theme")->first(); @@ -50,7 +72,7 @@ class AdminThemeService $info = []; $theme = getConst($theme); $info['path'] = $theme; - if (file_exists($theme . "/manifest.json")){ + if (file_exists($theme . "/manifest.json")) { $manifest = file_get_contents($theme . "/manifest.json"); $manifest = Manifest::getWithVars($manifest); $manifest['preview'] = $manifest['resource'] . "/" . $manifest['preview']; @@ -60,6 +82,11 @@ class AdminThemeService return $info; } + public function getAdminThemeInfoBySlug(string $slug) + { + // TODO + } + public function isInstall(string $slug): bool { $adminThemePaths = Option::where("key", "admin_theme_paths")->first(); @@ -85,12 +112,13 @@ class AdminThemeService public function isLastVersion(string $slug): bool { if ($this->moduleService->isServerAvailable()) { - $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); + $modulesInfo = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); - $modules_info = json_decode($modules_info->getBody()->getContents(), true); + $modulesInfo = json_decode($modulesInfo->getBody()->getContents(), true); $themeInfo = $this->getAdminThemeInfo($slug); - foreach ($modules_info as $mod) { +// Debug::dd($themeInfo); + foreach ($modulesInfo as $mod) { if ($mod['slug'] === $themeInfo['slug'] && $mod['version'] === $themeInfo['version']) { return true; } @@ -99,4 +127,79 @@ class AdminThemeService return false; } + + public function pack(string $path): void + { + $themeName = basename($path); + + $tmpThemeDirFull = RESOURCES_DIR . '/tmp/ad/' . $themeName . "/"; + + $fileHelper = new Files(); + $fileHelper->copy_folder(ROOT_DIR . $path, $tmpThemeDirFull . 'meta/'); + $fileHelper->copy_folder(RESOURCES_DIR . '/' . $themeName, $tmpThemeDirFull . 'resources/'); + + if (!is_dir(RESOURCES_DIR . '/tmp/admin_themes')) { + $old_mask = umask(0); + mkdir(RESOURCES_DIR . '/tmp/admin_themes', 0775, true); + umask($old_mask); + } + $fileHelper->pack($tmpThemeDirFull, RESOURCES_DIR . '/tmp/admin_themes/' . $themeName . '.igt'); + } + + public function install(string $path): bool + { + $zip = new ZipArchive; + $tmpThemeDir = md5(time()); + $res = $zip->open(ROOT_DIR . $path); + if ($res === TRUE) { + $tmpThemeDirFull = RESOURCES_DIR . '/tmp/ad/' . $tmpThemeDir . "/"; + $zip->extractTo($tmpThemeDirFull); + $zip->close(); + } else { + $this->addError('unable to open zip archive'); + return false; + } + + if (!file_exists($tmpThemeDirFull . "meta/manifest.json")){ + $this->addError('manifest.json not found'); + return false; + } + + $manifestJson = getConst(file_get_contents($tmpThemeDirFull . "meta/manifest.json")); + $manifest = Manifest::getWithVars($manifestJson); + + $fileHelper = new Files(); + if (isset($manifest['theme_path'])) { + $fileHelper->copy_folder($tmpThemeDirFull . "meta", $manifest['theme_path']); + } else { + $fileHelper->copy_folder($tmpThemeDirFull . "meta", APP_DIR . '/admin_themes/' . $manifest['slug']); + } + + if (isset($manifest['resource_path'])) { + $fileHelper->copy_folder($tmpThemeDirFull . "resources", $manifest['resource_path']); + } else { + $fileHelper->copy_folder($tmpThemeDirFull . "resources", RESOURCES_DIR . '/' . $manifest['slug']); + } + + $fileHelper->recursiveRemoveDir($tmpThemeDirFull); + unlink(ROOT_DIR . $path); + return true; + } + + public function uninstall(string $path): void + { + $themeInfo = $this->getAdminThemeInfo(APP_DIR . '/admin_themes/' . basename($path)); + + $active_admin_theme = Option::where("key", "active_admin_theme")->first(); + if ($active_admin_theme->value === ROOT_DIR . $path) { + $this->setActiveAdminTheme(KERNEL_ADMIN_THEMES_DIR . '/default'); + } + $fileHelper = new Files(); + if (file_exists(ROOT_DIR . $path)) { + $fileHelper->recursiveRemoveDir(ROOT_DIR . $path); + } + if (file_exists(RESOURCES_DIR . '/' . $themeInfo['slug'])) { + $fileHelper->recursiveRemoveDir(RESOURCES_DIR . '/' . $themeInfo['slug']); + } + } } \ No newline at end of file diff --git a/kernel/services/ConsoleService.php b/kernel/services/ConsoleService.php old mode 100644 new mode 100755 diff --git a/kernel/services/KernelService.php b/kernel/services/KernelService.php old mode 100644 new mode 100755 diff --git a/kernel/services/MigrationService.php b/kernel/services/MigrationService.php old mode 100644 new mode 100755 diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php old mode 100644 new mode 100755 index 56ca7be..2a0eb69 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -362,11 +362,15 @@ class ModuleService if (file_exists(KERNEL_APP_MODULES_DIR . '/' . $moduleName)) { $fileHelper->copy_folder(KERNEL_APP_MODULES_DIR . '/' . $moduleName, $tmpModuleDirFull . 'kernel/'); } else { - mkdir($tmpModuleDirFull . 'kernel/'); + $old_mask = umask(0); + mkdir($tmpModuleDirFull . 'kernel/', 0775, true); + umask($old_mask); } if (!is_dir(RESOURCES_DIR . '/tmp/modules')) { - mkdir(RESOURCES_DIR . '/tmp/modules', 0777, true); + $old_mask = umask(0); + mkdir(RESOURCES_DIR . '/tmp/modules', 0775, true); + umask($old_mask); } $fileHelper->pack($tmpModuleDirFull, RESOURCES_DIR . '/tmp/modules/' . $moduleName . '.igm'); } diff --git a/kernel/services/ModuleShopService.php b/kernel/services/ModuleShopService.php old mode 100644 new mode 100755 diff --git a/kernel/services/TokenService.php b/kernel/services/TokenService.php old mode 100644 new mode 100755 diff --git a/kernel/templates/controllers/app_controller_template b/kernel/templates/controllers/app_controller_template old mode 100644 new mode 100755 diff --git a/kernel/templates/controllers/kernel_controller_template b/kernel/templates/controllers/kernel_controller_template old mode 100644 new mode 100755 diff --git a/kernel/templates/manifests/manifest_template b/kernel/templates/manifests/manifest_template old mode 100644 new mode 100755 diff --git a/kernel/templates/models/forms/create_form_template b/kernel/templates/models/forms/create_form_template old mode 100644 new mode 100755 diff --git a/kernel/templates/models/model_template b/kernel/templates/models/model_template old mode 100644 new mode 100755 diff --git a/kernel/templates/module_files/app_module_file_template b/kernel/templates/module_files/app_module_file_template old mode 100644 new mode 100755 diff --git a/kernel/templates/module_files/kernel_module_file_template b/kernel/templates/module_files/kernel_module_file_template old mode 100644 new mode 100755 diff --git a/kernel/templates/routs/app_routs_template b/kernel/templates/routs/app_routs_template old mode 100644 new mode 100755 diff --git a/kernel/templates/routs/kernel_routs_template b/kernel/templates/routs/kernel_routs_template old mode 100644 new mode 100755 diff --git a/kernel/templates/services/service_template b/kernel/templates/services/service_template old mode 100644 new mode 100755 diff --git a/kernel/templates/views/form_template b/kernel/templates/views/form_template old mode 100644 new mode 100755 diff --git a/kernel/templates/views/index_template b/kernel/templates/views/index_template old mode 100644 new mode 100755 index a7a7171..44953ea --- a/kernel/templates/views/index_template +++ b/kernel/templates/views/index_template @@ -51,6 +51,16 @@ $table = new \Itguild\Tables\ListJsonTable(json_encode( ] )); +// Пример фильтра +$table->columns([ + 'title' => [ + 'filter' => [ + 'class' => \Itguild\Tables\Filter\InputTextFilter::class, + 'value' => $get['title'] ?? '' + ] + ], +] + $table->beforePrint(function () { return IconBtnCreateWidget::create(['url' => '/admin/{slug}/create'])->run(); }); diff --git a/kernel/templates/views/view_template b/kernel/templates/views/view_template old mode 100644 new mode 100755 diff --git a/kernel/views/mailing/login_by_code.php b/kernel/views/mailing/login_by_code.php old mode 100644 new mode 100755 diff --git a/kernel/views/mailing/register_by_code.php b/kernel/views/mailing/register_by_code.php old mode 100644 new mode 100755 diff --git a/kernel/views/module/index.php b/kernel/views/module/index.php old mode 100644 new mode 100755 diff --git a/kernel/views/module/view.php b/kernel/views/module/view.php old mode 100644 new mode 100755 diff --git a/kernel/views/widgets/action_button.php b/kernel/views/widgets/action_button.php old mode 100644 new mode 100755 diff --git a/kernel/views/widgets/menu.php b/kernel/views/widgets/menu.php old mode 100644 new mode 100755 diff --git a/kernel/views/widgets/tabs.php b/kernel/views/widgets/tabs.php old mode 100644 new mode 100755 diff --git a/kernel/widgets/ActionButtonWidget.php b/kernel/widgets/ActionButtonWidget.php old mode 100644 new mode 100755 diff --git a/kernel/widgets/IconBtn/IconBtnActivateWidget.php b/kernel/widgets/IconBtn/IconBtnActivateWidget.php old mode 100644 new mode 100755 diff --git a/kernel/widgets/IconBtn/IconBtnCreateWidget.php b/kernel/widgets/IconBtn/IconBtnCreateWidget.php old mode 100644 new mode 100755 diff --git a/kernel/widgets/IconBtn/IconBtnDeactivateWidget.php b/kernel/widgets/IconBtn/IconBtnDeactivateWidget.php old mode 100644 new mode 100755 diff --git a/kernel/widgets/IconBtn/IconBtnDeleteWidget.php b/kernel/widgets/IconBtn/IconBtnDeleteWidget.php old mode 100644 new mode 100755 diff --git a/kernel/widgets/IconBtn/IconBtnEditWidget.php b/kernel/widgets/IconBtn/IconBtnEditWidget.php old mode 100644 new mode 100755 diff --git a/kernel/widgets/IconBtn/IconBtnInstallWidget.php b/kernel/widgets/IconBtn/IconBtnInstallWidget.php old mode 100644 new mode 100755 diff --git a/kernel/widgets/IconBtn/IconBtnListWidget.php b/kernel/widgets/IconBtn/IconBtnListWidget.php old mode 100644 new mode 100755 diff --git a/kernel/widgets/IconBtn/IconBtnUpdateWidget.php b/kernel/widgets/IconBtn/IconBtnUpdateWidget.php old mode 100644 new mode 100755 diff --git a/kernel/widgets/IconBtn/IconBtnViewWidget.php b/kernel/widgets/IconBtn/IconBtnViewWidget.php old mode 100644 new mode 100755 diff --git a/kernel/widgets/MenuWidget.php b/kernel/widgets/MenuWidget.php old mode 100644 new mode 100755 diff --git a/kernel/widgets/ModuleTabsWidget.php b/kernel/widgets/ModuleTabsWidget.php old mode 100644 new mode 100755 diff --git a/kernel/widgets/TagTabsWidget.php b/kernel/widgets/TagTabsWidget.php old mode 100644 new mode 100755 diff --git a/resources/default_user_photo/noPhoto.png b/resources/default_user_photo/noPhoto.png new file mode 100644 index 0000000..05d1bac Binary files /dev/null and b/resources/default_user_photo/noPhoto.png differ