Ejemplo n.º 1
0
 /**
  * Get entity owner id
  *
  * @param OwnershipMetadata $metadata
  * @param object            $entity
  *
  * @return int
  */
 protected function getOwnerId(OwnershipMetadata $metadata, $entity)
 {
     $ownerId = self::EMPTY_OWNER_ID;
     if (in_array($metadata->getOwnerType(), [OwnershipMetadata::OWNER_TYPE_USER, OwnershipMetadata::OWNER_TYPE_BUSINESS_UNIT])) {
         $owner = $this->getPropertyAccessor()->getValue($entity, $metadata->getOwnerFieldName());
         if ($owner && $owner->getId()) {
             $ownerId = $owner->getId();
         }
     }
     return $ownerId;
 }
Ejemplo n.º 2
0
 public function testUserOwnership()
 {
     $metadata = new OwnershipMetadata('USER', 'usr', 'user_id');
     $this->assertEquals(OwnershipMetadata::OWNER_TYPE_USER, $metadata->getOwnerType());
     $this->assertTrue($metadata->hasOwner());
     $this->assertFalse($metadata->isOrganizationOwned());
     $this->assertFalse($metadata->isBusinessUnitOwned());
     $this->assertTrue($metadata->isUserOwned());
     $this->assertEquals('usr', $metadata->getOwnerFieldName());
     $this->assertEquals('user_id', $metadata->getOwnerColumnName());
 }
Ejemplo n.º 3
0
 public function testSetState()
 {
     $metadata = new OwnershipMetadata('ORGANIZATION', 'org', 'org_id');
     $restoredMetadata = $metadata->__set_state(['ownerType' => $metadata->getOwnerType(), 'ownerFieldName' => $metadata->getOwnerFieldName(), 'ownerColumnName' => $metadata->getOwnerColumnName(), 'not_exists' => true]);
     $this->assertEquals($metadata, $restoredMetadata);
 }