Filter teams by creator: users only see and manage their own teams
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user