phpvms/app/Listeners/SetUserActive.php
Nabeel S aedb1f22b6
Don't allow cancels from certain states (#396)
* Don't allow cancels from certain states

* Unused imports

* Don't reset the state doubly

* Move SetUserActive into listener; code cleanup

* Unused imports

* Add missing files into htaccess

* Move Command contract to correct folder
2019-09-16 13:08:26 -04:00

24 lines
626 B
PHP

<?php
namespace App\Listeners;
use App\Contracts\Listener;
use App\Events\PirepFiled;
use App\Events\UserStateChanged;
use App\Models\Enums\UserState;
class SetUserActive extends Listener
{
public function handle(PirepFiled $event): void
{
// Check the user state, set them to ACTIVE if on leave
if ($event->pirep->user->state !== UserState::ACTIVE) {
$old_state = $event->pirep->user->state;
$event->pirep->user->state = UserState::ACTIVE;
$event->pirep->user->save();
event(new UserStateChanged($event->pirep->user, $old_state));
}
}
}