Don't change rank if it seems like it's been manually changed by an admin #196

This commit is contained in:
Nabeel Shahzad
2018-02-28 15:01:23 -06:00
parent e03abc1a64
commit 6993cba55a

View File

@@ -12,6 +12,7 @@ use App\Models\Role;
use App\Models\User; use App\Models\User;
use App\Repositories\AircraftRepository; use App\Repositories\AircraftRepository;
use App\Repositories\SubfleetRepository; use App\Repositories\SubfleetRepository;
use App\Support\Units\Time;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
@@ -174,15 +175,23 @@ class UserService extends BaseService
return $user; 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; $old_rank = $user->rank;
$original_rank_id = $user->rank_id; $original_rank_id = $user->rank_id;
$pilot_hours = Utils::minutesToHours($user->flight_time);
$ranks = Rank::where('auto_promote', true) $ranks = Rank::where('auto_promote', true)
->orderBy('hours', 'asc')->get(); ->orderBy('hours', 'asc')->get();
foreach ($ranks as $rank) { foreach ($ranks as $rank) {
if($rank->hours > $pilot_hours) { if($rank->hours > $pilot_hours->hours) {
break; break;
} else { } else {
$user->rank_id = $rank->id; $user->rank_id = $rank->id;