diff --git a/app/modules/photo/PhotoModule.php b/app/modules/photo/PhotoModule.php index 4fdfff8..1ead103 100644 --- a/app/modules/photo/PhotoModule.php +++ b/app/modules/photo/PhotoModule.php @@ -40,11 +40,19 @@ class PhotoModule extends Module "url" => "/admin/photo", "slug" => "photo", ]); + + $this->menuService->createItem([ + "label" => "Фото", + "url" => "/admin/settings/photo", + "slug" => "photo_settings", + "parent_slug" => "settings" + ]); } public function deactivate(): void { $this->menuService->removeItemBySlug("photo"); + $this->menuService->removeItemBySlug("photo_settings"); } public function formInputs(string $entity, Model $model = null): void diff --git a/kernel/EntityRelation.php b/kernel/EntityRelation.php index 6b2fc42..1d118c2 100644 --- a/kernel/EntityRelation.php +++ b/kernel/EntityRelation.php @@ -249,4 +249,31 @@ class EntityRelation return $entities; } + + public static function configurationEntitiesByProperty(array|null $entities, string $property): void + { + $entityRelations = self::getEntitiesRelations(); + if (isset($entities)) { + foreach ($entities as $entity) { + if (!isset($entityRelations[$entity])) { + EntityRelation::addEntityRelation($entity, $property); + } + } + foreach ($entityRelations as $entity => $additionalProperty) { + if (in_array($entity, $entities)) { + if (!in_array($property, $additionalProperty)) { + EntityRelation::addEntityRelation($entity, $property); + } + } else { + if (in_array($property, $additionalProperty)) { + EntityRelation::removePropertyFromEntityRelations($entity, $property); + } + } + } + } else { + foreach ($entityRelations as $entity => $additionalProperty) { + EntityRelation::removePropertyFromEntityRelations($entity, $property); + } + } + } } \ No newline at end of file diff --git a/kernel/app_modules/photo/controllers/PhotoController.php b/kernel/app_modules/photo/controllers/PhotoController.php index e241869..17be731 100755 --- a/kernel/app_modules/photo/controllers/PhotoController.php +++ b/kernel/app_modules/photo/controllers/PhotoController.php @@ -8,7 +8,11 @@ use kernel\AdminController; use kernel\app_modules\photo\models\form\CreatePhotoForm; use kernel\app_modules\photo\models\Photo; use kernel\app_modules\photo\services\PhotoService; +use kernel\EntityRelation; +use kernel\Flash; use kernel\helpers\Debug; +use kernel\Request; + class PhotoController extends AdminController { private PhotoService $photoService; @@ -55,50 +59,19 @@ class PhotoController extends AdminController $this->cgView->render("view.php", ['photo' => $photo]); } -// /** -// * @throws Exception -// */ -// public function actionUpdate($id): void -// { -// $model = Tag::find($id); -// if (!$model){ -// throw new Exception(message: "The tag not found"); -// } -// -// $this->cgView->render("form.php", ['model' => $model]); -// } -// -// /** -// * @throws Exception -// */ -// public function actionEdit($id): void -// { -// $tag = Tag::find($id); -// if (!$tag){ -// throw new Exception(message: "The tag not found"); -// } -// $tagForm = new CreateTagForm(); -// $tagService = new TagService(); -// $tagForm->load($_REQUEST); -// if ($tagForm->validate()) { -// $tag = $tagService->update($tagForm, $tag); -// if ($tag) { -// $this->redirect("/admin/tag/view/" . $tag->id); -// } -// } -// $this->redirect("/admin/tag/update/" . $id); -// } -// -// #[NoReturn] public function actionDelete($id): void -// { -// $post = Tag::find($id)->first(); -// $post->delete(); -// $this->redirect("/admin/tag/"); -// } -// -// public function actionSettings(): void -// { -// $this->cgView->render('form.php'); -// } + public function actionSettings(): void + { + $this->cgView->render('settingsForm.php'); + } + + #[NoReturn] public function actionSaveSettings(): void + { + $request = new Request(); + $entities = $request->post('entity'); + EntityRelation::configurationEntitiesByProperty($entities, 'photo'); + + Flash::setMessage("success", "Настройка прошла успешно"); + $this->redirect("/admin/settings/photo", 302); + } } \ No newline at end of file diff --git a/kernel/app_modules/photo/routs/photo.php b/kernel/app_modules/photo/routs/photo.php index 4c74627..06d732e 100755 --- a/kernel/app_modules/photo/routs/photo.php +++ b/kernel/app_modules/photo/routs/photo.php @@ -16,5 +16,9 @@ App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router App::$collector->any("/edit/{id}", [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionEdit']); App::$collector->get('/delete/{id}', [\kernel\app_modules\photo\controllers\PhotoController::class]); }); + App::$collector->group(["prefix" => "settings"], function (CGRouteCollector $router) { + App::$collector->get('/photo', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionSettings']); + App::$collector->post('/photo/update', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionSaveSettings']); + }); }); }); \ No newline at end of file diff --git a/kernel/app_modules/photo/views/settingsForm.php b/kernel/app_modules/photo/views/settingsForm.php new file mode 100644 index 0000000..49d60bd --- /dev/null +++ b/kernel/app_modules/photo/views/settingsForm.php @@ -0,0 +1,46 @@ +beginForm("/admin/settings/photo/update"); + +?> + +