src/Cache/DatabaseTreeCache.php
public function getParentRecords(string $table, int $id, $maxLevels = null, string $key = 'id', array $parents = [], int $level = 0): array
    {
        if (null === ($tree = $this->getTreeCache($table, $key))) {
            return $this->database->getParentRecords($id, $table);
        }

        if (isset($tree[$id]) && 0 === $level) {
            $parents[] = $id;
        }

        foreach ($tree as $pid => $ids) {
            if (!\in_array($id, $ids)) {
                continue;
            }

            $parents[] = $pid;

            if (1 === $maxLevels) {
                continue;
            }

            if ($maxLevels > 0 && $level > $maxLevels) {
                return [];
            }

            if (!empty($nested = self::getParentRecords($table, $pid, $maxLevels, $key, $parents, ++$level))) {
                $parents = $nested;
            } else {
                $level = 0;
            }
        }

        return $parents;
    }
public function getParentRecords(string $table, int $id, $maxLevels = null, string $key = 'id', array $parents = [], int $level = 0): array
    {
        if (null === ($tree = $this->getTreeCache($table, $key))) {
            return $this->database->getParentRecords($id, $table);
        }

        if (isset($tree[$id]) && 0 === $level) {
            $parents[] = $id;
        }

        foreach ($tree as $pid => $ids) {
            if (!\in_array($id, $ids)) {
                continue;
            }

            $parents[] = $pid;

            if (1 === $maxLevels) {
                continue;
            }

            if ($maxLevels > 0 && $level > $maxLevels) {
                return [];
            }

            if (!empty($nested = self::getParentRecords($table, $pid, $maxLevels, $key, $parents, ++$level))) {
                $parents = $nested;
            } else {
                $level = 0;
            }
        }

        return $parents;
    }
public function getParentRecords ( string $ table , int $ id , $ maxLevels = null , string $ key = 'id' , array $ parents = [ ] , int $ level = 0 ) : array { if ( null === ( $ tree = $ this -> getTreeCache ( $ table , $ key ) ) ) { return $ this -> database -> getParentRecords ( $ id , $ table ) ; } if ( isset ( $ tree [ $ id ] ) && 0 === $ level ) { $ parents [ ] = $ id ; } foreach ( $ tree as $ pid => $ ids ) { if ( ! \ in_array ( $ id , $ ids ) ) { continue ; } $ parents [ ] = $ pid ; if ( 1 === $ maxLevels ) { continue ; } if ( $ maxLevels > 0 && $ level > $ maxLevels ) { return [ ] ; } if ( ! empty ( $ nested = self :: getParentRecords ( $ table , $ pid , $ maxLevels , $ key , $ parents , ++ $ level ) ) ) { $ parents = $ nested ; } else { $ level = 0 ; } } return $ parents ; }
Get all parent records for given child entity.

@param string $table     The database table
@param int    $id        The current entity id
@param int    $maxLevels The max stop level
@param string Custom index key (default: primary key from model)
@param array $parents Internal children return array
@param int   $level   Internal depth attribute

@return array An array containing all children for given parent entities
Get all parent records for given child entity .