<?php
namespace Customize\EventListener;
use Eccube\Event\TemplateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Plugin\ECCUBE4LineLoginIntegration42\Entity\LineLoginIntegration;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Security;
class BlockEventSubscriber implements EventSubscriberInterface {
private $em;
private $security;
public function __construct(EntityManagerInterface $em, Security $security)
{
$this->em = $em;
$this->security = $security;
}
public static function getSubscribedEvents()
{
return [
'Block/top_carousel.twig' => 'onBlockTopCarousel',
'Block/top_carousel_sp.twig' => 'onBlockTopCarouselSp',
'Block/feature_banner.twig' => 'onBlockFeatureBanner',
];
}
public function onBlockTopCarousel(TemplateEvent $event)
{
$event->setParameter('isLineLinked', $this->getLineStatus());
}
public function onBlockTopCarouselSp(TemplateEvent $event)
{
$event->setParameter('isLineLinked', $this->getLineStatus());
}
public function onBlockFeatureBanner(TemplateEvent $event)
{
$event->setParameter('isLineLinked', $this->getLineStatus());
}
private function getLineStatus()
{
$customer = $this->security->getUser();
if (!$customer) {
return false;
}
$repo = $this->em->getRepository(LineLoginIntegration::class);
return (bool) $repo->findOneBy(['Customer' => $customer]);
}
}