/**
  * @param string $ownerType
  * @return string
  * @throws \InvalidArgumentException
  */
 protected function getOwnerTargetEntityClassName($ownerType)
 {
     switch ($ownerType) {
         case OwnershipType::OWNER_TYPE_USER:
             return $this->ownershipMetadataProvider->getUserClass();
         case OwnershipType::OWNER_TYPE_BUSINESS_UNIT:
             return $this->ownershipMetadataProvider->getBusinessUnitClass();
         case OwnershipType::OWNER_TYPE_ORGANIZATION:
             return $this->ownershipMetadataProvider->getOrganizationClass();
     }
     throw new \InvalidArgumentException(sprintf('Unexpected owner type: %s.', $ownerType));
 }
 public function testOwnerClassesConfigWithoutEntityClassResolver()
 {
     $configProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $provider = new OwnershipMetadataProvider(array('organization' => 'AcmeBundle\\Entity\\Organization', 'business_unit' => 'AcmeBundle\\Entity\\BusinessUnit', 'user' => 'AcmeBundle\\Entity\\User'), $configProvider);
     $this->assertEquals('AcmeBundle\\Entity\\Organization', $provider->getOrganizationClass());
     $this->assertEquals('AcmeBundle\\Entity\\BusinessUnit', $provider->getBusinessUnitClass());
     $this->assertEquals('AcmeBundle\\Entity\\User', $provider->getUserClass());
 }
 /**
  * Gets the id of logged in user
  *
  * @return int|string
  */
 public function getUserId()
 {
     $token = $this->getSecurityContext()->getToken();
     if (!$token) {
         return null;
     }
     $user = $token->getUser();
     if (!is_object($user) || !is_a($user, $this->metadataProvider->getUserClass())) {
         return null;
     }
     return $this->objectIdAccessor->getId($user);
 }
 public function testOwnerClassesConfig()
 {
     $this->entityClassResolver->expects($this->exactly(3))->method('getEntityClass')->will($this->returnValueMap([['AcmeBundle:Organization', 'AcmeBundle\\Entity\\Organization'], ['AcmeBundle:BusinessUnit', 'AcmeBundle\\Entity\\BusinessUnit'], ['AcmeBundle:User', 'AcmeBundle\\Entity\\User']]));
     $provider = new OwnershipMetadataProvider(['organization' => 'AcmeBundle:Organization', 'business_unit' => 'AcmeBundle:BusinessUnit', 'user' => 'AcmeBundle:User']);
     $provider->setContainer($this->container);
     $this->assertEquals('AcmeBundle\\Entity\\Organization', $provider->getGlobalLevelClass());
     $this->assertEquals('AcmeBundle\\Entity\\Organization', $provider->getOrganizationClass());
     $this->assertEquals('AcmeBundle\\Entity\\BusinessUnit', $provider->getLocalLevelClass());
     $this->assertEquals('AcmeBundle\\Entity\\BusinessUnit', $provider->getBusinessUnitClass());
     $this->assertEquals('AcmeBundle\\Entity\\User', $provider->getBasicLevelClass());
     $this->assertEquals('AcmeBundle\\Entity\\User', $provider->getUserClass());
 }
 /**
  * Gets a string represents the type of the given owner
  *
  * @param mixed $owner
  * @return string
  */
 protected function getOwnerType($owner)
 {
     if (is_a($owner, $this->ownershipMetadata->getUserClass())) {
         return OwnershipType::OWNER_TYPE_USER;
     } elseif (is_a($owner, $this->ownershipMetadata->getBusinessUnitClass())) {
         return OwnershipType::OWNER_TYPE_BUSINESS_UNIT;
     } elseif (is_a($owner, $this->ownershipMetadata->getOrganizationClass())) {
         return OwnershipType::OWNER_TYPE_ORGANIZATION;
     } else {
         return OwnershipType::OWNER_TYPE_NONE;
     }
 }
 /**
  * Check that the given object is a user
  *
  * @param  object $user
  * @throws InvalidDomainObjectException
  */
 protected function validateUserObject($user)
 {
     if (!is_object($user) || !$this->isUser($user)) {
         throw new InvalidDomainObjectException(sprintf('$user must be an instance of %s.', $this->metadataProvider->getUserClass()));
     }
 }