Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

59 lines
2.0KB

  1. <?php
  2. namespace Lc\CaracoleBundle\EventSubscriber\User;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Factory\User\UserMerchantFactory;
  5. use Lc\SovBundle\Doctrine\EntityInterface;
  6. use Lc\SovBundle\Doctrine\Extension\SortableInterface;
  7. use Lc\SovBundle\Doctrine\Extension\StatusInterface;
  8. use Lc\SovBundle\Doctrine\Extension\TreeInterface;
  9. use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
  10. use Lc\SovBundle\Model\User\UserInterface;
  11. use Lc\SovBundle\Repository\AbstractRepositoryInterface;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
  14. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  15. class InitUserMerchantEventSubscriber implements EventSubscriberInterface
  16. {
  17. protected $em;
  18. protected $userMerchantFactory;
  19. public function __construct(EntityManagerInterface $entityManager, UserMerchantFactory $userMerchantFactory)
  20. {
  21. $this->em = $entityManager;
  22. $this->userMerchantFactory = $userMerchantFactory;
  23. }
  24. public static function getSubscribedEvents()
  25. {
  26. return [
  27. EntityManagerEvent::PRE_CREATE_EVENT => ['createUserMerchant'],
  28. ];
  29. }
  30. public function createUserMerchant(EntityManagerEvent $event)
  31. {
  32. /* $user = $event->getEntity();
  33. $entityRepository = $this->em->getRepository(get_class($user));
  34. if ($user instanceof UserInterface) {
  35. $existingUser = $entityRepository->findOneByEmail($user->getEmail());
  36. //Le user n'existe pas, on le créer et on lui créer un user_merchant
  37. if ($existingUser == null) {
  38. $userMerchant = $this->userMerchantFactory->create(
  39. [
  40. 'active' => true,
  41. 'roles' => $user->getRoles(),
  42. 'user' => $user
  43. ]
  44. );
  45. $this->em->create($userMerchant);
  46. }
  47. }*/
  48. }
  49. }