<?phpnamespace CioMasterdata\Subscriber;use CioCustomerPermissionGroups\Event\CustomerPermissionGroupIdsLoadedEvent;use CioCustomerPermissionGroups\Service\CustomerPermissionService;use CioMasterdata\Definition\Masterdata\MasterdataEntity;use CioMasterdata\Service\MasterdataService;use Symfony\Component\EventDispatcher\EventSubscriberInterface;class CustomerGroupsLoadedSubscriber implements EventSubscriberInterface{ private MasterdataService $masterdataService; private CustomerPermissionService $customerPermissionService; public function __construct(MasterdataService $masterdataService, CustomerPermissionService $customerPermissionService) { $this->masterdataService = $masterdataService; $this->customerPermissionService = $customerPermissionService; } public static function getSubscribedEvents(): array { return [ CustomerPermissionGroupIdsLoadedEvent::class => 'onCustomerGroupsLoadedEvent' ]; } public function onCustomerGroupsLoadedEvent(CustomerPermissionGroupIdsLoadedEvent $event) { $customer = $event->getCustomer(); $groups = $event->getPermissionGroupIds(); /** @var MasterdataEntity $masterData */ $masterDatas = $this->masterdataService->getMasterdatasForCustomer($customer); foreach ($masterDatas as $masterData) { switch ($masterData->getPartnerstatus()) { case MasterdataEntity::PARTNERSTATUS_VALUE_BASIC: if ($masterData->isPartnerDivisionTk()) { $groups[] = $this->customerPermissionService->getPermissionGroupByName('basis_tk')->getId(); } if ($masterData->isPartnerDivisionTke()) { $groups[] = $this->customerPermissionService->getPermissionGroupByName('basis_tke')->getId(); } break; case MasterdataEntity::PARTNERSTATUS_VALUE_BRONZE: if ($masterData->isPartnerDivisionTk()) { $groups[] = $this->customerPermissionService->getPermissionGroupByName('bronze_tk')->getId(); } if ($masterData->isPartnerDivisionTke()) { $groups[] = $this->customerPermissionService->getPermissionGroupByName('bronze_tke')->getId(); } break; case MasterdataEntity::PARTNERSTATUS_VALUE_SILVER: if ($masterData->isPartnerDivisionTk()) { $groups[] = $this->customerPermissionService->getPermissionGroupByName('silber_tk')->getId(); } if ($masterData->isPartnerDivisionTke()) { $groups[] = $this->customerPermissionService->getPermissionGroupByName('silber_tke')->getId(); } break; case MasterdataEntity::PARTNERSTATUS_VALUE_GOLD: if ($masterData->isPartnerDivisionTk()) { $groups[] = $this->customerPermissionService->getPermissionGroupByName('gold_tk')->getId(); } if ($masterData->isPartnerDivisionTke()) { $groups[] = $this->customerPermissionService->getPermissionGroupByName('gold_tke')->getId(); } break; case MasterdataEntity::PARTNERSTATUS_LABEL_DOOR2DOOR: if ($masterData->isPartnerDivisionTk()) { $groups[] = $this->customerPermissionService->getPermissionGroupByName('door2door_tk')->getId(); } if ($masterData->isPartnerDivisionTke()) { $groups[] = $this->customerPermissionService->getPermissionGroupByName('door2door_tke')->getId(); } break; case MasterdataEntity::PARTNERSTATUS_VALUE_EWESHOP:// if ($masterData->isPartnerDivisionTk()) { $groups[] = $this->customerPermissionService->getPermissionGroupByName('ewe_shop')->getId();// }//// if ($masterData->isPartnerDivisionTke()) {// $groups[] = $this->customerPermissionService->getPermissionGroupByName('ewe_shop')->getId();// } break; } if ($masterData->isBrandtkEwe()) { $groups[] = $this->customerPermissionService->getPermissionGroupByName('ewe')->getId(); } if ($masterData->isBrandtkSwb()) { $groups[] = $this->customerPermissionService->getPermissionGroupByName('swb')->getId(); } if ($masterData->isBrandtkOsnatel()) { $groups[] = $this->customerPermissionService->getPermissionGroupByName('osnatel')->getId(); } } $event->setPermissionGroupIds($groups); }}