src/EventSubscribers/Coaching/CoachingSubscriptionSubscriber.php line 66

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscribers\Coaching;
  3. use App\Events\Coaching\CoachingSubscription\CoachingSubscriptionCreatedEvent;
  4. use App\Services\CoachingUserManager;
  5. use App\Entity\Main\UserSettings;
  6. use App\Services\EmailManager;
  7. use App\Tools\ShortId;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. /**
  11.  * Class CoachingSubscriptionSubscriber
  12.  * @package Castalis\Pls\Brulafine\CoachingBundle\EventSubscribers
  13.  */
  14. class CoachingSubscriptionSubscriber implements EventSubscriberInterface
  15. {
  16.     const COACHING_SUBSCRIPTION_CREATED 'coaching.subscription.created';
  17.     /**
  18.      * @var EntityManagerInterface
  19.      */
  20.     private $entityManager;
  21.     /**
  22.      * @var ShortId
  23.      */
  24.     private $shortId;
  25.     /**
  26.      * @var EmailManager
  27.      */
  28.     private $emailFactory;
  29.     /**
  30.      * @var CoachingUserManager
  31.      */
  32.     private $coachingUserManager;
  33.     /**
  34.      * CoachingUserSubscriber constructor.
  35.      * @param EntityManagerInterface $entityManager
  36.      */
  37.     public function __construct(EntityManagerInterface $entityManagerShortId $shortIdEmailManager $emailFactoryCoachingUserManager $coachingUserManager)
  38.     {
  39.         $this->entityManager $entityManager;
  40.         $this->shortId $shortId;
  41.         $this->emailFactory $emailFactory;
  42.         $this->coachingUserManager $coachingUserManager;
  43.     }
  44.     /**
  45.      * @return array
  46.      */
  47.     public static function getSubscribedEvents()
  48.     {
  49.         return array(
  50.             self::COACHING_SUBSCRIPTION_CREATED => "newSubscription",
  51.         );
  52.     }
  53.     /**
  54.      * @param CoachingSubscriptionCreatedEvent $event
  55.      * @throws \Twig_Error_Loader
  56.      * @throws \Twig_Error_Runtime
  57.      * @throws \Twig_Error_Syntax
  58.      */
  59.     public function newSubscription(CoachingSubscriptionCreatedEvent $event)
  60.     {
  61.         // We don't send anymore the email here, we now use the "single" email system where the user get the coaching
  62.         // data in the same email than the purchase receipt.
  63.         // I still keep this commented in case they want to put it back.
  64. //        if (false == $event->getCart()->getUser()->getAbTest(UserSettings::AB_SUB_SINGLE_EMAIL)) {
  65. //            $commandeId = $this->shortId->encode($event->getCart()->getCartId());
  66. //            $this->emailFactory->sendElectronicSubscription($commandeId, $event->getCart(), $event->getCredentials());
  67. //        }
  68.     }
  69. }