Extract pagination into templates/partials/pagination.php

The pagination nav was duplicated between public/index.php and public/search.php
with structural differences: index.php used string concatenation for query params
and had first/last-page buttons (« »); search.php used http_build_query but had
only prev/next (‹ ›) and a flat <span> rather than a <ul>/<li> structure.

- Add templates/partials/pagination.php: accepts $page, $totalPages, $baseParams[]
  (any array of query params to preserve); builds URLs with http_build_query;
  renders a semantic <nav>/<ul>/<li> block with first/prev/info/next/last buttons,
  correct aria-disabled + tabindex on disabled links, and aria-label on each button.
  Returns immediately (no output) when $totalPages <= 1.

- Replace inline pagination block in index.php with:
    $baseParams = array_filter(['year' => $year]);
    include pagination.php

- Replace inline pagination block in search.php with:
    $baseParams = array_diff_key($_GET, ['page' => '']);
    include pagination.php
  This also upgrades search.php to the full first/last button set it was missing.

Both callers verified with php -l. No functional change to existing behaviour.
This commit is contained in:
Pontoporeia
2026-04-02 12:20:31 +02:00
parent 0ab08f3aa0
commit 7834d88873
4 changed files with 72 additions and 49 deletions

View File

@@ -126,40 +126,10 @@ $bodyClass = 'home-body';
<?php endif; ?>
</ul>
<?php if ($totalPages > 1): ?>
<nav class="pagination-wrap" aria-label="Pagination">
<?php $yearParam = $year ? '&year=' . (int)$year : ''; ?>
<ul>
<li>
<a href="?page=1<?= $yearParam ?>"
class="pagination-btn <?= $page <= 1 ? 'disabled' : '' ?>"
<?= $page <= 1 ? 'aria-disabled="true" tabindex="-1"' : '' ?>
aria-label="Première page">«</a>
</li>
<li>
<a href="?page=<?= max(1, $page - 1) . $yearParam ?>"
class="pagination-btn <?= $page <= 1 ? 'disabled' : '' ?>"
<?= $page <= 1 ? 'aria-disabled="true" tabindex="-1"' : '' ?>
aria-label="Page précédente"></a>
</li>
<li class="pagination-info" aria-current="page">
<span class="page-current"><?= $page ?></span> / <?= $totalPages ?>
</li>
<li>
<a href="?page=<?= min($totalPages, $page + 1) . $yearParam ?>"
class="pagination-btn <?= $page >= $totalPages ? 'disabled' : '' ?>"
<?= $page >= $totalPages ? 'aria-disabled="true" tabindex="-1"' : '' ?>
aria-label="Page suivante"></a>
</li>
<li>
<a href="?page=<?= $totalPages . $yearParam ?>"
class="pagination-btn <?= $page >= $totalPages ? 'disabled' : '' ?>"
<?= $page >= $totalPages ? 'aria-disabled="true" tabindex="-1"' : '' ?>
aria-label="Dernière page">»</a>
</li>
</ul>
</nav>
<?php endif; ?>
<?php
$baseParams = array_filter(['year' => $year]);
include APP_ROOT . '/templates/partials/pagination.php';
?>
</main>
<?php include APP_ROOT . '/templates/footer.php'; ?>

View File

@@ -179,19 +179,11 @@ $bodyClass = 'search-body';
<?php endforeach; ?>
</ul>
<?php if ($totalPages > 1): ?>
<nav class="pagination-wrap" aria-label="Pagination">
<a href="?<?= http_build_query(array_merge($_GET, ['page' => max(1, $page - 1)])) ?>"
class="pagination-btn<?= $page <= 1 ? ' disabled' : '' ?>"
<?= $page <= 1 ? 'aria-disabled="true" tabindex="-1"' : '' ?>
aria-label="Page précédente"></a>
<span class="pagination-info" aria-current="page"><?= $page ?> / <?= $totalPages ?></span>
<a href="?<?= http_build_query(array_merge($_GET, ['page' => min($totalPages, $page + 1)])) ?>"
class="pagination-btn<?= $page >= $totalPages ? ' disabled' : '' ?>"
<?= $page >= $totalPages ? 'aria-disabled="true" tabindex="-1"' : '' ?>
aria-label="Page suivante"></a>
</nav>
<?php endif; ?>
<?php
// Preserve all active search/filter params (strip 'page' — injected by partial)
$baseParams = array_diff_key($_GET, ['page' => '']);
include APP_ROOT . '/templates/partials/pagination.php';
?>
<?php else: ?>
<p class="search-empty">Aucun résultat pour cette recherche.</p>