app/Plugin/Gift42/Event.php line 74

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Gift42 Plugin
  4.  *
  5.  * Copyright (C) 2023 Diezon.
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Plugin\Gift42;
  11. use Eccube\Event\EccubeEvents;
  12. use Eccube\Event\EventArgs;
  13. use Eccube\Event\TemplateEvent;
  14. use Plugin\Gift42\Common\GiftKind;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class Event implements EventSubscriberInterface
  17. {
  18.     /**
  19.      * Event constructor.
  20.      */
  21.     public function __construct() {
  22.     }
  23.     /**
  24.      * @return array
  25.      */
  26.     public static function getSubscribedEvents()
  27.     {
  28.         return [
  29.             '@admin/Product/product.twig' => 'onAdminProductProductTwig',
  30.             '@admin/Order/edit.twig' => 'onAdminOrderEditTwig',
  31.             'Product/detail.twig' => 'onProductDetailTwig',
  32.             'Cart/index.twig' => 'onCartIndexTwig',
  33.             'Shopping/index.twig' => 'onShoppingIndexTwig',
  34.             'Shopping/confirm.twig' => 'onShoppingConfirmTwig',
  35.             'Mypage/index.twig' => 'onMypageIndexTwig',
  36.             'Mypage/history.twig' => 'onMypageHistoryTwig',
  37.             EccubeEvents::ADMIN_PRODUCT_CSV_EXPORT => self::getMethodName(EccubeEvents::ADMIN_PRODUCT_CSV_EXPORT),
  38.             EccubeEvents::ADMIN_ORDER_CSV_EXPORT_ORDER => self::getMethodName(EccubeEvents::ADMIN_ORDER_CSV_EXPORT_ORDER),
  39.         ];
  40.     }
  41.     /**
  42.      * @param TemplateEvent $event
  43.      */
  44.     public function onAdminProductProductTwig(TemplateEvent $event)
  45.     {
  46.         $event->addSnippet('@Gift42/admin/Product/product.twig');
  47.     }
  48.     /**
  49.      * @param TemplateEvent $event
  50.      */
  51.     public function onAdminOrderEditTwig(TemplateEvent $event)
  52.     {
  53.         $event->addSnippet('@Gift42/admin/Order/edit.twig');
  54.     }
  55.     /**
  56.      * @param TemplateEvent $event
  57.      */
  58.     public function onProductDetailTwig(TemplateEvent $event)
  59.     {
  60.         $event->addSnippet('@Gift42/front/Product/detail.twig');
  61.     }
  62.     /**
  63.      * @param TemplateEvent $event
  64.      */
  65.     public function onCartIndexTwig(TemplateEvent $event)
  66.     {
  67.         $event->addSnippet('@Gift42/front/Cart/index.twig');
  68.     }
  69.     /**
  70.      * @param TemplateEvent $event
  71.      */
  72.     public function onShoppingIndexTwig(TemplateEvent $event)
  73.     {
  74.         $event->addSnippet('@Gift42/front/Shopping/index.twig');
  75.     }
  76.     /**
  77.      * @param TemplateEvent $event
  78.      */
  79.     public function onShoppingConfirmTwig(TemplateEvent $event)
  80.     {
  81.         $event->addSnippet('@Gift42/front/Shopping/confirm.twig');
  82.     }
  83.     /**
  84.      * @param TemplateEvent $event
  85.      */
  86.     public function onMypageIndexTwig(TemplateEvent $event)
  87.     {
  88.         $event->addSnippet('@Gift42/front/Mypage/index.twig');
  89.     }
  90.     /**
  91.      * @param TemplateEvent $event
  92.      */
  93.     public function onMypageHistoryTwig(TemplateEvent $event)
  94.     {
  95.         $event->addSnippet('@Gift42/front/Mypage/history.twig');
  96.     }
  97.     /**
  98.      * @param string $const
  99.      * @return string $methodName
  100.      */
  101.     public static function getMethodName(string $const): string
  102.     {
  103.         $words explode('.'$const);
  104.         $methodName null;
  105.         foreach ($words as $word) {
  106.             $methodName .= ucfirst($word);
  107.         }
  108.         $methodName 'on' $methodName;
  109.         return $methodName;
  110.     }
  111.     /**
  112.      * @param EventArgs $event
  113.      */
  114.     public function onAdminProductCsvExport(EventArgs $event)
  115.     {
  116.         $Csv $event->getArgument('Csv');
  117.         $ProductClass $event->getArgument('ProductClass');
  118.         $ExportCsvRow $event->getArgument('ExportCsvRow');
  119.         if ($Csv->getFieldName() == 'gift_kind' && $Csv->getDispName() == trans('admin.gift_kind_name')) {
  120.             $Product $ProductClass->getProduct();
  121.             $giftKindName trans(array_search($Product->getGiftKind(), GiftKind::GIFT_KIND_LIST));
  122.             $ExportCsvRow->setData($giftKindName);
  123.         }
  124.     }
  125.     /**
  126.      * @param EventArgs $event
  127.      */
  128.     public function onAdminOrderCsvExportOrder(EventArgs $event)
  129.     {
  130.         $Csv $event->getArgument('Csv');
  131.         $OrderItem $event->getArgument('OrderItem');
  132.         $ExportCsvRow $event->getArgument('ExportCsvRow');
  133.         if ($Csv->getFieldName() == 'gift_kind' && $Csv->getDispName() == trans('admin.gift_kind_name') && !$ExportCsvRow->isDataNull()) {
  134.             $giftKindName trans(array_search($OrderItem->getGiftKind(), GiftKind::GIFT_KIND_LIST));
  135.             $ExportCsvRow->setData($giftKindName);
  136.         }
  137.     }
  138. }