app/Plugin/CustomerRank42/Event/MailMagazineEvent.php line 44

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : CustomerRank
  4. *
  5. * Copyright (C) BraTech Co., Ltd. All Rights Reserved.
  6. * http://www.bratech.co.jp/
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Plugin\CustomerRank42\Event;
  12. use Eccube\Event\TemplateEvent;
  13. use Plugin\CustomerRank42\Repository\CustomerRankRepository;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. class MailMagazineEvent implements EventSubscriberInterface
  16. {
  17.     private $customerRankRepository;
  18.     /**
  19.      * CustomerRankController constructor.
  20.      * @param CustomerRankRepository $customerRankRepository
  21.      */
  22.     public function __construct(
  23.             CustomerRankRepository $customerRankRepository
  24.             )
  25.     {
  26.         $this->customerRankRepository $customerRankRepository;
  27.     }
  28.     /**
  29.      * @return array
  30.      */
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return [
  34.             '@MailMagazine42/admin/index.twig' => 'onTemplateAdminCustomer',
  35.             '@MailMagazine42/admin/history_condition.twig' => 'onTemplateMailmagazineHistoryCondition',
  36.         ];
  37.     }
  38.     public function onTemplateAdminCustomer(TemplateEvent $event)
  39.     {
  40.         $twig '@CustomerRank42/admin/Customer/customer_index.twig';
  41.         $event->addSnippet($twig);
  42.         $js '@CustomerRank42/admin/Customer/customer_index.js';
  43.         $event->addAsset($js);
  44.     }
  45.     public function onTemplateMailmagazineHistoryCondition(TemplateEvent $event)
  46.     {
  47.         $parameters $event->getParameters();
  48.         $searchData $parameters['search_data'];
  49.         if(isset($searchData['customer_rank']) && is_array($searchData['customer_rank'])){
  50.             $val = [];
  51.             foreach($searchData['customer_rank'] as $id){
  52.                 $CustomerRank $this->customerRankRepository->find($id);
  53.                 if($CustomerRank){
  54.                     $val[] = $CustomerRank->getName();
  55.                 }
  56.             }
  57.             if(count($val) != 0){
  58.                 $searchData['customer_rank'] = implode(', '$val);
  59.             }else{
  60.                 $searchData['customer_rank'] = null;
  61.             }
  62.         }
  63.         $parameters['search_data'] = $searchData;
  64.         $event->setParameters($parameters);
  65.         $twig '@CustomerRank42/admin/mailmagazine_history_condition_add.twig';
  66.         $event->addSnippet($twig);
  67.         $js '@CustomerRank42/admin/mailmagazine_history_condition_add.js';
  68.         $event->addAsset($js);
  69.     }
  70. }