feat(site): navbar links only sections with content, Galeria link, brand-tinted gallery background
This commit is contained in:
1 parent
1eb2a61031
commit
49adbd0ae1
2 files changed
+27
-6
No files matched your search
@@ -29,16 +29,37 @@ function site_info(PDO $pdo, ?int $gym_id = null): array {
|
||||
return $row;
|
||||
}
|
||||
|
||||
/** Whether the home page renders section $sec for $gym (same data checks as site/index.php). */
|
||||
function site_section_has_content(array $gym, string $sec): bool {
|
||||
$pdo = $GLOBALS['pdo'] ?? null;
|
||||
$gid = (int) $gym['id'];
|
||||
if (!$pdo && $sec !== 'galeria') return true;
|
||||
return match ($sec) {
|
||||
'modalidades' => (bool) site_modalidades($pdo, $gid),
|
||||
'equipa' => (bool) site_team_active($pdo, $gid),
|
||||
'horario' => (bool) site_horario($pdo, '', $gid),
|
||||
'mensalidades' => (bool) site_memberships($pdo, $gid),
|
||||
'galeria' => !empty($gym['gallery_id']) && preg_grep('/\.(jpe?g|png|gif|webp|jxl)$/i',
|
||||
glob(dirname(__DIR__) . '/uploads/gallery/' . (int) $gym['gallery_id'] . '/*') ?: []),
|
||||
default => true,
|
||||
};
|
||||
}
|
||||
|
||||
/** Team members shown on the site (status «ativo»). */
|
||||
function site_team_active(PDO $pdo, ?int $gym_id = null): array {
|
||||
return array_values(array_filter(site_team($pdo, $gym_id), fn($d) => ($d['status'] ?? '') === 'ativo'));
|
||||
}
|
||||
|
||||
// Top navigation (label => absolute URL): anchors on the gym's own page, only
|
||||
// for the sections that gym shows, plus its CrossFit page when it has one.
|
||||
// for the sections that gym shows and has content for, plus its CrossFit page when it has one.
|
||||
function site_navbar(?array $gym = null): array {
|
||||
$gym = $gym ?? current_gym();
|
||||
$items = ['Home' => ['#home', null]];
|
||||
foreach (['Modalidades' => 'modalidades', 'Equipa' => 'equipa', 'Horário' => 'horario',
|
||||
foreach (['Galeria' => 'galeria', 'Modalidades' => 'modalidades', 'Equipa' => 'equipa', 'Horário' => 'horario',
|
||||
'Mensalidades' => 'mensalidades', 'Contactos' => 'contactos'] as $label => $sec) {
|
||||
if (!gym_section_on($gym, $sec)) continue;
|
||||
// No active plans → the section isn't rendered, so no link to it either.
|
||||
if ($sec === 'mensalidades' && !empty($GLOBALS['pdo']) && !site_memberships($GLOBALS['pdo'], (int) $gym['id'])) continue;
|
||||
// A section with nothing to show isn't rendered, so no link to it either.
|
||||
if (!site_section_has_content($gym, $sec)) continue;
|
||||
$items[$label] = ['#' . $sec, $sec];
|
||||
}
|
||||
$nav = [];
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ require __DIR__ . '/_open.php'; // resolves $gym (404 if unknown / not visible
|
||||
$gid = (int) $gym['id'];
|
||||
$on = fn(string $key) => gym_section_on($gym, $key);
|
||||
$offer = $on('oferta') ? site_offer($pdo, $gid) : [];
|
||||
$team = $on('equipa') ? site_team($pdo, $gid) : [];
|
||||
$team = $on('equipa') ? site_team_active($pdo, $gid) : [];
|
||||
$modalidades = $on('modalidades') ? site_modalidades($pdo, $gid) : [];
|
||||
$horario = $on('horario') ? site_horario($pdo, '', $gid) : [];
|
||||
$whours = $on('workhours') ? site_work_hours($pdo, $gid) : [];
|
||||
@@ -121,7 +121,7 @@ $gallery_files = ($on('galeria') && $gallery_path !== '') ? preg_grep('/\.(jpe?g
|
||||
if ($gallery_files && count($gallery_files) > 0):
|
||||
$gallery_h2 = 'Conhece as nossas instalações';
|
||||
?>
|
||||
<section id="galeria" class="gallery-section" style="padding:70px 0 0;background:var(--fitme-white)">
|
||||
<section id="galeria" class="gallery-section" style="padding:70px 0 0;background:color-mix(in srgb, var(--fitme-accent) 7%, #fff)">
|
||||
<?php include __DIR__ . '/includes/gallery.php'; ?>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
Reference in new issue
Block a user