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 = [];
|
||||
|
||||
Reference in new issue
Block a user