src/Subscriber/Livecam/BalanceAmateurSubscriber.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Subscriber\Livecam;
  3. use App\Dictionary\BalanceDetailUsageType;
  4. use App\Dictionary\BalanceType;
  5. use App\Event\Balance\BalanceAmateurProvisionCreatedEvent;
  6. use App\Event\RedisEventManager;
  7. use Frivol\Common\Service\Notification\LivecamProvisionNotification;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class BalanceAmateurSubscriber implements EventSubscriberInterface
  10. {
  11.     protected RedisEventManager $redisEventManager;
  12.     public function __construct(RedisEventManager $redisEventManager)
  13.     {
  14.         $this->redisEventManager $redisEventManager;
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             BalanceAmateurProvisionCreatedEvent::class => [
  20.                 ['onLivecamProvisionSendNotification'0],
  21.             ],
  22.         ];
  23.     }
  24.     /**
  25.      * @return void
  26.      */
  27.     public function onLivecamProvisionSendNotification(BalanceAmateurProvisionCreatedEvent $event)
  28.     {
  29.         $balance $event->getBalance();
  30.         if (BalanceType::INCOME !== $balance->getType()) {
  31.             return;
  32.         }
  33.         if ($balance->isTypeCam()) { // of course, it is need to disable it temporarily
  34.             return;
  35.         }
  36.         $detail $balance->getBalanceDetail();
  37.         if (!$detail || BalanceDetailUsageType::CAM !== $detail->getUsageType()) {
  38.             return;
  39.         }
  40.         if ($balance->getAmount() / 1.21 0.01) {
  41.             return;
  42.         }
  43.         $amateur $balance->getMember();
  44.         $amount number_format($balance->getAmount() / 1.212',''.');
  45.         $notification = new LivecamProvisionNotification();
  46.         $notification->setData([
  47.             'message' => 'Du hast eine Gutschrift über '.$amount.' EUR erhalten.',
  48.             'amount' => $amount,
  49.         ]);
  50.         $notification->setRecipientUsername($amateur->getUsername());
  51.         $notification->setRecipientId($amateur->getId());
  52.         $this->redisEventManager->publishToMember($amateur$notification);
  53.     }
  54. }