move filterSubfleets() to FlightService class #170

This commit is contained in:
Nabeel Shahzad
2018-02-09 14:36:36 -06:00
parent f6b2102e48
commit 13b4a3854b
3 changed files with 38 additions and 31 deletions

View File

@@ -16,6 +16,34 @@ use App\Models\UserBid;
class FlightService extends BaseService
{
protected $userSvc;
public function __construct(UserService $userSvc)
{
$this->userSvc = $userSvc;
}
/**
* Filter out subfleets to only include aircraft that a user has access to
* @param $user
* @param $flight
* @return mixed
*/
public function filterSubfleets($user, $flight)
{
if (setting('pireps.restrict_aircraft_to_rank', false)) {
$allowed_subfleets = $this->userSvc->getAllowableSubfleets($user)->pluck('id');
$flight->subfleets = $flight->subfleets->filter(
function ($subfleet, $item) use ($allowed_subfleets) {
if ($allowed_subfleets->contains($subfleet->id)) {
return true;
}
});
}
return $flight;
}
/**
* Delete a flight, and all the user bids, etc associated with it
* @param Flight $flight