<?php
namespace App\EventSubscribers\Coaching;
use App\Events\Coaching\CoachingSubscription\CoachingSubscriptionCreatedEvent;
use App\Services\CoachingUserManager;
use App\Entity\Main\UserSettings;
use App\Services\EmailManager;
use App\Tools\ShortId;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class CoachingSubscriptionSubscriber
* @package Castalis\Pls\Brulafine\CoachingBundle\EventSubscribers
*/
class CoachingSubscriptionSubscriber implements EventSubscriberInterface
{
const COACHING_SUBSCRIPTION_CREATED = 'coaching.subscription.created';
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* @var ShortId
*/
private $shortId;
/**
* @var EmailManager
*/
private $emailFactory;
/**
* @var CoachingUserManager
*/
private $coachingUserManager;
/**
* CoachingUserSubscriber constructor.
* @param EntityManagerInterface $entityManager
*/
public function __construct(EntityManagerInterface $entityManager, ShortId $shortId, EmailManager $emailFactory, CoachingUserManager $coachingUserManager)
{
$this->entityManager = $entityManager;
$this->shortId = $shortId;
$this->emailFactory = $emailFactory;
$this->coachingUserManager = $coachingUserManager;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return array(
self::COACHING_SUBSCRIPTION_CREATED => "newSubscription",
);
}
/**
* @param CoachingSubscriptionCreatedEvent $event
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*/
public function newSubscription(CoachingSubscriptionCreatedEvent $event)
{
// We don't send anymore the email here, we now use the "single" email system where the user get the coaching
// data in the same email than the purchase receipt.
// I still keep this commented in case they want to put it back.
// if (false == $event->getCart()->getUser()->getAbTest(UserSettings::AB_SUB_SINGLE_EMAIL)) {
// $commandeId = $this->shortId->encode($event->getCart()->getCartId());
// $this->emailFactory->sendElectronicSubscription($commandeId, $event->getCart(), $event->getCredentials());
// }
}
}