30 خطوط
995 B
PHP
30 خطوط
995 B
PHP
<?php
|
|
|
|
namespace App\Modules\Manager\Application;
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Identity\Domain\Enums\UserRole;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
final class ManagerScope
|
|
{
|
|
/** @return Collection<int, string> */
|
|
public function teamIds(User $manager): Collection
|
|
{
|
|
abort_unless($manager->role === UserRole::Manager, 403);
|
|
|
|
return DB::table('team_managers')->join('teams', 'teams.id', '=', 'team_managers.team_id')
|
|
->where('team_managers.user_id', $manager->getKey())
|
|
->where('teams.organization_id', $manager->organization_id)
|
|
->pluck('teams.id')->map(fn ($id) => (string) $id)->values();
|
|
}
|
|
|
|
/** @return Collection<int, string> */
|
|
public function memberIds(User $manager): Collection
|
|
{
|
|
return DB::table('team_memberships')->whereIn('team_id', $this->teamIds($manager))
|
|
->distinct()->pluck('user_id')->map(fn ($id) => (string) $id)->values();
|
|
}
|
|
}
|