Drest\Query\ExposeFields::processExposeDepth PHP Method

processExposeDepth() protected method

Recursive function to generate default expose columns
protected processExposeDepth ( array &$fields, string $class, Drest\EntityManagerRegistry $emr, integer $depth, integer $fetchType = null )
$fields array - array to be populated recursively (referenced)
$class string - name of the class to process
$emr Drest\EntityManagerRegistry - entity manager registry used to fetch class information
$depth integer - maximum depth you want to travel through the relations
$fetchType integer - The fetch type to be used
    protected function processExposeDepth(&$fields, $class, EntityManagerRegistry $emr, $depth = 0, $fetchType = null)
    {
        $this->registered_expose_classes[] = $class;
        if ($depth > 0) {
            /** @var \Doctrine\ORM\Mapping\ClassMetaData $metaData */
            $metaData = $emr->getManagerForClass($class)->getClassMetadata($class);
            $fields = $metaData->getColumnNames();
            if ($depth - 1 > 0) {
                --$depth;
                foreach ($metaData->getAssociationMappings() as $key => $assocMapping) {
                    if (!in_array($assocMapping['targetEntity'], $this->registered_expose_classes) && (is_null($fetchType) || $assocMapping['fetch'] == $fetchType)) {
                        $this->processExposeDepth($fields[$key], $assocMapping['targetEntity'], $emr, $depth, $fetchType);
                    }
                }
            }
        }
    }