feat: cover image fallback for home grid cards

- index.php: batch-load thesis_files covers for theses without banner_path
- Resolution order: banner_path → cover file → gradient placeholder
- Uses single IN() query to avoid N+1 problem
This commit is contained in:
Pontoporeia
2026-03-24 15:39:23 +01:00
parent 372abb5cd6
commit ed2b06a34c
2 changed files with 27 additions and 2 deletions

View File

@@ -322,7 +322,7 @@ Goal: rename the tables and column to the canonical M2M pattern (`tags`, `thesis
- [x] Add flake.nix for Nix-based PHP dev environment - [x] Add flake.nix for Nix-based PHP dev environment
- [x] Add favicon (`<link rel="icon">` → admin_favicon.svg) to all pages; nginx 204 for /favicon.ico - [x] Add favicon (`<link rel="icon">` → admin_favicon.svg) to all pages; nginx 204 for /favicon.ico
- [x] Remove 100-item cap from répertoire student index: `getAllPublishedTheses()` fetches all published theses; search results remain paginated at 30/page - [x] Remove 100-item cap from répertoire student index: `getAllPublishedTheses()` fetches all published theses; search results remain paginated at 30/page
- [ ] Thumbnail generation / cover image support for home grid cards - [x] Cover image fallback for home grid cards: batch-load `thesis_files` covers for theses without `banner_path`; resolution order: banner → cover → gradient
## Admin / Server ## Admin / Server

View File

@@ -28,6 +28,26 @@ try {
} }
$totalPages = $isDefaultView ? 1 : (int)ceil($totalItems / $itemsPerPage); $totalPages = $isDefaultView ? 1 : (int)ceil($totalItems / $itemsPerPage);
// Batch-load cover images for theses that have no banner_path
$coverMap = [];
if (!empty($itemsToLoad)) {
$needCover = array_column(
array_filter($itemsToLoad, fn($t) => empty($t['banner_path'])),
'id'
);
if (!empty($needCover)) {
$ph = implode(',', array_fill(0, count($needCover), '?'));
$cStmt = $db->getConnection()->prepare("
SELECT thesis_id, file_path FROM thesis_files
WHERE file_type = 'cover' AND thesis_id IN ($ph)
");
$cStmt->execute($needCover);
foreach ($cStmt->fetchAll() as $row) {
$coverMap[$row['thesis_id']] = $row['file_path'];
}
}
}
} catch (Exception $e) { } catch (Exception $e) {
error_log("Error loading theses: " . $e->getMessage()); error_log("Error loading theses: " . $e->getMessage());
$itemsToLoad = []; $itemsToLoad = [];
@@ -36,6 +56,7 @@ try {
$totalItems = 0; $totalItems = 0;
$latestYear = null; $latestYear = null;
$isDefaultView = false; $isDefaultView = false;
$coverMap = [];
} }
$currentNav = ''; $currentNav = '';
@@ -91,7 +112,11 @@ $currentNav = '';
$thumb = $item['banner_path']; $thumb = $item['banner_path'];
} }
// 2. Cover image from thesis_files (not returned by view — skip for now) // 2. Cover image from thesis_files (batch-loaded above)
if (!$thumb && isset($coverMap[$item['id']])) {
$thumb = $coverMap[$item['id']];
}
// 3. Fall through to gradient // 3. Fall through to gradient
?> ?>
<?php if ($thumb): ?> <?php if ($thumb): ?>