Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 protected function fillTree(OwnerTreeInterface $tree)
 {
     $userClass = $this->getOwnershipMetadataProvider()->getBasicLevelClass();
     $businessUnitClass = $this->getOwnershipMetadataProvider()->getLocalLevelClass();
     /** @var User[] $users */
     $users = $this->getManagerForClass($userClass)->getRepository($userClass)->findAll();
     /** @var BusinessUnit[] $businessUnits */
     $businessUnitsRepo = $this->getManagerForClass($businessUnitClass)->getRepository($businessUnitClass);
     $businessUnits = $businessUnitsRepo->createQueryBuilder('bu')->select(['bu.id', 'IDENTITY(bu.organization) organization', 'IDENTITY(bu.owner) owner'])->getQuery()->getArrayResult();
     foreach ($businessUnits as $businessUnit) {
         if (!empty($businessUnit['organization'])) {
             $tree->addLocalEntity($businessUnit['id'], $businessUnit['organization']);
             if ($businessUnit['owner']) {
                 $tree->addDeepEntity($businessUnit['id'], $businessUnit['owner']);
             }
         }
     }
     $tree->buildTree();
     foreach ($users as $user) {
         $owner = $user->getOwner();
         $tree->addBasicEntity($user->getId(), $owner ? $owner->getId() : null);
         foreach ($user->getOrganizations() as $organization) {
             $organizationId = $organization->getId();
             $tree->addGlobalEntity($user->getId(), $organizationId);
             $userBusinessUnits = $user->getBusinessUnits();
             foreach ($userBusinessUnits as $businessUnit) {
                 $buOrganizationId = $businessUnit->getOrganization()->getId();
                 if ($organizationId == $buOrganizationId) {
                     $tree->addLocalEntityToBasic($user->getId(), $businessUnit->getId(), $organizationId);
                 }
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function fillTree(OwnerTreeInterface $tree)
 {
     $userClass = $this->getOwnershipMetadataProvider()->getBasicLevelClass();
     $businessUnitClass = $this->getOwnershipMetadataProvider()->getLocalLevelClass();
     /** @var User[] $users */
     $users = $this->getManagerForClass($userClass)->getRepository($userClass)->findAll();
     /** @var BusinessUnit[] $businessUnits */
     $businessUnits = $this->getManagerForClass($businessUnitClass)->getRepository($businessUnitClass)->findAll();
     foreach ($businessUnits as $businessUnit) {
         if ($businessUnit->getOrganization()) {
             $tree->addLocalEntity($businessUnit->getId(), $businessUnit->getOrganization()->getId());
             if ($businessUnit->getOwner()) {
                 $tree->addDeepEntity($businessUnit->getId(), $businessUnit->getOwner()->getId());
             }
         }
     }
     foreach ($users as $user) {
         $owner = $user->getOwner();
         $tree->addBasicEntity($user->getId(), $owner ? $owner->getId() : null);
         foreach ($user->getOrganizations() as $organization) {
             $organizationId = $organization->getId();
             $tree->addGlobalEntity($user->getId(), $organizationId);
             foreach ($user->getBusinessUnits() as $businessUnit) {
                 $buOrganizationId = $businessUnit->getOrganization()->getId();
                 if ($organizationId == $buOrganizationId) {
                     $tree->addLocalEntityToBasic($user->getId(), $businessUnit->getId(), $organizationId);
                 }
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function fillTree(OwnerTreeInterface $tree)
 {
     $accountUserClass = $this->getOwnershipMetadataProvider()->getBasicLevelClass();
     $accountClass = $this->getOwnershipMetadataProvider()->getLocalLevelClass();
     /** @var AccountUser[] $accountUsers */
     $accountUsers = $this->getManagerForClass($accountUserClass)->getRepository($accountUserClass)->findAll();
     /** @var Account[] $accounts */
     $accounts = $this->getManagerForClass($accountClass)->getRepository($accountClass)->findAll();
     // map accounts
     foreach ($accounts as $account) {
         if ($account->getOrganization()) {
             $tree->addLocalEntity($account->getId(), $account->getOrganization()->getId());
             if ($account->getParent()) {
                 $tree->addDeepEntity($account->getId(), $account->getParent()->getId());
             }
         }
     }
     // map users
     foreach ($accountUsers as $user) {
         $account = $user->getAccount();
         $tree->addBasicEntity($user->getId(), $account ? $account->getId() : null);
         foreach ($user->getOrganizations() as $organization) {
             $organizationId = $organization->getId();
             $tree->addGlobalEntity($user->getId(), $organizationId);
             if ($organizationId === $account->getOrganization()->getId()) {
                 $tree->addLocalEntityToBasic($user->getId(), $account->getId(), $organizationId);
             }
         }
     }
 }