2019-09-17 01:08:26 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Listeners;
|
|
|
|
|
|
|
|
use App\Contracts\Listener;
|
|
|
|
use App\Events\PirepFiled;
|
|
|
|
use App\Events\UserStateChanged;
|
|
|
|
use App\Models\Enums\UserState;
|
|
|
|
|
2019-11-20 23:16:01 +08:00
|
|
|
class UserStateListener extends Listener
|
2019-09-17 01:08:26 +08:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|