<?php
namespace Aqarmap\Bundle\UserBundle\EventListener;
use Aqarmap\Bundle\UserBundle\Entity\User;
use Aqarmap\Bundle\UserBundle\Event\ParentLogoApprovedEvent;
use Doctrine\ORM\EntityManagerInterface;
use FOS\UserBundle\Model\UserManager;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ParentLogoApprovedEventSubscriber implements EventSubscriberInterface
{
/**
* @var EntityManagerInterface
*/
private $em;
/**
* UserManager constructor.
*/
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public static function getSubscribedEvents()
{
return [
ParentLogoApprovedEvent::NAME => 'onParentLogoApproved',
];
}
public function onParentLogoApproved(ParentLogoApprovedEvent $event): void
{
/**
* @var User $subAccount
*/
foreach ($event->getSubAccounts() as $subAccount) {
$subAccount->setLogo($event->getLogo());
$subAccount->setIsValidLogo(true);
$this->em->persist($subAccount);
}
$this->em->flush();
}
}