custom/plugins/CioMasterdata/src/Subscriber/CustomerGroupsLoadedSubscriber.php line 29

Open in your IDE?
  1. <?php
  2. namespace CioMasterdata\Subscriber;
  3. use CioCustomerPermissionGroups\Event\CustomerPermissionGroupIdsLoadedEvent;
  4. use CioCustomerPermissionGroups\Service\CustomerPermissionService;
  5. use CioMasterdata\Definition\Masterdata\MasterdataEntity;
  6. use CioMasterdata\Service\MasterdataService;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class CustomerGroupsLoadedSubscriber implements EventSubscriberInterface
  9. {
  10.     private MasterdataService $masterdataService;
  11.     private CustomerPermissionService $customerPermissionService;
  12.     public function __construct(MasterdataService $masterdataServiceCustomerPermissionService $customerPermissionService)
  13.     {
  14.         $this->masterdataService $masterdataService;
  15.         $this->customerPermissionService $customerPermissionService;
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             CustomerPermissionGroupIdsLoadedEvent::class => 'onCustomerGroupsLoadedEvent'
  21.         ];
  22.     }
  23.     public function onCustomerGroupsLoadedEvent(CustomerPermissionGroupIdsLoadedEvent $event)
  24.     {
  25.         $customer $event->getCustomer();
  26.         $groups $event->getPermissionGroupIds();
  27.         /** @var MasterdataEntity $masterData */
  28.         $masterDatas $this->masterdataService->getMasterdatasForCustomer($customer);
  29.         foreach ($masterDatas as $masterData) {
  30.             switch ($masterData->getPartnerstatus()) {
  31.                 case MasterdataEntity::PARTNERSTATUS_VALUE_BASIC:
  32.                     if ($masterData->isPartnerDivisionTk()) {
  33.                         $groups[] = $this->customerPermissionService->getPermissionGroupByName('basis_tk')->getId();
  34.                     }
  35.                     if ($masterData->isPartnerDivisionTke()) {
  36.                         $groups[] = $this->customerPermissionService->getPermissionGroupByName('basis_tke')->getId();
  37.                     }
  38.                     break;
  39.                 case MasterdataEntity::PARTNERSTATUS_VALUE_BRONZE:
  40.                     if ($masterData->isPartnerDivisionTk()) {
  41.                         $groups[] = $this->customerPermissionService->getPermissionGroupByName('bronze_tk')->getId();
  42.                     }
  43.                     if ($masterData->isPartnerDivisionTke()) {
  44.                         $groups[] = $this->customerPermissionService->getPermissionGroupByName('bronze_tke')->getId();
  45.                     }
  46.                     break;
  47.                 case MasterdataEntity::PARTNERSTATUS_VALUE_SILVER:
  48.                     if ($masterData->isPartnerDivisionTk()) {
  49.                         $groups[] = $this->customerPermissionService->getPermissionGroupByName('silber_tk')->getId();
  50.                     }
  51.                     if ($masterData->isPartnerDivisionTke()) {
  52.                         $groups[] = $this->customerPermissionService->getPermissionGroupByName('silber_tke')->getId();
  53.                     }
  54.                     break;
  55.                 case MasterdataEntity::PARTNERSTATUS_VALUE_GOLD:
  56.                     if ($masterData->isPartnerDivisionTk()) {
  57.                         $groups[] = $this->customerPermissionService->getPermissionGroupByName('gold_tk')->getId();
  58.                     }
  59.                     if ($masterData->isPartnerDivisionTke()) {
  60.                         $groups[] = $this->customerPermissionService->getPermissionGroupByName('gold_tke')->getId();
  61.                     }
  62.                     break;
  63.                 case MasterdataEntity::PARTNERSTATUS_LABEL_DOOR2DOOR:
  64.                     if ($masterData->isPartnerDivisionTk()) {
  65.                         $groups[] = $this->customerPermissionService->getPermissionGroupByName('door2door_tk')->getId();
  66.                     }
  67.                     if ($masterData->isPartnerDivisionTke()) {
  68.                         $groups[] = $this->customerPermissionService->getPermissionGroupByName('door2door_tke')->getId();
  69.                     }
  70.                     break;
  71.                 case MasterdataEntity::PARTNERSTATUS_VALUE_EWESHOP:
  72. //                if ($masterData->isPartnerDivisionTk()) {
  73.                     $groups[] = $this->customerPermissionService->getPermissionGroupByName('ewe_shop')->getId();
  74. //                }
  75. //
  76. //                if ($masterData->isPartnerDivisionTke()) {
  77. //                    $groups[] = $this->customerPermissionService->getPermissionGroupByName('ewe_shop')->getId();
  78. //                }
  79.                     break;
  80.             }
  81.             if ($masterData->isBrandtkEwe()) {
  82.                 $groups[] = $this->customerPermissionService->getPermissionGroupByName('ewe')->getId();
  83.             }
  84.             if ($masterData->isBrandtkSwb()) {
  85.                 $groups[] = $this->customerPermissionService->getPermissionGroupByName('swb')->getId();
  86.             }
  87.             if ($masterData->isBrandtkOsnatel()) {
  88.                 $groups[] = $this->customerPermissionService->getPermissionGroupByName('osnatel')->getId();
  89.             }
  90.         }
  91.         $event->setPermissionGroupIds($groups);
  92.     }
  93. }