Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4321c4bee5 |
Generated
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="dataSourceStorageLocal" created-in="IU-253.32098.101">
|
||||
<component name="dataSourceStorageLocal" created-in="IU-261.25134.95">
|
||||
<data-source name="articles" uuid="315cb5c9-2b0f-435b-b602-59823b160908">
|
||||
<database-info product="SQLite" version="3.51.1" jdbc-version="4.2" driver-name="SQLite JDBC" driver-version="3.51.1.0" dbms="SQLITE" exact-version="3.51.1" exact-driver-version="3.51">
|
||||
<identifier-quote-string>"</identifier-quote-string>
|
||||
|
||||
+27
-21
@@ -19,28 +19,34 @@ include_once 'php/controller/home-controller.php';
|
||||
sea takimata sanctus est Lorem ipsum dolor sit amet.
|
||||
</p>
|
||||
|
||||
<!-- Flexbox -->
|
||||
<div class="flexbox">
|
||||
<div class="container">
|
||||
<a href="index.php?pfad=showCategory&category=informatik" class="category-link">Informatik</a>
|
||||
<div class="article-link">
|
||||
<a href="index.php?pfad=showArticle&id=<?php echo $dummy3->getId()?>"><?php if(isset($dummy3)){echo $dummy3->getTitle();}else{echo "Fehler: Beitrag nicht gefunden!";} ?></a>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Flexbox für aktive Kategorien -->
|
||||
<div class="flexbox">
|
||||
<?php
|
||||
if (!empty($categoriesWithArticles) && is_array($categoriesWithArticles)):
|
||||
foreach ($categoriesWithArticles as $category):
|
||||
?>
|
||||
<div class="container">
|
||||
<a href="index.php?pfad=showCategory&category=<?php echo htmlspecialchars($category['slug']); ?>" class="category-link">
|
||||
<?php echo htmlspecialchars($category['name']); ?>
|
||||
</a>
|
||||
|
||||
<div class="container">
|
||||
<a href="index.php?pfad=showCategory&category=mathe" class="category-link">Mathe</a>
|
||||
<div class="article-link">
|
||||
<a href="index.php?pfad=showArticle&id=<?php echo $dummy1->getId()?>"><?php if(isset($dummy1)){echo $dummy1->getTitle();}else{echo "Fehler: Beitrag nicht gefunden!";} ?></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<a href="index.php?pfad=showCategory&category=physik" class="category-link">Physik</a>
|
||||
<div class="article-link">
|
||||
<a href="index.php?pfad=showArticle&id=<?php echo $dummy2->getId()?>"><?php if(isset($dummy2)){echo $dummy2->getTitle();}else{echo "Fehler: Beitrag nicht gefunden!";} ?></a>
|
||||
</div>
|
||||
</div>
|
||||
<!-- die 5 neuesten Beiträge der Kategorie -->
|
||||
<div class="article-links-wrapper">
|
||||
<?php foreach ($category['articles'] as $article): ?>
|
||||
<div class="article-link">
|
||||
<a href="index.php?pfad=showArticle&id=<?php echo htmlspecialchars($article->getId()); ?>">
|
||||
<?php echo htmlspecialchars($article->getTitle()); ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
endforeach;
|
||||
else:
|
||||
?>
|
||||
<p>Aktuell sind keine Beiträge in den Kategorien vorhanden.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
</main>
|
||||
@@ -6,14 +6,44 @@ require_once 'php/model/Article.php';
|
||||
require_once 'php/model/ArticleManager.php';
|
||||
require_once 'php/model/LocalArticleManager.php';
|
||||
|
||||
$categoriesWithArticles = [];
|
||||
|
||||
$allowedCategories = [
|
||||
'deutsch', 'englisch', 'franzoesisch', 'latein', 'literatur',
|
||||
'mathe', 'biologie', 'chemie', 'physik', 'informatik', 'astronomie',
|
||||
'geschichte', 'erdkunde', 'sozialkunde', 'wirtschaft', 'religion',
|
||||
'ethik', 'philosophie', 'psychologie', 'kunst', 'musik', 'theater',
|
||||
'technik', 'werken', 'hauswirtschaft', 'sport'
|
||||
];
|
||||
|
||||
try {
|
||||
$articleManager = ArticleManager::getInstance();
|
||||
// Beziehen der Dummy-Beiträge aus dem ArticleManager:
|
||||
$dummy1 = $articleManager->getArticle(1);
|
||||
$dummy2 = $articleManager->getArticle(2);
|
||||
$dummy3 = $articleManager->getArticle(3);
|
||||
|
||||
foreach ($allowedCategories as $categorySlug) {
|
||||
$allCategoryArticles = $articleManager->getArticlesByCategory($categorySlug);
|
||||
|
||||
// nur Kategorien, die Beiträge enthält:
|
||||
if (!empty($allCategoryArticles) && is_array($allCategoryArticles)) {
|
||||
|
||||
// Beiträge nach Erstellungsdatum sortieren:
|
||||
usort($allCategoryArticles, function($a, $b) {
|
||||
$dateA = strtotime($a->getCreationDate());
|
||||
$dateB = strtotime($b->getCreationDate());
|
||||
return $dateB <=> $dateA; // Absteigende Sortierung
|
||||
});
|
||||
|
||||
// auf die 5 zuletzt hinzugefügten Beiträge begrenzen:
|
||||
$limitedArticles = array_slice($allCategoryArticles, 0, 5);
|
||||
|
||||
$categoriesWithArticles[] = [
|
||||
'slug' => $categorySlug,
|
||||
'name' => ucfirst($categorySlug), // Erster Buchstabe groß für die Ansicht
|
||||
'articles' => $limitedArticles
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception $e){
|
||||
$_SESSION["message"] = "internal_error";
|
||||
echo "Fehler aufgetreten: " . $e->getMessage();
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user