local/modules/TheliaGiftCard/Hook/HookConfigurationManager.php line 24

Open in your IDE?
  1. <?php
  2. /*************************************************************************************/
  3. /*      Copyright (c) BERTRAND TOURLONIAS                                            */
  4. /*      email : btourlonias@openstudio.fr                                            */
  5. /*************************************************************************************/
  6. namespace TheliaGiftCard\Hook;
  7. use Thelia\Core\Event\Hook\HookRenderEvent;
  8. use Thelia\Core\Hook\BaseHook;
  9. use Thelia\Model\CategoryQuery;
  10. use Thelia\Tools\URL;
  11. use TheliaGiftCard\TheliaGiftCard;
  12. use TheliaGiftCard\Model\Map\GiftCardTableMap;
  13. use TheliaGiftCard\Model\GiftCard;
  14. use TheliaGiftCard\Model\GiftCardQuery;
  15. use Thelia\Model\Lang;
  16. use Thelia\Model\LangQuery;
  17. use Thelia\Core\Translation\Translator;
  18. class HookConfigurationManager extends BaseHook
  19. {
  20.     public function onConfiguration(HookRenderEvent $event)
  21.     {
  22.       $giftCards GiftCardQuery::create()->find();
  23.       $allInfo = array(
  24.         'orders' => array(),
  25.         'sponsor_customers' => array(),
  26.         'beneficiary_customers' => array(),
  27.         'languages' => array()
  28.       );
  29.       foreach ($giftCards as $giftCard) {
  30.         $beneficiaryCustomer $giftCard->getCustomerRelatedByBeneficiaryCustomerId();
  31.         if ($beneficiaryCustomer !== null) {
  32.             $fullName $beneficiaryCustomer->getFirstname() . ' ' $beneficiaryCustomer->getLastname();
  33.             $allInfo['beneficiary_customers'][$giftCard->getBeneficiaryCustomerId()] = $fullName;
  34.         }
  35.         $sponsorCustomer $giftCard->getCustomerRelatedBySponsorCustomerId();
  36.         if ($sponsorCustomer !== null) {
  37.             $fullName $sponsorCustomer->getFirstname() . ' ' $sponsorCustomer->getLastname();
  38.             $allInfo['sponsor_customers'][$giftCard->getSponsorCustomerId()] = $fullName;
  39.         }
  40.         $order $giftCard->getOrder();
  41.         if ($order !== null)
  42.           $allInfo['orders'][$giftCard->getOrderId()] = $order->getRef();
  43.       }
  44.       $languages LangQuery::create()
  45.         ->filterByActive(1)
  46.         ->find();
  47.       foreach ($languages as $language) {
  48.         $lang = array(
  49.             'locale' => $language->getLocale(),
  50.             'code' => $language->getCode(),
  51.             'title' => $language->getTitle()
  52.         );
  53.         array_push($allInfo['languages'], $lang);
  54.       };
  55.       $event->add(
  56.           $this->render("gift-card-config.html",
  57.           [
  58.                 'all_info' => $allInfo,
  59.                 'columnsDefinitionTransaction' => $this->defineColumnsDefinition()
  60.           ]
  61.         )
  62.       );
  63.       $event->add($this->addCSS('assets/css/style.css'));
  64.     }
  65.     public function onProductEditJs(HookRenderEvent $event)
  66.     {
  67.         $event->add(
  68.             $this->render(
  69.                 "datatable.js.html"
  70.             )
  71.         );
  72.     }
  73.     protected function defineColumnsDefinition()
  74.     {
  75.       return HookConfigurationManager::getdefineColumnsDefinition();
  76.     }
  77.     public static function getdefineColumnsDefinition()
  78.     {
  79.         $i = -1;
  80.         $definitions = [
  81.             [
  82.                 'name' => 'id',
  83.                 'targets' => ++$i,
  84.                 'orm' => GiftCardTableMap::ID,
  85.                 'title' => Translator::getInstance()->trans('ID', [], TheliaGiftCard::DOMAIN_NAME),
  86.                 'searchable' => false,
  87.             ],
  88.             [
  89.                 'name' => 'orderRef',
  90.                 'targets' => ++$i,
  91.                 'orm' => null,
  92.                 'title' => Translator::getInstance()->trans('order', [], TheliaGiftCard::DOMAIN_NAME),
  93.                 'searchable' => true,
  94.             ],
  95.             [
  96.                 'name' => 'code',
  97.                 'targets' => ++$i,
  98.                 'orm' => GiftCardTableMap::CODE,
  99.                 'title' => Translator::getInstance()->trans('code', [], TheliaGiftCard::DOMAIN_NAME),
  100.                 'searchable' => true,
  101.             ],
  102.             [
  103.                 'name' => 'sponsor_customer_id',
  104.                 'targets' => ++$i,
  105.                 'orm' => GiftCardTableMap::SPONSOR_CUSTOMER_ID,
  106.                 'title' => Translator::getInstance()->trans('sponsor_customer', [], TheliaGiftCard::DOMAIN_NAME),
  107.                 'searchable' => true,
  108.             ],
  109.             [
  110.                 'name' => 'beneficiary_customer_id',
  111.                 'targets' => ++$i,
  112.                 'orm' => GiftCardTableMap::BENEFICIARY_CUSTOMER_ID,
  113.                 'title' => Translator::getInstance()->trans('beneficiary_customer', [], TheliaGiftCard::DOMAIN_NAME),
  114.                 'searchable' => true,
  115.             ],
  116.             [
  117.                 'name' => 'amount',
  118.                 'targets' => ++$i,
  119.                 'orm' => GiftCardTableMap::AMOUNT,
  120.                 'title' => Translator::getInstance()->trans('amount', [], TheliaGiftCard::DOMAIN_NAME),
  121.                 'searchable' => true,
  122.             ],
  123.             [
  124.                 'name' => 'spend_amount',
  125.                 'targets' => ++$i,
  126.                 'orm' => GiftCardTableMap::SPEND_AMOUNT,
  127.                 'title' => Translator::getInstance()->trans('spend_amount', [], TheliaGiftCard::DOMAIN_NAME),
  128.                 'searchable' => true,
  129.             ],
  130.             [
  131.                 'name' => 'expiration_date',
  132.                 'targets' => ++$i,
  133.                 'orm' => GiftCardTableMap::EXPIRATION_DATE,
  134.                 'title' => Translator::getInstance()->trans('expiration_date', [], TheliaGiftCard::DOMAIN_NAME),
  135.                 'searchable' => false,
  136.             ],
  137.             [
  138.                 'name' => 'created_at',
  139.                 'targets' => ++$i,
  140.                 'orm' => GiftCardTableMap::CREATED_AT,
  141.                 'title' => Translator::getInstance()->trans('created_at', [], TheliaGiftCard::DOMAIN_NAME),
  142.                 'searchable' => false,
  143.             ],
  144.             [
  145.                 'name' => 'status',
  146.                 'targets' => ++$i,
  147.                 'orm' => GiftCardTableMap::STATUS,
  148.                 'title' => Translator::getInstance()->trans('status', [], TheliaGiftCard::DOMAIN_NAME),
  149.                 'searchable' => true,
  150.             ],
  151.             [
  152.                 'name' => 'pdf',
  153.                 'targets' => ++$i,
  154.                 'orm' => null,
  155.                 'title' => Translator::getInstance()->trans('pdf', [], TheliaGiftCard::DOMAIN_NAME),
  156.                 'searchable' => false,
  157.             ],
  158.             [
  159.                 'name' => 'action',
  160.                 'targets' => ++$i,
  161.                 'orm' => null,
  162.                 'title' => Translator::getInstance()->trans('action', [], TheliaGiftCard::DOMAIN_NAME),
  163.                 'searchable' => false,
  164.             ]
  165.         ];
  166.         return $definitions;
  167.     }
  168. }