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

Open in your IDE?
  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.      * @var EntityManagerInterface
  12.      */
  13.     private $em;
  14.     /**
  15.      * UserManager constructor.
  16.      */
  17.     public function __construct(EntityManagerInterface $em)
  18.     {
  19.         $this->em $em;
  20.     }
  21.     public static function getSubscribedEvents()
  22.     {
  23.         return [
  24.             ParentLogoApprovedEvent::NAME => 'onParentLogoApproved',
  25.         ];
  26.     }
  27.     public function onParentLogoApproved(ParentLogoApprovedEvent $event): void
  28.     {
  29.         /**
  30.          * @var User $subAccount
  31.          */
  32.         foreach ($event->getSubAccounts() as $subAccount) {
  33.             $subAccount->setLogo($event->getLogo());
  34.             $subAccount->setIsValidLogo(true);
  35.             $this->em->persist($subAccount);
  36.         }
  37.         $this->em->flush();
  38.     }
  39. }