49 lines
1.7 KiB
PHP
49 lines
1.7 KiB
PHP
<?php
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
session_start();
|
|
}
|
|
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();
|
|
|
|
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";
|
|
}
|
|
?>
|