src/Subscriber/User/AmateurUpgrade/DefaultPropertiesSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Subscriber\User\AmateurUpgrade;
  3. use App\Event\User\AmateurUpgradeCompleteEvent;
  4. use App\Service\Messenger\MessengerPropertyService;
  5. use App\Service\Property\MemberPropertyService;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class DefaultPropertiesSubscriber implements EventSubscriberInterface
  8. {
  9.     protected MemberPropertyService $service;
  10.     public function __construct(MemberPropertyService $service)
  11.     {
  12.         $this->service $service;
  13.     }
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             AmateurUpgradeCompleteEvent::class => [
  18.                 ['createDefaultAmateurProperties'0],
  19.             ],
  20.         ];
  21.     }
  22.     /**
  23.      * @throws \Doctrine\ORM\ORMException
  24.      * @throws \Doctrine\ORM\OptimisticLockException
  25.      */
  26.     public function createDefaultAmateurProperties(AmateurUpgradeCompleteEvent $event)
  27.     {
  28.         if ($event->isRejected()) {
  29.             return;
  30.         }
  31.         $account $event->getAmateurUpgrade()->getAccount();
  32.         $amateur $account->getMember();
  33.         // create default message price
  34.         $propName MessengerPropertyService::PROPERTY_CONVERSATION_COST_AMOUNT;
  35.         if (!$existingProperty $this->service->getPropertyForMember($amateur$propName)) {
  36.             $this->service->createPropertyEntity($amateur$propName,  99);
  37.         }
  38.     }
  39. }