app/Plugin/CustomerPlus42/Event/AdminCustomerEvent.php line 47

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : CustomerPlus4
  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\CustomerPlus42\Event;
  12. use Eccube\Event\EccubeEvents;
  13. use Eccube\Event\EventArgs;
  14. use Eccube\Event\TemplateEvent;
  15. use Plugin\CustomerPlus42\Event\AbstractEvent;
  16. use Plugin\CustomerPlus42\Service\CustomerPlusService;
  17. use Symfony\Component\DependencyInjection\ContainerInterface;
  18. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  19. class AdminCustomerEvent extends AbstractEvent implements EventSubscriberInterface
  20. {
  21.     private $customerPlusService;
  22.     public function __construct(
  23.             ContainerInterface $container,
  24.             CustomerPlusService $customerPlusService
  25.             )
  26.     {
  27.         parent::__construct($container);
  28.         $this->customerPlusService $customerPlusService;
  29.     }
  30.     /**
  31.      * @return array
  32.      */
  33.     public static function getSubscribedEvents()
  34.     {
  35.         return [
  36.             '@admin/Customer/edit.twig' => 'onTemplateAdminCustomerEdit',
  37.             '@admin/Customer/delivery_edit.twig' => 'onTemplateAdminCustomerDeliveryEdit',
  38.             EccubeEvents::ADMIN_CUSTOMER_CSV_EXPORT => 'hookAdminCustomerCsvExport',
  39.         ];
  40.     }
  41.     public function onTemplateAdminCustomerEdit(TemplateEvent $event)
  42.     {
  43.         $parameters $event->getParameters();
  44.         $source $event->getSource();
  45.         $CustomerItems $this->customerPlusService->getEnabledCustomerPlusForm('customer');
  46.         $AdminCustomerItems $this->customerPlusService->getCustomerPlusForm('admin_customer');
  47.         foreach($CustomerItems as $key => $CustomerItem){
  48.             foreach($AdminCustomerItems as $AdminCustomerItem){
  49.                 if($CustomerItem->getId() == $AdminCustomerItem->getId())unset($CustomerItems[$key]);
  50.             }
  51.         }
  52.         if(preg_match('/\{\%\sfor\sf\sin\sform(\sif|\|filter\(f\s\=\>)\sf\.vars\.eccube\_form\_options\.auto\_render/',$source$result)){
  53.             $search $result[0];
  54.             $snippet file_get_contents($this->container->getParameter('plugin_realdir'). '/CustomerPlus42/Resource/template/admin/Customer/ext_edit.twig');
  55.             $replace $snippet $search;
  56.             $source str_replace($search$replace$source);
  57.         }
  58.         $event->setSource($source);
  59.         $parameters['CustomerItems'] = $CustomerItems;
  60.         $event->setParameters($parameters);
  61.         $this->insertDatePickerJSAdmin($event);
  62.     }
  63.     public function onTemplateAdminCustomerDeliveryEdit(TemplateEvent $event)
  64.     {
  65.         $parameters $event->getParameters();
  66.         $source $event->getSource();
  67.         $CustomerItems $this->customerPlusService->getEnabledCustomerPlusForm('shipping');
  68.         $AdminCustomerItems $this->customerPlusService->getCustomerPlusForm('admin_delivery');
  69.         foreach($CustomerItems as $key => $CustomerItem){
  70.             foreach($AdminCustomerItems as $AdminCustomerItem){
  71.                 if($CustomerItem->getId() == $AdminCustomerItem->getId())unset($CustomerItems[$key]);
  72.             }
  73.         }
  74.         if(preg_match('/\{\%\sfor\sf\sin\sform(\sif|\|filter\(f\s\=\>)\sf\.vars\.eccube\_form\_options\.auto\_render/',$source$result)){
  75.             $search $result[0];
  76.             $snippet file_get_contents($this->container->getParameter('plugin_realdir'). '/CustomerPlus42/Resource/template/admin/Customer/ext_edit.twig');
  77.             $replace $snippet $search;
  78.             $source str_replace($search$replace$source);
  79.         }
  80.         $event->setSource($source);
  81.         $parameters['CustomerItems'] = $CustomerItems;
  82.         $event->setParameters($parameters);
  83.         $this->insertDatePickerJSAdmin($event);
  84.     }
  85.     public function hookAdminCustomerCsvExport(EventArgs $event)
  86.     {
  87.         $ExportCsvRow $event->getArgument('ExportCsvRow');
  88.         if ($ExportCsvRow->isDataNull()) {
  89.             $Customer $event->getArgument('Customer');
  90.             $Csv $event->getArgument('Csv');
  91.             $csvEntityName str_replace('\\\\''\\'$Csv->getEntityName());
  92.             if($csvEntityName == 'Plugin\CustomerPlus42\Entity\CustomerCustom'){
  93.                 $data $Customer->getViewData($Csv->getFieldName());
  94.                 $ExportCsvRow->setData($data);
  95.             }
  96.         }
  97.     }
  98. }