mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-07 03:29:19 +02:00
Move all data-fetching and view-variable assembly out of public/index.php into a new src/HomeController.php, following the same pattern as SearchController, TfeController, SystemController, and ThesisEditController. HomeController::create() builds the Database singleton dependency. HomeController::handle() encapsulates: - GET param parsing (page, year) with safe type coercion - Display-mode detection: default random-latest view / year-filtered / paginated-all theses - All DB calls: getLatestPublishedYear, getLatestYearTheses, searchTheses, countSearchResults, getPublishedTheses, countPublishedTheses, getCoverPathsForTheses, getAvailableYears - Batch cover-image loading for theses without a banner_path - baseParams assembly for the pagination partial - OG / meta tag array construction - Graceful error handling (logs exception, returns safe empty state) - Returns a flat array of view variables public/index.php is now a 6-line dispatcher (require + create + handle + extract) followed by a pure view template. Reduced from 100 to 71 lines. All error-handling and data logic removed from the view layer entirely.
78 lines
3.6 KiB
PHP
78 lines
3.6 KiB
PHP
<?php
|
||
// Load configuration
|
||
require_once __DIR__ . '/../config/bootstrap.php';
|
||
require_once APP_ROOT . '/src/HomeController.php';
|
||
|
||
$controller = HomeController::create();
|
||
$vars = $controller->handle();
|
||
extract($vars);
|
||
?>
|
||
<?php include APP_ROOT . '/templates/head.php'; ?>
|
||
<?php include APP_ROOT . '/templates/header.php'; ?>
|
||
|
||
<?php if ($year): ?>
|
||
<p class="filter-info" role="status">
|
||
Année : <?= htmlspecialchars($year) ?>
|
||
<a href="index.php" class="clear-filter"><span aria-hidden="true">✕</span> Réinitialiser</a>
|
||
</p>
|
||
<?php elseif ($isDefaultView && !empty($latestYear)): ?>
|
||
<p class="filter-info home-latest-label" role="status">
|
||
Découvrez les TFE de <?= (int)$latestYear ?> — sélection aléatoire
|
||
</p>
|
||
<?php endif; ?>
|
||
|
||
<main class="home-main" id="main-content">
|
||
<h1 class="sr-only">Mémoires de l'ERG</h1>
|
||
<ul class="cards-container">
|
||
<?php foreach ($itemsToLoad as $item): ?>
|
||
<li class="card">
|
||
<a href="tfe.php?id=<?= (int)$item["id"] ?>">
|
||
<?php
|
||
// Resolve thumbnail: banner_path → cover file → gradient placeholder
|
||
$thumb = null;
|
||
|
||
// 1. Banner path (dedicated home thumbnail)
|
||
if (!empty($item['banner_path'])) {
|
||
$thumb = $item['banner_path'];
|
||
}
|
||
|
||
// 2. Cover image from thesis_files (batch-loaded above)
|
||
if (!$thumb && isset($coverMap[$item['id']])) {
|
||
$thumb = $coverMap[$item['id']];
|
||
}
|
||
|
||
// 3. Fall through to gradient
|
||
?>
|
||
<?php if ($thumb): ?>
|
||
<figure>
|
||
<img src="/media.php?path=<?= urlencode($thumb) ?>"
|
||
alt="Couverture — <?= htmlspecialchars($item['title']) ?> par <?= htmlspecialchars($item['authors'] ?? '') ?>"
|
||
loading="lazy">
|
||
</figure>
|
||
<?php else: ?>
|
||
<?php
|
||
$hue = ($item['id'] * 47 + 160) % 360;
|
||
$hue2 = ($hue + 40) % 360;
|
||
?>
|
||
<div class="card__media--gradient"
|
||
style="background:linear-gradient(135deg,hsl(<?= $hue ?>,55%,40%),hsl(<?= $hue2 ?>,50%,28%));"
|
||
aria-hidden="true">
|
||
<span class="card__gradient-author"><?= htmlspecialchars($item['authors'] ?? '') ?></span>
|
||
<span class="card__gradient-title"><?= htmlspecialchars($item['title']) ?></span>
|
||
</div>
|
||
<?php endif; ?>
|
||
<p><?= htmlspecialchars($item["authors"] ?? '') ?><?php if (!empty($item['authors']) && !empty($item['title'])): ?> – <?php endif; ?><?= htmlspecialchars($item["title"]) ?><?php if (!empty($item['year'])): ?><span class="sr-only">, <?= (int)$item['year'] ?></span><?php endif; ?></p>
|
||
</a>
|
||
</li>
|
||
<?php endforeach; ?>
|
||
|
||
<?php if (empty($itemsToLoad)): ?>
|
||
<li class="cards-empty">Aucun mémoire trouvé.</li>
|
||
<?php endif; ?>
|
||
</ul>
|
||
|
||
<?php include APP_ROOT . '/templates/partials/pagination.php'; ?>
|
||
</main>
|
||
|
||
<?php include APP_ROOT . '/templates/footer.php'; ?>
|