SendActionEmailNotification.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\ObjectActionCreate;
  4. use App\Models\Enums\ActionObjectType;
  5. use App\Models\Enums\ObjectAction;
  6. use App\Services\Notification\ActionEmail\ActionEmailService;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. class SendActionEmailNotification implements ShouldQueue
  10. {
  11. /**
  12. * Create the event listener.
  13. */
  14. public function __construct()
  15. {
  16. //
  17. }
  18. /**
  19. * Handle the event.
  20. */
  21. public function handle(ObjectActionCreate $event): void
  22. {
  23. (new ActionEmailService($event->action))->send();
  24. }
  25. public function shouldQueue(ObjectActionCreate $event): bool
  26. {
  27. $actionObjectType = ActionObjectType::tryFrom($event->action->object_type);
  28. $objectAction = ObjectAction::tryFrom($event->action->action);
  29. if (! $actionObjectType || !$objectAction) {
  30. return false;
  31. }
  32. return in_array($objectAction->value, $event->notificationSetting[$actionObjectType->value]['email'] ?? []);
  33. }
  34. }