public function testSerialization()
 {
     $metadata = new OwnershipMetadata('ORGANIZATION', 'org', 'org_id');
     $data = serialize($metadata);
     $metadata = new OwnershipMetadata();
     $this->assertFalse($metadata->isOrganizationOwned());
     $this->assertEquals('', $metadata->getOwnerFieldName());
     $this->assertEquals('', $metadata->getOwnerColumnName());
     $metadata = unserialize($data);
     $this->assertTrue($metadata->isOrganizationOwned());
     $this->assertEquals('org', $metadata->getOwnerFieldName());
     $this->assertEquals('org_id', $metadata->getOwnerColumnName());
 }
 /**
  * Gets the name of owner column
  *
  * @param OwnershipMetadata $metadata
  * @param null $columnName
  * @return null|string
  */
 protected function getColumnName(OwnershipMetadata $metadata, $columnName = null)
 {
     if ($columnName === null) {
         $columnName = $metadata->getOwnerFieldName();
     }
     return $columnName;
 }
Beispiel #3
0
 /**
  * Get entity organization id
  *
  * @param OwnershipMetadata $metadata
  * @param object            $entity
  *
  * @return int
  */
 protected function getOrganizationId(OwnershipMetadata $metadata, $entity)
 {
     $organizationId = self::EMPTY_ORGANIZATION_ID;
     $organizationField = null;
     if ($metadata->getGlobalOwnerFieldName()) {
         $organizationField = $metadata->getGlobalOwnerFieldName();
     }
     if ($metadata->isGlobalLevelOwned()) {
         $organizationField = $metadata->getOwnerFieldName();
     }
     if ($organizationField) {
         /** @var Organization $organization */
         $organization = $this->getPropertyAccessor()->getValue($entity, $organizationField);
         if ($organization && null !== $organization->getId()) {
             $organizationId = $organization->getId();
         }
     }
     return $organizationId;
 }
 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);
 }