From e772a8b57f4b06deeeb2b9ecb0a2c1dc50920138 Mon Sep 17 00:00:00 2001
From: NOrtmann1
Date: Wed, 3 Jun 2026 19:29:29 +0200
Subject: [PATCH] Kategorien nicht statisch sondern dynamisch
---
content/home.php | 5 +
content/showCategory.php | 33 +++++++
includes/navbar.php | 104 ++++++++++-----------
php/controller/showCategory-controller.php | 20 ++++
php/model/ArticleManager.php | 21 +++++
php/model/ArticleManagerDAO.php | 7 ++
6 files changed, 138 insertions(+), 52 deletions(-)
create mode 100644 content/showCategory.php
create mode 100644 php/controller/showCategory-controller.php
diff --git a/content/home.php b/content/home.php
index 58e0993..878295a 100644
--- a/content/home.php
+++ b/content/home.php
@@ -17,6 +17,11 @@ include_once 'php/controller/home-controller.php';
Dein Beitrag wurde erfolgreich veröffentlicht!
+
+
+ Diese Kategorie ist nicht gültig.
+
+
diff --git a/content/showCategory.php b/content/showCategory.php
new file mode 100644
index 0000000..e07c14f
--- /dev/null
+++ b/content/showCategory.php
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Es sind noch keine Beiträge in dieser Kategorie enthalten.
+
+
+
+
\ No newline at end of file
diff --git a/includes/navbar.php b/includes/navbar.php
index b233584..2beb981 100644
--- a/includes/navbar.php
+++ b/includes/navbar.php
@@ -39,50 +39,50 @@ Globales Menü, wird via PHP später in alle Seiten eingebunden
Sprachen
MINT
Gesellschaft & Werte
Technik & Praxis
@@ -92,50 +92,50 @@ Globales Menü, wird via PHP später in alle Seiten eingebunden
Sprachen
MINT
Gesellschaft & Werte
Technik & Praxis
diff --git a/php/controller/showCategory-controller.php b/php/controller/showCategory-controller.php
new file mode 100644
index 0000000..59dda14
--- /dev/null
+++ b/php/controller/showCategory-controller.php
@@ -0,0 +1,20 @@
+getArticlesByCategory($category);
+ } catch (Exception $e) {
+ $_SESSION["message"] = "internal_error";
+ header("location: ../../index.php");
+ exit();
+ }
+}else{
+ $_SESSION["message"] = "invalid_category";
+ header("location: ../../index.php");
+ exit();
+}
+?>
\ No newline at end of file
diff --git a/php/model/ArticleManager.php b/php/model/ArticleManager.php
index 5887cc5..45325e0 100644
--- a/php/model/ArticleManager.php
+++ b/php/model/ArticleManager.php
@@ -44,5 +44,26 @@ class ArticleManager extends LocalArticleManager
return $articleManager;
}
+
+ public function getArticlesByCategory($category)
+ {
+ $articles = $this->getAllArticles();
+ $filteredArticles = [];
+
+ foreach ($articles as $article) {
+ if (isset($article['category']) && $article['category'] == $category) {
+ $filteredArticles[] = new Article(
+ intval($article['id']),
+ $article['title'],
+ $article['content'],
+ $article['author'],
+ $article['category'],
+ $article['tags'],
+ $article['creationDate']
+ );
+ }
+ }
+ return $filteredArticles;
+ }
}
\ No newline at end of file
diff --git a/php/model/ArticleManagerDAO.php b/php/model/ArticleManagerDAO.php
index 191b21a..d33df23 100644
--- a/php/model/ArticleManagerDAO.php
+++ b/php/model/ArticleManagerDAO.php
@@ -85,6 +85,13 @@ interface ArticleManagerDAO
*/
public function search(string $keyword): array;
+ /**
+ * Gibt alle Beiträge einer gegebenen Kategorie aus.
+ * @param $category
+ * @return mixed
+ */
+ public function getArticlesByCategory($category);
+
}
?>
\ No newline at end of file