feat: add year filter to main index

- Footer now displays all available years horizontally with scroll
- Click on year filters thesis list to that year
- Active year highlighted in footer
- 'Tous' link to reset filter
- Filter info banner shows when year selected with reset button
- Pagination preserves year filter
- Styled with horizontal scroll, smooth scrollbar
- Tests passing 
This commit is contained in:
Théophile Gervreau-Mercier
2026-02-12 12:26:32 +01:00
parent 942a93a3ad
commit 9511bb93b5
5 changed files with 121 additions and 14 deletions

View File

@@ -5,23 +5,43 @@ require_once APP_ROOT . '/src/Database.php';
$pageTitle = "Liste des TFE";
$page = isset($_GET["page"]) ? intval($_GET["page"]) : 1;
$year = isset($_GET["year"]) ? intval($_GET["year"]) : null;
$itemsPerPage = 10;
try {
$db = Database::getInstance();
$offset = ($page - 1) * $itemsPerPage;
$itemsToLoad = $db->getPublishedTheses($itemsPerPage, $offset);
$totalItems = $db->countPublishedTheses();
// Get available years for footer
$availableYears = $db->getAvailableYears();
// Filter by year if specified
if ($year) {
$itemsToLoad = $db->searchTheses(['year' => $year], $itemsPerPage, $offset);
$totalItems = $db->countSearchResults(['year' => $year]);
} else {
$itemsToLoad = $db->getPublishedTheses($itemsPerPage, $offset);
$totalItems = $db->countPublishedTheses();
}
$totalPages = ceil($totalItems / $itemsPerPage);
} catch (Exception $e) {
error_log("Error loading theses: " . $e->getMessage());
$itemsToLoad = [];
$totalPages = 0;
$availableYears = [];
}
include APP_ROOT . '/templates/header.php';
?>
<?php if ($year): ?>
<div class="filter-info">
Année : <?= htmlspecialchars($year) ?>
<a href="index.php" class="clear-filter">✕ Réinitialiser</a>
</div>
<?php endif; ?>
<main>
<?php foreach ($itemsToLoad as $item): ?>
<a href="memoire.php?id=<?= (int)$item["id"] ?>" class="card-link">
@@ -42,12 +62,15 @@ include APP_ROOT . '/templates/header.php';
<?php if ($totalPages > 1): ?>
<nav class="pagination">
<?php
$yearParam = $year ? '&year=' . (int)$year : '';
?>
<?php if ($page > 1): ?>
<a href="?page=<?= (int)($page - 1) ?>" class="pagination-previous">Précédent</a>
<a href="?page=<?= (int)($page - 1) . $yearParam ?>" class="pagination-previous">Précédent</a>
<?php endif; ?>
<?php if ($page < $totalPages): ?>
<a href="?page=<?= (int)($page + 1) ?>" class="pagination-next">Suivant</a>
<a href="?page=<?= (int)($page + 1) . $yearParam ?>" class="pagination-next">Suivant</a>
<?php endif; ?>
<span class="pagination-info">Page <?= (int)$page ?> sur <?= (int)$totalPages ?></span>