<?php
/*
* Plugin Name : CustomerRank
*
* Copyright (C) BraTech Co., Ltd. All Rights Reserved.
* http://www.bratech.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\CustomerRank42\Event;
use Eccube\Event\TemplateEvent;
use Plugin\CustomerRank42\Repository\CustomerRankRepository;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MailMagazineEvent implements EventSubscriberInterface
{
private $customerRankRepository;
/**
* CustomerRankController constructor.
* @param CustomerRankRepository $customerRankRepository
*/
public function __construct(
CustomerRankRepository $customerRankRepository
)
{
$this->customerRankRepository = $customerRankRepository;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'@MailMagazine42/admin/index.twig' => 'onTemplateAdminCustomer',
'@MailMagazine42/admin/history_condition.twig' => 'onTemplateMailmagazineHistoryCondition',
];
}
public function onTemplateAdminCustomer(TemplateEvent $event)
{
$twig = '@CustomerRank42/admin/Customer/customer_index.twig';
$event->addSnippet($twig);
$js = '@CustomerRank42/admin/Customer/customer_index.js';
$event->addAsset($js);
}
public function onTemplateMailmagazineHistoryCondition(TemplateEvent $event)
{
$parameters = $event->getParameters();
$searchData = $parameters['search_data'];
if(isset($searchData['customer_rank']) && is_array($searchData['customer_rank'])){
$val = [];
foreach($searchData['customer_rank'] as $id){
$CustomerRank = $this->customerRankRepository->find($id);
if($CustomerRank){
$val[] = $CustomerRank->getName();
}
}
if(count($val) != 0){
$searchData['customer_rank'] = implode(', ', $val);
}else{
$searchData['customer_rank'] = null;
}
}
$parameters['search_data'] = $searchData;
$event->setParameters($parameters);
$twig = '@CustomerRank42/admin/mailmagazine_history_condition_add.twig';
$event->addSnippet($twig);
$js = '@CustomerRank42/admin/mailmagazine_history_condition_add.js';
$event->addAsset($js);
}
}