From 6993cba55a3b3e4caa21c7fa6b9e87b65d8a6ebf Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Wed, 28 Feb 2018 15:01:23 -0600 Subject: [PATCH] Don't change rank if it seems like it's been manually changed by an admin #196 --- app/Services/UserService.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Services/UserService.php b/app/Services/UserService.php index 074bc4c0..61d3bb9b 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -12,6 +12,7 @@ use App\Models\Role; use App\Models\User; use App\Repositories\AircraftRepository; use App\Repositories\SubfleetRepository; +use App\Support\Units\Time; use Illuminate\Support\Collection; use Log; @@ -174,15 +175,23 @@ class UserService extends BaseService return $user; } + $pilot_hours = new Time($user->flight_time); + + # The current rank's hours are over the pilot's current hours, + # so assume that they were "placed" here by an admin so don't + # bother with updating it + if($user->rank && $user->rank->hours > $pilot_hours->hours) { + return $user; + } + $old_rank = $user->rank; $original_rank_id = $user->rank_id; - $pilot_hours = Utils::minutesToHours($user->flight_time); $ranks = Rank::where('auto_promote', true) ->orderBy('hours', 'asc')->get(); foreach ($ranks as $rank) { - if($rank->hours > $pilot_hours) { + if($rank->hours > $pilot_hours->hours) { break; } else { $user->rank_id = $rank->id;