public function modifyStructuralType(StructuralType &$structuralType)
 {
     $meta = $this->metaFactory->getMetadataForClass($structuralType->reflectionClass->getName());
     $availableProperties = array();
     $fkFieldNames = array();
     foreach (array('navigationProperties', 'dataProperties') as $properties) {
         if (!$structuralType->{$properties}) {
             continue;
         }
         $processedProperties = array();
         foreach ($structuralType->{$properties} as &$property) {
             if (isset($meta->propertyMetadata[$property->name])) {
                 $availableProperties[] = $property->name;
                 if ($meta->propertyMetadata[$property->name]->serializedName) {
                     $property->name = $meta->propertyMetadata[$property->name]->serializedName;
                 }
                 $processedProperties[] = $property;
                 if ($properties == 'navigationProperties') {
                     $fkey = $property->entityTypeName . '_' . $property->name;
                     //                        echo $fkey.'<br>';
                     if (isset($this->foreignKeys[$fkey])) {
                         $fkFieldNames[] = $this->foreignKeys[$fkey];
                     }
                 }
             } else {
                 if ($properties == 'dataProperties') {
                     if (in_array($property->name, $fkFieldNames)) {
                         $processedProperties[] = $property;
                     }
                 }
             }
         }
         $structuralType->{$properties} = $processedProperties;
     }
     foreach ($meta->propertyMetadata as $propertyName => $propertyMeta) {
         if (isset($this->excludedProperties[$propertyName]) && $this->excludedProperties[$propertyName]->structuralType === $structuralType) {
             continue;
         }
         if (!$propertyMeta->reflection || in_array($propertyName, $availableProperties)) {
             continue;
         }
         $dataProperty = new DataProperty();
         $dataProperty->name = $propertyMeta->serializedName ? $propertyMeta->serializedName : $propertyName;
         if ($propertyMeta->type && isset($propertyMeta->type['name'])) {
             $type = $propertyMeta->type['name'];
             $dataProperty->dataType = DataTypeMapper::fromDoctrineToOData($type, false);
         }
         if (!$dataProperty->dataType) {
             $dataProperty->dataType = DataTypeMapper::fromDoctrineToOData('string');
         }
         $structuralType->dataProperties[] = $dataProperty;
     }
     return $structuralType;
 }
 public static function getResourceType($entityManager, ClassMetadata $meta, $level = 0)
 {
     if (isset(self::$resourceTypes[$meta->getName()])) {
         return self::$resourceTypes[$meta->getName()];
     }
     $refClass = $meta->getReflectionClass();
     $namespace = null;
     $resourceType = new ResourceType($refClass, ResourceTypeKind::ENTITY, $refClass->getShortName(), $namespace);
     $addedProperties = array();
     foreach ($meta->fieldMappings as $fieldName => $data) {
         $type = $resourceType->getPrimitiveResourceType(DataTypeMapper::fromDoctrineToOData($data['type']));
         $kind = ResourcePropertyKind::PRIMITIVE;
         $resourceProperty = new ResourceProperty($fieldName, null, $kind, $type);
         $resourceType->addProperty($resourceProperty);
         $addedProperties[$fieldName] = $resourceProperty;
     }
     if ($level < self::LEVEL_MAX) {
         foreach ($meta->associationMappings as $fieldName => $data) {
             if ($associationMeta = $entityManager->getClassMetadata($data['targetEntity'])) {
                 $type = self::getResourceType($entityManager, $associationMeta, self::$level++);
                 $kind = ResourcePropertyKind::RESOURCE_REFERENCE;
                 $resourceProperty = new ResourceProperty($fieldName, null, $kind, $type);
                 $resourceType->addProperty($resourceProperty);
                 $fkFieldName = self::getForeignKeyFieldName($data, $entityManager);
                 if (!$fkFieldName) {
                     $fkFieldName = $data['fieldName'] . 'Id';
                 }
                 if ($fkFieldName) {
                     if (!isset($addedProperties[$fkFieldName])) {
                         //*
                         $type = $resourceType->getPrimitiveResourceType(DataTypeMapper::fromDoctrineToOData('integer'));
                         $kind = ResourcePropertyKind::PRIMITIVE;
                         $resourceProperty = new ResourceProperty($fkFieldName, null, $kind, $type);
                         $resourceType->addProperty($resourceProperty);
                         $addedProperties[$fieldName] = $resourceProperty;
                         //*/
                     }
                 }
                 //                        break;
             }
         }
     }
     self::$level = 1;
     return self::$resourceTypes[$meta->getName()] = $resourceType;
 }
 function createDataProperty(StructuralType &$structuralType, $fieldMapping)
 {
     $dataProperty = new DataProperty();
     $dataProperty->structuralType = $structuralType;
     $dataProperty->name = $fieldMapping['fieldName'];
     $dataProperty->dataType = DataTypeMapper::fromDoctrineToOData($fieldMapping['type']);
     if (isset($fieldMapping['nullable'])) {
         $dataProperty->isNullable = $fieldMapping['nullable'];
     }
     if (isset($fieldMapping['id'])) {
         $dataProperty->isPartOfKey = $fieldMapping['id'];
     }
     if (isset($fieldMapping['length'])) {
         $dataProperty->maxLength = $fieldMapping['length'];
     }
     if (in_array($fieldMapping['type'], array('array', 'simple_array', 'json_array'))) {
         $dataProperty->isScalar = false;
     }
     if ($this->isInheritanceEnabled()) {
         if (isset($fieldMapping['inherited'], $fieldMapping['declared']) && $fieldMapping['inherited']) {
             if ($this->interceptor) {
                 $this->interceptor->excludeProperty($dataProperty);
             }
             return false;
         }
     }
     return $dataProperty;
 }