Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1dd128d480 | |||
| dca716ddc5 | |||
| c1dd4fce2b | |||
| 16cfa92721 | |||
| 3b2ed78c1c |
+51
-22
@@ -2,31 +2,60 @@
|
|||||||
include_once "php/controller/showCategory-controller.php";
|
include_once "php/controller/showCategory-controller.php";
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<main>
|
<div class="category-results-container">
|
||||||
<?php include_once "includes/alertMessages.php"?>
|
<!-- Kategorie-Titel sicher ausgeben -->
|
||||||
|
<h1>Kategorie: <?php echo (isset($category) && !empty($category)) ? htmlspecialchars($category) : 'Unbekannt'; ?></h1>
|
||||||
|
|
||||||
<h1><?php if (isset($category) && !empty($category)){ echo htmlspecialchars($category); } ?></h1>
|
<!-- 1. Die Artikel-Liste ausgeben -->
|
||||||
|
<div class="articles-list">
|
||||||
<div class="s-res-list">
|
<?php if (isset($articles) && !empty($articles)): ?>
|
||||||
<?php
|
|
||||||
if (!empty($articles)): ?>
|
|
||||||
<?php foreach ($articles as $article): ?>
|
<?php foreach ($articles as $article): ?>
|
||||||
<div class="s-res-item">
|
<article class="article-item">
|
||||||
<div class="s-res-content">
|
<!-- Sichere Objektausrufe über die Getter-Methoden -->
|
||||||
<h2 class="s-res-item-title">
|
<h2><?php echo (isset($article) && !empty($article->getTitle())) ? htmlspecialchars($article->getTitle()) : 'Kein Titel'; ?></h2>
|
||||||
<a href="index.php?pfad=showArticle&id=<?php echo $article->getId(); ?>" class="s-res-link">
|
<p><?php echo (isset($article) && !empty($article->getContent())) ? htmlspecialchars($article->getContent()) : 'Kein Inhalt'; ?></p>
|
||||||
<?php echo htmlspecialchars($article->getTitle()); ?>
|
</article>
|
||||||
</a>
|
|
||||||
</h2>
|
|
||||||
<p class="s-res-author">Von: <span class="s-res-author-name"><?php echo htmlspecialchars($article->getAuthor()); ?></span></p>
|
|
||||||
</div>
|
|
||||||
<div class="s-res-arrow">→</div>
|
|
||||||
</div>
|
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php
|
<?php else: ?>
|
||||||
else: ?>
|
<p>Keine Artikel in dieser Kategorie gefunden.</p>
|
||||||
<p> Es sind noch keine Beiträge in dieser Kategorie enthalten.</p>
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</main>
|
<!-- 2. Der Paginator (Greift nur, wenn mehr als eine Seite existiert) -->
|
||||||
|
<?php if (isset($totalPages) && $totalPages > 1): ?>
|
||||||
|
<form id="search-form-id" action="index.php" method="GET" style="display: inline;">
|
||||||
|
|
||||||
|
<!-- Pfad und Kategorie als versteckte Felder mitsenden -->
|
||||||
|
<input type="hidden" name="pfad" value="showCategory">
|
||||||
|
<input type="hidden" name="category" value="<?php echo (isset($category) && !empty($category)) ? htmlspecialchars($category) : ''; ?>">
|
||||||
|
|
||||||
|
<!-- Das Feld, das dein JS-Paginator befüllt (Nutzt Kurzform ?? für Fallback) -->
|
||||||
|
<input type="hidden" id="s-res-page-input" name="page" value="<?php echo (isset($page) && !empty($page)) ? $page : 1; ?>">
|
||||||
|
|
||||||
|
<!-- Die Navigations-Buttons -->
|
||||||
|
<div class="s-res-page-navigation">
|
||||||
|
|
||||||
|
<!-- Zurück-Button -->
|
||||||
|
<?php $currentPage = $page ?? 1; ?>
|
||||||
|
<button type="button" class="s-res-page-btn" data-page="<?php echo $currentPage - 1; ?>" <?php echo ($currentPage <= 1) ? 'disabled' : ''; ?>>
|
||||||
|
« Zurück
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- Seitenzahlen generieren -->
|
||||||
|
<?php for ($i = 1; $i <= $totalPages; $i++): ?>
|
||||||
|
<button type="button"
|
||||||
|
class="s-res-page-btn <?php echo ($i === $currentPage) ? 'active' : ''; ?>"
|
||||||
|
data-page="<?php echo $i; ?>"
|
||||||
|
<?php echo ($i === $currentPage) ? 'disabled' : ''; ?>>
|
||||||
|
<?php echo $i; ?>
|
||||||
|
</button>
|
||||||
|
<?php endfor; ?>
|
||||||
|
|
||||||
|
<!-- Vor-Button -->
|
||||||
|
<button type="button" class="s-res-page-btn" data-page="<?php echo $currentPage + 1; ?>" <?php echo ($currentPage >= $totalPages) ? 'disabled' : ''; ?>>
|
||||||
|
Weiter »
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -1,21 +1,41 @@
|
|||||||
<?php
|
<?php
|
||||||
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
require_once 'php/model/Article.php';
|
require_once 'php/model/Article.php';
|
||||||
require_once 'php/model/ArticleManager.php';
|
require_once 'php/model/ArticleManager.php';
|
||||||
require_once 'php/validator/article-validator.php';
|
require_once 'php/validator/article-validator.php';
|
||||||
|
|
||||||
if (isset($_GET["category"]) && !empty($_GET["category"]) && articleCategoryValidator($_GET["category"])){
|
if (isset($_GET["category"]) && !empty($_GET["category"]) && articleCategoryValidator($_GET["category"])){
|
||||||
$category = $_GET["category"];
|
$category = $_GET["category"];
|
||||||
|
|
||||||
|
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
|
||||||
|
if ($page < 1) { $page = 1; }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$articleManager = ArticleManager::getInstance();
|
$articleManager = ArticleManager::getInstance();
|
||||||
$articles = $articleManager->getArticlesByCategory($category);
|
|
||||||
|
$allArticles = $articleManager->getArticlesByCategory($category);
|
||||||
|
|
||||||
|
// Paginierung konfigurieren
|
||||||
|
$limit = 10; // Wie viele Artikel pro Seite?
|
||||||
|
$totalArticles = count($allArticles);
|
||||||
|
$totalPages = ceil($totalArticles / $limit);
|
||||||
|
|
||||||
|
if ($page > $totalPages && $totalPages > 0) { $page = $totalPages; }
|
||||||
|
|
||||||
|
$offset = ($page - 1) * $limit;
|
||||||
|
$articles = array_slice($allArticles, $offset, $limit);
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$_SESSION["message"] = "internal_error";
|
$_SESSION["message"] = "internal_error";
|
||||||
include_once "content/404.php";
|
include_once "content/404.php";
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
$_SESSION["message"] = "invalid_category";
|
$_SESSION["message"] = "invalid_category";
|
||||||
include_once "content/404.php";
|
include_once "content/404.php";
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user