phpvms/app/Listeners/UserStateListener.php
Nabeel S ea3ab21beb
391 Notification refactorings (#441)
* Refactor notifications to allow easier plugins

* Notification refactoring

* Formatting

* Move news to NewsService; cleanup of events

* More refactoring; added send email out for news item and the template

* Formatting

* Formatting
2019-11-20 10:16:01 -05:00

24 lines
630 B
PHP

<?php
namespace App\Listeners;
use App\Contracts\Listener;
use App\Events\PirepFiled;
use App\Events\UserStateChanged;
use App\Models\Enums\UserState;
class UserStateListener 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));
}
}
}