private function buildTestTree() { /** * org1 org2 org3 org4 * | | * bu1 bu2 +-bu3 +-bu4 * | | | | * | | +-bu31 | * | | | | | * | | | +-user31 | * | | | | * user1 +-user2 | +-user3 +-user4 * | | * +-bu3a +-bu3 * | +-bu4 * +-bu3a1 | * +-bu41 * | * +-bu411 * | * +-user411 */ $this->tree->addBusinessUnit('bu1', null); $this->tree->addBusinessUnit('bu2', null); $this->tree->addBusinessUnit('bu3', 'org3'); $this->tree->addBusinessUnit('bu31', 'org3'); $this->tree->addBusinessUnit('bu3a', 'org3'); $this->tree->addBusinessUnit('bu3a1', 'org3'); $this->tree->addBusinessUnit('bu4', 'org4'); $this->tree->addBusinessUnit('bu41', 'org4'); $this->tree->addBusinessUnit('bu411', 'org4'); $this->tree->addBusinessUnitRelation('bu1', null); $this->tree->addBusinessUnitRelation('bu2', null); $this->tree->addBusinessUnitRelation('bu3', null); $this->tree->addBusinessUnitRelation('bu31', 'bu3'); $this->tree->addBusinessUnitRelation('bu3a', null); $this->tree->addBusinessUnitRelation('bu3a1', 'bu3a'); $this->tree->addBusinessUnitRelation('bu4', null); $this->tree->addBusinessUnitRelation('bu41', 'bu4'); $this->tree->addBusinessUnitRelation('bu411', 'bu41'); $this->tree->addUser('user1', null); $this->tree->addUser('user2', 'bu2'); $this->tree->addUser('user3', 'bu3'); $this->tree->addUser('user31', 'bu31'); $this->tree->addUser('user4', 'bu4'); $this->tree->addUser('user41', 'bu41'); $this->tree->addUser('user411', 'bu411'); $this->tree->addUserBusinessUnit('user4', 'bu3'); $this->tree->addUserBusinessUnit('user4', 'bu4'); }
public function testAddUserBusinessUnitBelongToDifferentOrganizations() { $tree = new OwnerTree(); $tree->addUser('user', null); $tree->addBusinessUnit('bu1', null); $this->assertNull($tree->getBusinessUnitOrganizationId('bu1')); $tree->addBusinessUnit('bu2', 'org2'); $this->assertEquals('org2', $tree->getBusinessUnitOrganizationId('bu2')); $tree->addBusinessUnit('bu3', 'org3'); $this->assertEquals('org3', $tree->getBusinessUnitOrganizationId('bu3')); $tree->addUserBusinessUnit('user', null); $this->assertEquals(array(), $tree->getUserBusinessUnitIds('user')); $this->assertNull($tree->getUserOrganizationId('user')); $this->assertEquals(array(), $tree->getUserOrganizationIds('user')); $tree->addUserBusinessUnit('user', 'bu1'); $this->assertEquals(array('bu1'), $tree->getUserBusinessUnitIds('user')); $this->assertNull($tree->getUserOrganizationId('user')); $this->assertEquals(array(), $tree->getUserOrganizationIds('user')); $tree->addUserBusinessUnit('user', 'bu2'); $this->assertEquals(array('bu1', 'bu2'), $tree->getUserBusinessUnitIds('user')); $this->assertNull($tree->getUserOrganizationId('user')); $this->assertEquals(array('org2'), $tree->getUserOrganizationIds('user')); $tree->addUserBusinessUnit('user', 'bu3'); $this->assertEquals(array('bu1', 'bu2', 'bu3'), $tree->getUserBusinessUnitIds('user')); $this->assertNull($tree->getUserOrganizationId('user')); $this->assertEquals(array('org2', 'org3'), $tree->getUserOrganizationIds('user')); }
protected function addUserInfoToTree(OwnerTree $tree, User $user) { $owner = $user->getOwner(); $tree->addUser($user->getId(), $owner ? $owner->getId() : null); foreach ($user->getOrganizations() as $organization) { $tree->addUserOrganization($user->getId(), $organization->getId()); foreach ($user->getBusinessUnits() as $businessUnit) { $organizationId = $organization->getId(); $buOrganizationId = $businessUnit->getOrganization()->getId(); if ($organizationId == $buOrganizationId) { $tree->addUserBusinessUnit($user->getId(), $organizationId, $businessUnit->getId()); } } } }
private function buildTestTree() { /** * org1 org2 org3 org4 * | | * bu1 bu2 +-bu3 +-bu4 * | | | | * | | +-bu31 | * | | | | | * | | | +-user31 | * | | | | * user1 +-user2 | +-user3 +-user4 * | | * +-bu3a +-bu3 * | +-bu4 * +-bu3a1 | * +-bu41 * | * +-bu411 * | * +-user411 * * user1 user2 user3 user31 user4 user411 * * org1 org2 org3 org3 org4 org4 * org2 org2 * * bu1 bu2 bu3 bu31 bu4 bu411 * bu2 bu2 */ $this->org1 = new Organization('org1'); $this->org2 = new Organization('org2'); $this->org3 = new Organization('org3'); $this->org4 = new Organization('org4'); $this->bu1 = new BusinessUnit('bu1'); $this->bu2 = new BusinessUnit('bu2'); $this->bu3 = new BusinessUnit('bu3'); $this->bu31 = new BusinessUnit('bu31', $this->bu3); $this->bu4 = new BusinessUnit('bu4'); $this->bu41 = new BusinessUnit('bu41', $this->bu4); $this->bu411 = new BusinessUnit('bu411', $this->bu41); $this->user1 = new User('user1', null, $this->org1); $this->user2 = new User('user2', $this->bu2, $this->org2); $this->user3 = new User('user3', $this->bu3, $this->org3); $this->user31 = new User('user31', $this->bu31, $this->org3); $this->user4 = new User('user4', $this->bu4, $this->org4); $this->user411 = new User('user411', $this->bu411, $this->org4); $this->tree->addBusinessUnit('bu1', null); $this->tree->addBusinessUnit('bu2', null); $this->tree->addBusinessUnit('bu3', 'org3'); $this->tree->addBusinessUnit('bu31', 'org3'); $this->tree->addBusinessUnit('bu3a', 'org3'); $this->tree->addBusinessUnit('bu3a1', 'org3'); $this->tree->addBusinessUnit('bu4', 'org4'); $this->tree->addBusinessUnit('bu41', 'org4'); $this->tree->addBusinessUnit('bu411', 'org4'); $this->tree->addBusinessUnitRelation('bu1', null); $this->tree->addBusinessUnitRelation('bu2', null); $this->tree->addBusinessUnitRelation('bu3', null); $this->tree->addBusinessUnitRelation('bu31', 'bu3'); $this->tree->addBusinessUnitRelation('bu3a', null); $this->tree->addBusinessUnitRelation('bu3a1', 'bu3a'); $this->tree->addBusinessUnitRelation('bu4', null); $this->tree->addBusinessUnitRelation('bu41', 'bu4'); $this->tree->addBusinessUnitRelation('bu411', 'bu41'); $this->tree->addUser('user1', null); $this->tree->addUser('user2', 'bu2'); $this->tree->addUser('user3', 'bu3'); $this->tree->addUser('user31', 'bu31'); $this->tree->addUser('user4', 'bu4'); $this->tree->addUser('user41', 'bu41'); $this->tree->addUser('user411', 'bu411'); $this->tree->addUserOrganization('user1', 'org1'); $this->tree->addUserOrganization('user1', 'org2'); $this->tree->addUserOrganization('user2', 'org2'); $this->tree->addUserOrganization('user3', 'org2'); $this->tree->addUserOrganization('user3', 'org3'); $this->tree->addUserOrganization('user31', 'org3'); $this->tree->addUserOrganization('user4', 'org4'); $this->tree->addUserOrganization('user411', 'org4'); $this->tree->addUserBusinessUnit('user1', 'org1', 'bu1'); $this->tree->addUserBusinessUnit('user1', 'org2', 'bu2'); $this->tree->addUserBusinessUnit('user2', 'org2', 'bu2'); $this->tree->addUserBusinessUnit('user3', 'org3', 'bu3'); $this->tree->addUserBusinessUnit('user3', 'org2', 'bu2'); $this->tree->addUserBusinessUnit('user31', 'org3', 'bu31'); $this->tree->addUserBusinessUnit('user4', 'org4', 'bu4'); $this->tree->addUserBusinessUnit('user411', 'org4', 'bu411'); }
/** * @param OwnerTree $tree */ protected function fillTree(OwnerTree $tree) { $users = $this->em->getRepository('Oro\\Bundle\\UserBundle\\Entity\\User')->findAll(); $businessUnits = $this->em->getRepository('Oro\\Bundle\\OrganizationBundle\\Entity\\BusinessUnit')->findAll(); foreach ($businessUnits as $businessUnit) { if ($businessUnit->getOrganization()) { /** @var \Oro\Bundle\OrganizationBundle\Entity\BusinessUnit $businessUnit */ $tree->addBusinessUnit($businessUnit->getId(), $businessUnit->getOrganization()->getId()); if ($businessUnit->getOwner()) { $tree->addBusinessUnitRelation($businessUnit->getId(), $businessUnit->getOwner()->getId()); } } } foreach ($users as $user) { /** @var \Oro\Bundle\UserBundle\Entity\User $user */ $owner = $user->getOwner(); $tree->addUser($user->getId(), $owner ? $owner->getId() : null); foreach ($user->getOrganizations() as $organization) { $tree->addUserOrganization($user->getId(), $organization->getId()); foreach ($user->getBusinessUnits() as $businessUnit) { $organizationId = $organization->getId(); $buOrganizationId = $businessUnit->getOrganization()->getId(); if ($organizationId == $buOrganizationId) { $tree->addUserBusinessUnit($user->getId(), $organizationId, $businessUnit->getId()); } } } } }