src/Aqarmap/Bundle/UserBundle/EventListener/ParentLogoApprovedEventSubscriber.php line 33

  1. <?php
  2. namespace Aqarmap\Bundle\UserBundle\EventListener;
  3. use Aqarmap\Bundle\UserBundle\Entity\User;
  4. use Aqarmap\Bundle\UserBundle\Event\ParentLogoApprovedEvent;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use FOS\UserBundle\Model\UserManager;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class ParentLogoApprovedEventSubscriber implements EventSubscriberInterface
  9. {
  10. /**
  11. * UserManager constructor.
  12. */
  13. public function __construct(private readonly EntityManagerInterface $em)
  14. {
  15. }
  16. public static function getSubscribedEvents(): array
  17. {
  18. return [
  19. ParentLogoApprovedEvent::NAME => 'onParentLogoApproved',
  20. ];
  21. }
  22. public function onParentLogoApproved(ParentLogoApprovedEvent $event): void
  23. {
  24. /**
  25. * @var User $subAccount
  26. */
  27. foreach ($event->getSubAccounts() as $subAccount) {
  28. $subAccount->setLogo($event->getLogo());
  29. $subAccount->setIsValidLogo(true);
  30. $this->em->persist($subAccount);
  31. }
  32. $this->em->flush();
  33. }
  34. }