Kategorien nicht statisch sondern dynamisch

This commit is contained in:
2026-06-03 19:29:29 +02:00
parent 9c3ebc9877
commit e772a8b57f
6 changed files with 138 additions and 52 deletions
@@ -0,0 +1,20 @@
<?php
require_once '../model/LocalArticleManager.php';
require_once '../model/ArticleManager.php';
if (isset($_GET["category"]) && !empty($_GET["category"]) && articleCategoryValidator($_GET["category"])){
$category = $_GET["category"];
try {
$articleManager = ArticleManager::getInstance();
$articles = $articleManager->getArticlesByCategory($category);
} catch (Exception $e) {
$_SESSION["message"] = "internal_error";
header("location: ../../index.php");
exit();
}
}else{
$_SESSION["message"] = "invalid_category";
header("location: ../../index.php");
exit();
}
?>
+21
View File
@@ -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;
}
}
+7
View File
@@ -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);
}
?>