public function isOffspringOf(Hierarchy $element, LoaderInterface $loader = null)
    {
        if (get_class($element) !== get_class($this))
            return 0;

        $stack = [];
        $parents = $this->getParents($loader);
        foreach ($parents as $p)
            $stack[] = [1, $p];

        $seen = [];
        $level = 0;
        while (!empty($stack))
        {
            list($level, $cur) = array_shift($stack);

            // Avoid infinite cycles
            if (isset($seen[$cur->id]))
                continue;

            // If the ancestor is the requested element, we found our answer
            if ($cur->id === $element->id)
                return $level;

            // Add all parents of this element to the stack
            $parents = $loader === null ? $cur->getParents() : $cur->getParents($loader);
            foreach ($cur->getParents($loader) as $p)
                $stack[] = [$level + 1, $p];

            // Store seen entities to avoid cycles
            $seen[$cur->id] = true;
        }

        // Nothing found
        return 0;
    }
public function isOffspringOf(Hierarchy $element, LoaderInterface $loader = null)
    {
        if (get_class($element) !== get_class($this))
            return 0;

        $stack = [];
        $parents = $this->getParents($loader);
        foreach ($parents as $p)
            $stack[] = [1, $p];

        $seen = [];
        $level = 0;
        while (!empty($stack))
        {
            list($level, $cur) = array_shift($stack);

            // Avoid infinite cycles
            if (isset($seen[$cur->id]))
                continue;

            // If the ancestor is the requested element, we found our answer
            if ($cur->id === $element->id)
                return $level;

            // Add all parents of this element to the stack
            $parents = $loader === null ? $cur->getParents() : $cur->getParents($loader);
            foreach ($cur->getParents($loader) as $p)
                $stack[] = [$level + 1, $p];

            // Store seen entities to avoid cycles
            $seen[$cur->id] = true;
        }

        // Nothing found
        return 0;
    }
public function isOffspringOf ( Hierarchy $ element , LoaderInterface $ loader = null ) { if ( get_class ( $ element ) !== get_class ( $ this ) ) return 0 ; $ stack = [ ] ; $ parents = $ this -> getParents ( $ loader ) ; foreach ( $ parents as $ p ) $ stack [ ] = [ 1 , $ p ] ; $ seen = [ ] ; $ level = 0 ; while ( ! empty ( $ stack ) ) { list ( $ level , $ cur ) = array_shift ( $ stack ) ; // Avoid infinite cycles if ( isset ( $ seen [ $ cur -> id ] ) ) continue ; // If the ancestor is the requested element, we found our answer if ( $ cur -> id === $ element -> id ) return $ level ; // Add all parents of this element to the stack $ parents = $ loader === null ? $ cur -> getParents ( ) : $ cur -> getParents ( $ loader ) ; foreach ( $ cur -> getParents ( $ loader ) as $ p ) $ stack [ ] = [ $ level + 1 , $ p ] ; // Store seen entities to avoid cycles $ seen [ $ cur -> id ] = true ; } // Nothing found return 0 ; }
Check if the current element is offspring of the specified element

@param $role Hierarchy The element to check
@param $loader LoaderInterface A loader that can be used to load additional instances
@return integer The number of generation levels between the $this and $element - 0 if they're not related
Check if the current element is offspring of the specified element