Filter teams by creator: users only see and manage their own teams

This commit is contained in:
2026-06-07 07:23:47 -04:00
parent 5607a3e507
commit e721a34d8f
2 changed files with 31 additions and 13 deletions

View File

@@ -16,17 +16,26 @@ class Team
$this->db = Database::getInstance();
}
public function findAll(): array
public function findAll(?int $userId = null): array
{
$where = $userId ? ' WHERE t.created_by = ?' : '';
$params = $userId ? [$userId] : [];
return $this->db->fetchAll(
'SELECT t.*,
"SELECT t.*,
(SELECT COUNT(*) FROM team_user WHERE team_id = t.id) AS member_count,
(SELECT COUNT(*) FROM team_server WHERE team_id = t.id) AS server_count
FROM teams t
ORDER BY t.name ASC'
FROM teams t{$where}
ORDER BY t.name ASC",
$params
);
}
public function findByCreator(int $userId): array
{
return $this->findAll($userId);
}
public function findById(int $id): ?array
{
$team = $this->db->fetch(