diff --git a/src/Controllers/SiteController.php b/src/Controllers/SiteController.php index c6da7ba..91d3a28 100644 --- a/src/Controllers/SiteController.php +++ b/src/Controllers/SiteController.php @@ -109,13 +109,21 @@ class SiteController extends Controller $topics = Topic::findBySiteWithGlobal((int) $id); $globalTopics = GlobalTopic::findAllGrouped(); - $assignedGlobalIds = array_filter(array_column($topics, 'global_topic_id')); + $assignedGlobalIds = array_values(array_unique(array_map( + static fn($v) => (int) $v, + array_filter(array_column($topics, 'global_topic_id')) + ))); + $assignedTopicNames = array_values(array_unique(array_filter(array_map( + static fn($name) => mb_strtolower(trim((string) $name)), + array_column($topics, 'name') + )))); $this->view('sites/edit', [ 'site' => $site, 'topics' => $topics, 'globalTopics' => $globalTopics, 'assignedGlobalIds' => $assignedGlobalIds, + 'assignedTopicNames' => $assignedTopicNames, ]); } diff --git a/src/Controllers/TopicController.php b/src/Controllers/TopicController.php index 507b74f..f890937 100644 --- a/src/Controllers/TopicController.php +++ b/src/Controllers/TopicController.php @@ -24,8 +24,22 @@ class TopicController extends Controller $topics = Topic::findBySiteWithGlobal((int) $id); $globalTopics = GlobalTopic::findAllGrouped(); + $assignedGlobalIds = array_values(array_unique(array_map( + static fn($v) => (int) $v, + array_filter(array_column($topics, 'global_topic_id')) + ))); + $assignedTopicNames = array_values(array_unique(array_filter(array_map( + static fn($name) => mb_strtolower(trim((string) $name)), + array_column($topics, 'name') + )))); - $this->view('topics/index', ['site' => $site, 'topics' => $topics, 'globalTopics' => $globalTopics]); + $this->view('topics/index', [ + 'site' => $site, + 'topics' => $topics, + 'globalTopics' => $globalTopics, + 'assignedGlobalIds' => $assignedGlobalIds, + 'assignedTopicNames' => $assignedTopicNames, + ]); } public function store(string $id): void @@ -51,7 +65,7 @@ class TopicController extends Controller ]); $this->flash('success', 'Temat został dodany.'); - $this->redirect("/sites/{$id}/topics"); + $this->redirect("/sites/{$id}/topics?topic_added=1"); } public function update(string $id): void diff --git a/templates/sites/edit.php b/templates/sites/edit.php index 9cf4150..906e6f4 100644 --- a/templates/sites/edit.php +++ b/templates/sites/edit.php @@ -180,128 +180,18 @@
-
-
-
Tematy ()
- - Zarządzaj - -
-
- -
Brak tematów. Dodaj z biblioteki poniżej.
- - - - - - - - - - - - - - - - - - - - -
TematKategoriaArt.
- - - off - - - -
- -
-
-
-
Dodaj temat z biblioteki
+
Tematy strony
-
-
- -
- - - - -
+

+ Zarządzanie tematami zostało przeniesione do dedykowanego widoku, aby nie duplikować miejsc edycji. +

+ + Przejdź do zarządzania tematami +
- - diff --git a/templates/topics/index.php b/templates/topics/index.php index 0189a82..eb1b235 100644 --- a/templates/topics/index.php +++ b/templates/topics/index.php @@ -97,6 +97,16 @@
+
@@ -105,6 +115,12 @@ + +