|
- <?php
-
- namespace Lc\CaracoleBundle\EventSubscriber\User;
-
- use Doctrine\ORM\EntityManagerInterface;
-
- use Lc\CaracoleBundle\Factory\User\UserMerchantFactory;
- use Lc\SovBundle\Doctrine\EntityInterface;
- use Lc\SovBundle\Doctrine\Extension\SortableInterface;
- use Lc\SovBundle\Doctrine\Extension\StatusInterface;
- use Lc\SovBundle\Doctrine\Extension\TreeInterface;
- use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
- use Lc\SovBundle\Model\User\UserInterface;
- use Lc\SovBundle\Repository\AbstractRepositoryInterface;
- use Symfony\Component\EventDispatcher\EventSubscriberInterface;
- use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
- use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
-
- class InitUserMerchantEventSubscriber implements EventSubscriberInterface
- {
- protected $em;
- protected $userMerchantFactory;
-
- public function __construct(EntityManagerInterface $entityManager, UserMerchantFactory $userMerchantFactory)
- {
- $this->em = $entityManager;
- $this->userMerchantFactory = $userMerchantFactory;
- }
-
- public static function getSubscribedEvents()
- {
- return [
- EntityManagerEvent::PRE_CREATE_EVENT => ['createUserMerchant'],
- ];
- }
-
- public function createUserMerchant(EntityManagerEvent $event)
- {
- /* $user = $event->getEntity();
- $entityRepository = $this->em->getRepository(get_class($user));
- if ($user instanceof UserInterface) {
- $existingUser = $entityRepository->findOneByEmail($user->getEmail());
-
- //Le user n'existe pas, on le créer et on lui créer un user_merchant
- if ($existingUser == null) {
- $userMerchant = $this->userMerchantFactory->create(
- [
- 'active' => true,
- 'roles' => $user->getRoles(),
- 'user' => $user
- ]
- );
- $this->em->create($userMerchant);
- }
- }*/
- }
-
-
- }
|