Kategorien nicht statisch sondern dynamisch #20
@@ -17,6 +17,11 @@ include_once 'php/controller/home-controller.php';
|
||||
Dein Beitrag wurde erfolgreich veröffentlicht!
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_category"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Diese Kategorie ist nicht gültig.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
unset($_SESSION["message"]);
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
include_once "php/controller/showCategory-controller.php";
|
||||
?>
|
||||
|
||||
<main>
|
||||
|
||||
<h1><?php if (isset($category) && !empty($category)){ echo htmlspecialchars($category); } ?></h1>
|
||||
|
||||
<div class="s-res-list">
|
||||
<?php
|
||||
if (!empty($articles)): ?>
|
||||
<?php foreach ($articles as $article): ?>
|
||||
<div class="s-res-item">
|
||||
<div class="s-res-content">
|
||||
<h2 class="s-res-item-title">
|
||||
<a href="index.php?pfad=showArticle&id=<?php echo $article['id']; ?>" class="s-res-link">
|
||||
<?php echo htmlspecialchars($article['title']); ?>
|
||||
</a>
|
||||
</h2>
|
||||
<p class="s-res-author">Von: <span class="s-res-author-name"><?php echo htmlspecialchars($article['author']); ?></span></p>
|
||||
</div>
|
||||
<div class="s-res-arrow">→</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php
|
||||
else: ?>
|
||||
<p> Es sind noch keine Beiträge in dieser Kategorie enthalten.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
</main>
|
||||
+52
-52
@@ -39,50 +39,50 @@ Globales Menü, wird via PHP später in alle Seiten eingebunden
|
||||
<li>
|
||||
<label class="nav__mobile-label">Sprachen</label>
|
||||
<ul class="nav__mobile-submenu">
|
||||
<li><a href="index.php?pfad=deutsch">Deutsch</a></li>
|
||||
<li><a href="index.php?pfad=englisch">Englisch</a></li>
|
||||
<li><a href="index.php?pfad=franzoesisch">Französisch</a></li>
|
||||
<li><a href="index.php?pfad=latein">Latein</a></li>
|
||||
<li><a href="index.php?pfad=literatur">Literatur</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=deutsch">Deutsch</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=englisch">Englisch</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=franzoesisch">Französisch</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=latein">Latein</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=literatur">Literatur</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<label class="nav__mobile-label">MINT</label>
|
||||
<ul class="nav__mobile-submenu">
|
||||
<li><a href="index.php?pfad=mathe">Mathematik</a></li>
|
||||
<li><a href="index.php?pfad=biologie">Biologie</a></li>
|
||||
<li><a href="index.php?pfad=chemie">Chemie</a></li>
|
||||
<li><a href="index.php?pfad=physik">Physik</a></li>
|
||||
<li><a href="index.php?pfad=informatik">Informatik</a></li>
|
||||
<li><a href="index.php?pfad=astronomie">Astronomie</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=mathe">Mathematik</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=biologie">Biologie</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=chemie">Chemie</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=physik">Physik</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=informatik">Informatik</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=astronomie">Astronomie</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<label class="nav__mobile-label">Gesellschaft & Werte</label>
|
||||
<ul class="nav__mobile-submenu">
|
||||
<li><a href="index.php?pfad=geschichte">Geschichte</a></li>
|
||||
<li><a href="index.php?pfad=erdkunde">Erdkunde</a></li>
|
||||
<li><a href="index.php?pfad=sozialkunde">Sozialkunde</a></li>
|
||||
<li><a href="index.php?pfad=wirtschaft">Wirtschaftskunde</a></li>
|
||||
<li><a href="index.php?pfad=religion">Religion</a></li>
|
||||
<li><a href="index.php?pfad=ethik">Ethikunterricht</a></li>
|
||||
<li><a href="index.php?pfad=philosophie">Philosophie</a></li>
|
||||
<li><a href="index.php?pfad=psychologie">Psychologie</a></li>
|
||||
<li><a href="index.php?pfad=kunst">Kunst</a></li>
|
||||
<li><a href="index.php?pfad=musik">Musik</a></li>
|
||||
<li><a href="index.php?pfad=theater">Theater</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=geschichte">Geschichte</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=erdkunde">Erdkunde</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=sozialkunde">Sozialkunde</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=wirtschaft">Wirtschaftskunde</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=religion">Religion</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=ethik">Ethikunterricht</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=philosophie">Philosophie</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=psychologie">Psychologie</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=kunst">Kunst</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=musik">Musik</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=theater">Theater</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<label class="nav__mobile-label">Technik & Praxis</label>
|
||||
<ul class="nav__mobile-submenu">
|
||||
<li><a href="index.php?pfad=technik">Technik</a></li>
|
||||
<li><a href="index.php?pfad=werken">Werken</a></li>
|
||||
<li><a href="index.php?pfad=hauswirtschaft">Hauswirtschaft</a></li>
|
||||
<li><a href="index.php?pfad=sport">Sport</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=technik">Technik</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=werken">Werken</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=hauswirtschaft">Hauswirtschaft</a></li>
|
||||
<li><a href="index.php?pfad=showCategory&category=sport">Sport</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -92,50 +92,50 @@ Globales Menü, wird via PHP später in alle Seiten eingebunden
|
||||
<div class="nav__item nav__dropdown">
|
||||
<button class="nav__dropdown-toggle">Sprachen</button>
|
||||
<div class="nav__dropdown-menu">
|
||||
<a href="index.php?pfad=deutsch">Deutsch</a>
|
||||
<a href="index.php?pfad=englisch">Englisch</a>
|
||||
<a href="index.php?pfad=franzoesisch">Französisch</a>
|
||||
<a href="index.php?pfad=latein">Latein</a>
|
||||
<a href="index.php?pfad=literatur">Literatur</a>
|
||||
<a href="index.php?pfad=showCategory&category=deutsch">Deutsch</a>
|
||||
<a href="index.php?pfad=showCategory&category=englisch">Englisch</a>
|
||||
<a href="index.php?pfad=showCategory&category=franzoesisch">Französisch</a>
|
||||
<a href="index.php?pfad=showCategory&category=latein">Latein</a>
|
||||
<a href="index.php?pfad=showCategory&category=literatur">Literatur</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="nav__item nav__dropdown">
|
||||
<button class="nav__dropdown-toggle">MINT</button>
|
||||
<div class="nav__dropdown-menu">
|
||||
<a href="index.php?pfad=mathe">Mathematik</a>
|
||||
<a href="index.php?pfad=biologie">Biologie</a>
|
||||
<a href="index.php?pfad=chemie">Chemie</a>
|
||||
<a href="index.php?pfad=physik">Physik</a>
|
||||
<a href="index.php?pfad=informatik">Informatik</a>
|
||||
<a href="index.php?pfad=astronomie">Astronomie</a>
|
||||
<a href="index.php?pfad=showCategory&category=mathe">Mathematik</a>
|
||||
<a href="index.php?pfad=showCategory&category=biologie">Biologie</a>
|
||||
<a href="index.php?pfad=showCategory&category=chemie">Chemie</a>
|
||||
<a href="index.php?pfad=showCategory&category=physik">Physik</a>
|
||||
<a href="index.php?pfad=showCategory&category=informatik">Informatik</a>
|
||||
<a href="index.php?pfad=showCategory&category=astronomie">Astronomie</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="nav__item nav__dropdown">
|
||||
<button class="nav__dropdown-toggle">Gesellschaft & Werte</button>
|
||||
<div class="nav__dropdown-menu">
|
||||
<a href="index.php?pfad=geschichte">Geschichte</a>
|
||||
<a href="index.php?pfad=erdkunde">Erdkunde</a>
|
||||
<a href="index.php?pfad=sozialkunde">Sozialkunde</a>
|
||||
<a href="index.php?pfad=wirtschaft">Wirtschaftskunde</a>
|
||||
<a href="index.php?pfad=religion">Religion</a>
|
||||
<a href="index.php?pfad=ethik">Ethikunterricht</a>
|
||||
<a href="index.php?pfad=philosophie">Philosophie</a>
|
||||
<a href="index.php?pfad=psychologie">Psychologie</a>
|
||||
<a href="index.php?pfad=kunst">Kunst</a>
|
||||
<a href="index.php?pfad=musik">Musik</a>
|
||||
<a href="index.php?pfad=theater">Theater</a>
|
||||
<a href="index.php?pfad=showCategory&category=geschichte">Geschichte</a>
|
||||
<a href="index.php?pfad=showCategory&category=erdkunde">Erdkunde</a>
|
||||
<a href="index.php?pfad=showCategory&category=sozialkunde">Sozialkunde</a>
|
||||
<a href="index.php?pfad=showCategory&category=wirtschaft">Wirtschaftskunde</a>
|
||||
<a href="index.php?pfad=showCategory&category=religion">Religion</a>
|
||||
<a href="index.php?pfad=showCategory&category=ethik">Ethikunterricht</a>
|
||||
<a href="index.php?pfad=showCategory&category=philosophie">Philosophie</a>
|
||||
<a href="index.php?pfad=showCategory&category=psychologie">Psychologie</a>
|
||||
<a href="index.php?pfad=showCategory&category=kunst">Kunst</a>
|
||||
<a href="index.php?pfad=showCategory&category=musik">Musik</a>
|
||||
<a href="index.php?pfad=showCategory&category=theater">Theater</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="nav__item nav__dropdown">
|
||||
<button class="nav__dropdown-toggle">Technik & Praxis</button>
|
||||
<div class="nav__dropdown-menu">
|
||||
<a href="index.php?pfad=technik">Technik</a>
|
||||
<a href="index.php?pfad=werken">Werken</a>
|
||||
<a href="index.php?pfad=hauswirtschaft">Hauswirtschaft</a>
|
||||
<a href="index.php?pfad=sport">Sport</a>
|
||||
<a href="index.php?pfad=showCategory&category=technik">Technik</a>
|
||||
<a href="index.php?pfad=showCategory&category=werken">Werken</a>
|
||||
<a href="index.php?pfad=showCategory&category=hauswirtschaft">Hauswirtschaft</a>
|
||||
<a href="index.php?pfad=showCategory&category=sport">Sport</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
?>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user