mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 21:52:08 +00:00
38 lines
978 B
PHP
38 lines
978 B
PHP
<?php
|
|
|
|
namespace App\Services\Rooms;
|
|
|
|
use App\Models\Room;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
class DashboardRoomService
|
|
{
|
|
/**
|
|
* @return array{owned: Collection<int, Room>, favorites: Collection<int, Room>}
|
|
*/
|
|
public function forUser(User $user): array
|
|
{
|
|
$ownedRooms = $user
|
|
->ownedRooms()
|
|
->withCount('players')
|
|
->withCount(['activePlayers as active_player_count'])
|
|
->orderByRaw('closed_at IS NOT NULL')
|
|
->orderByDesc('last_activity_at')
|
|
->get();
|
|
|
|
$favoriteRooms = $user
|
|
->favoriteRooms()
|
|
->withCount('players')
|
|
->withCount(['activePlayers as active_player_count'])
|
|
->orderByRaw('closed_at IS NOT NULL')
|
|
->orderByDesc('last_activity_at')
|
|
->get();
|
|
|
|
return [
|
|
'owned' => $ownedRooms,
|
|
'favorites' => $favoriteRooms,
|
|
];
|
|
}
|
|
}
|