<?php 
/** 
 * Copyright(c) 2022 SYSTEM_KD 
 * Date: 2022/06/04 
 */ 
 
namespace Plugin\PointExDx\EventSubscriber; 
 
 
use Doctrine\ORM\EntityManagerInterface; 
use Eccube\Entity\Customer; 
use Eccube\Event\EccubeEvents; 
use Eccube\Event\EventArgs; 
use Plugin\PointExDx\Service\PointExDxService; 
use Symfony\Component\EventDispatcher\EventSubscriberInterface; 
 
/** 
 * EccubeEvents::FRONT_ENTRY_ACTIVATE_COMPLETE がなくなったため廃止 
 * 
 * @deprecated 
 */ 
class EntryEventSubscriber implements EventSubscriberInterface 
{ 
 
    /** @var EntityManagerInterface */ 
    private $entityManager; 
 
    /** @var PointExDxService */ 
    protected $pointExService; 
 
    public function __construct( 
        EntityManagerInterface $entityManager, 
        PointExDxService       $pointExService 
    ) 
    { 
        $this->entityManager = $entityManager; 
        $this->pointExService = $pointExService; 
    } 
 
    /** 
     * 本会員登録完了時 
     * 
     * @param EventArgs $event 
     * @return void 
     */ 
    public function onFrontEntryActivateComplete(EventArgs $event) 
    { 
 
        if ($this->pointExService->isEntryAddPoint()) { 
 
            $addPoint = $this->pointExService->getEntryAddPoint(); 
 
            /** @var Customer $customer */ 
            $customer = $event->getArgument("Customer"); 
            $point = (int)$customer->getPoint() + $addPoint; 
 
            $customer->setPoint($point); 
            $this->entityManager->persist($customer); 
            $this->entityManager->flush(); 
        } 
    } 
 
    /** 
     * Returns an array of event names this subscriber wants to listen to. 
     * 
     * The array keys are event names and the value can be: 
     * 
     * * The method name to call (priority defaults to 0) 
     * * An array composed of the method name to call and the priority 
     * * An array of arrays composed of the method names to call and respective 
     *   priorities, or 0 if unset 
     * 
     * For instance: 
     * 
     * * array('eventName' => 'methodName') 
     * * array('eventName' => array('methodName', $priority)) 
     * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) 
     * 
     */ 
    public static function getSubscribedEvents() 
    { 
        return [ 
            EccubeEvents::FRONT_ENTRY_ACTIVATE_COMPLETE => 'onFrontEntryActivateComplete' 
        ]; 
    } 
}