asddad
All checks were successful
Deploy / deploy (push) Successful in 49s

This commit is contained in:
2026-07-19 22:08:55 +02:00
parent b9673814b5
commit b9026c7808
6 changed files with 319 additions and 13 deletions

View File

@@ -140,16 +140,12 @@ final class Community
$params[$ph2] = '%' . $tok . '%';
$i++;
}
$defaultBoard = $this->getBoardBySlug('wochenendideen');
$boardJoin = '';
$boardSelect = "NULL AS board_slug, NULL AS board_title, NULL AS category_slug, NULL AS category_title";
$boardWhere = '';
if ($this->hasColumn('forum_threads', 'board_id') && $this->hasTable('forum_boards') && $this->hasTable('forum_categories')) {
$boardJoin = ' LEFT JOIN forum_boards fb ON fb.id = ft.board_id LEFT JOIN forum_categories fc ON fc.id = fb.category_id ';
$boardSelect = 'fb.slug AS board_slug, fb.title AS board_title, fc.slug AS category_slug, fc.title AS category_title';
if ($boardSlug !== null && $boardSlug !== '') {
$boardWhere = ' AND fb.slug = :boardSlug';
$params[':boardSlug'] = $boardSlug;
}
}
$where = $conditions ? ('AND ' . implode(' AND ', $conditions)) : '';
@@ -182,7 +178,7 @@ final class Community
JOIN users u ON u.id = ft.user_id
LEFT JOIN user_profiles p ON p.user_id = u.id
$boardJoin
WHERE 1=1 $where $boardWhere
WHERE 1=1 $where
ORDER BY ft.created_at DESC
LIMIT :lim";
$stmt = $this->pdo->prepare($sql);
@@ -191,7 +187,12 @@ final class Community
}
$stmt->bindValue(':lim', $limit, \PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetchAll(\PDO::FETCH_ASSOC) ?: [];
$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC) ?: [];
$rows = array_map(fn(array $row) => $this->applyFallbackBoard($row, $defaultBoard), $rows);
if ($boardSlug !== null && $boardSlug !== '') {
$rows = array_values(array_filter($rows, fn(array $row): bool => (string)($row['board_slug'] ?? '') === $boardSlug));
}
return $rows;
}
public function listThreads(int $limit = 50, ?string $boardSlug = null): array
@@ -210,7 +211,10 @@ final class Community
$stmt = $this->pdo->prepare("SELECT $select FROM forum_threads ft LEFT JOIN user_profiles p ON p.user_id = ft.user_id $join WHERE ft.id = :id");
$stmt->execute([':id' => $id]);
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
return $row ?: null;
if (!$row) {
return null;
}
return $this->applyFallbackBoard($row, $this->getBoardBySlug('wochenendideen'));
}
public function listPosts(int $threadId): array
@@ -477,6 +481,19 @@ final class Community
}
}
private function applyFallbackBoard(array $row, ?array $defaultBoard): array
{
if (!empty($row['board_slug']) || !$defaultBoard) {
return $row;
}
$row['board_slug'] = $defaultBoard['slug'] ?? null;
$row['board_title'] = $defaultBoard['title'] ?? null;
$row['category_slug'] = $defaultBoard['category_slug'] ?? null;
$row['category_title'] = $defaultBoard['category_title'] ?? null;
return $row;
}
private function hasTable(string $table): bool
{
if (array_key_exists($table, $this->tableCache)) {