src/Sedona/SBORuntimeBundle/Datatable/Data/DatatableQuery.php
private function entityFieldToArray(array $data, $entity, $path)
    {
        $parts = explode('.', $path, 2);

        if (count($parts) === 1) {
            if ($entity instanceof \Traversable) {
                $data = [];

                foreach ($entity as $item) {
                    $id = $this->em->getClassMetadata(get_class($item))->getSingleIdentifierColumnName();

                    $data[] = [
                        $id => $this->propertyAccessor->getValue($item, $id),
                        $parts[0] => $this->propertyAccessor->getValue($item, $parts[0]),
                    ];
                }
            } else {
                if (count($data) === 0) {
                    $data = [];
                    $id = $this->em->getClassMetadata(get_class($entity))->getSingleIdentifierColumnName();
                    $data[$id] = $this->propertyAccessor->getValue($entity, $id);
                }

                $data[$parts[0]] = $this->propertyAccessor->getValue($entity, $parts[0]);
            }

            return $data;
        } else {
            $data[$parts[0]] = $this->entityFieldToArray(
                isset($data[$parts[0]]) ? $data[$parts[0]] : [],
                $this->propertyAccessor->getValue($entity, $parts[0]),
                $parts[1]
            );

            return $data;
        }
    }
private function entityFieldToArray(array $data, $entity, $path)
    {
        $parts = explode('.', $path, 2);

        if (count($parts) === 1) {
            if ($entity instanceof \Traversable) {
                $data = [];

                foreach ($entity as $item) {
                    $id = $this->em->getClassMetadata(get_class($item))->getSingleIdentifierColumnName();

                    $data[] = [
                        $id => $this->propertyAccessor->getValue($item, $id),
                        $parts[0] => $this->propertyAccessor->getValue($item, $parts[0]),
                    ];
                }
            } else {
                if (count($data) === 0) {
                    $data = [];
                    $id = $this->em->getClassMetadata(get_class($entity))->getSingleIdentifierColumnName();
                    $data[$id] = $this->propertyAccessor->getValue($entity, $id);
                }

                $data[$parts[0]] = $this->propertyAccessor->getValue($entity, $parts[0]);
            }

            return $data;
        } else {
            $data[$parts[0]] = $this->entityFieldToArray(
                isset($data[$parts[0]]) ? $data[$parts[0]] : [],
                $this->propertyAccessor->getValue($entity, $parts[0]),
                $parts[1]
            );

            return $data;
        }
    }
private function entityFieldToArray ( array $ data , $ entity , $ path ) { $ parts = explode ( '.' , $ path , 2 ) ; if ( count ( $ parts ) === 1 ) { if ( $ entity instanceof \ Traversable ) { $ data = [ ] ; foreach ( $ entity as $ item ) { $ id = $ this -> em -> getClassMetadata ( get_class ( $ item ) ) -> getSingleIdentifierColumnName ( ) ; $ data [ ] = [ $ id => $ this -> propertyAccessor -> getValue ( $ item , $ id ) , $ parts [ 0 ] => $ this -> propertyAccessor -> getValue ( $ item , $ parts [ 0 ] ) , ] ; } } else { if ( count ( $ data ) === 0 ) { $ data = [ ] ; $ id = $ this -> em -> getClassMetadata ( get_class ( $ entity ) ) -> getSingleIdentifierColumnName ( ) ; $ data [ $ id ] = $ this -> propertyAccessor -> getValue ( $ entity , $ id ) ; } $ data [ $ parts [ 0 ] ] = $ this -> propertyAccessor -> getValue ( $ entity , $ parts [ 0 ] ) ; } return $ data ; } else { $ data [ $ parts [ 0 ] ] = $ this -> entityFieldToArray ( isset ( $ data [ $ parts [ 0 ] ] ) ? $ data [ $ parts [ 0 ] ] : [ ] , $ this -> propertyAccessor -> getValue ( $ entity , $ parts [ 0 ] ) , $ parts [ 1 ] ) ; return $ data ; } }
Normalizes an entity path into an array.
Each entity of each level will have its id set.
All values are retrieved using a property accessor with magic call activated.

@param array  $data
@param object $entity Entity to normalize
@param string $path   Path to set in the array

@return array Normalized data
Normalizes an entity path into an array . Each entity of each level will have its id set . All values are retrieved using a property accessor with magic call activated .