Gets real depth of the new ancestor of the model.

@param Entity|int|null $ancestor
@return int
507940
protected function getNewRealDepth($ancestor)
    {
        if (!$ancestor instanceof EntityInterface) {
            if (is_null($ancestor)) {
                return 0;
            } else {
                return static::find($ancestor)->real_depth + 1;
            }
        } else {
            return $ancestor->real_depth + 1;
        }
    }
752469
private function hasAncestorGuid( $entry, $ancestor )
	{
		if (
				( isset( $entry['parent'] ) && isset( $ancestor['parent'] ) && ( $entry['parent'] == $ancestor['parent'] ) ) || // The item is a sibling
				( isset( $entry['parent'] ) && ( $entry['parent'] == $ancestor['guid'] ) ) || // The item is a child
				( $entry['guid'] == $ancestor['guid'] ) // Same
		   )
		{
			return true;
		}

		if ( $entry['guid'] == 'xbrl' || $entry['parent'] == 'xbrl' )
		{
			return false; // If here and the entry guid is xbrl there can be no parent or match
		}

		$parent =& $this->getEntryForGuid( $entry['parent'] );
		if ( ! $parent ) return false;
		return $this->hasAncestorGuid( $parent, $ancestor );
	}
803767
public function getLogEntriesRoot($entity, $rootVersion = null)
    {
        $q = $this->getLogEntriesQueryRoot($entity, $rootVersion);

        return $q->getResult();
    }
331120
public function getParent()
    {
        if($this->isRoot())
        {
            return null;
        }

        if($this->parent == null && $this->ancestors)
        {
            // Shortcut if we already loaded the ancestors
            $this->parent = $this->ancestors[count($this->ancestors)-1];
        }

        if($this->parent == null)
        {
            $qb = $this->getManager()->getConfiguration()->getBaseQueryBuilder();
            $alias = $this->getManager()->getConfiguration()->getQueryBuilderAlias();

            $qb->andWhere("$alias.".$this->getLeftFieldName()." < :lft1")
                ->setParameter('lft1', $this->getLeftValue())
                ->andWhere("$alias.".$this->getRightFieldName()." > :rgt1")
                ->setParameter('rgt1', $this->getRightValue())
                ->orderBy("$alias.".$this->getRightFieldName(), "ASC")
                ->setMaxResults(1);
            if($this->hasManyRoots())
            {
                $qb->andWhere("$alias.".$this->getRootFieldName()." = :root")
                    ->setParameter('root', $this->getRootValue());
            }

			$q = $qb->getQuery();
			if ($this->getManager()->getConfiguration()->isQueryHintSet()){
				$q = $this->getManager()->addHintToQuery($q);
			}
			$results = $q->getResult();
			
            $this->parent = $this->getManager()->wrapNode($results[0]);
        }

        return $this->parent;
    }
408216
public function ancestor($lookup = null)
    {
        /** @var Pages $pages */
        $pages = Grav::instance()['pages'];

        return $pages->ancestor($this->route, $lookup);
    }
950741
public function getDepth(): int
    {
        $depth = parent::getDepth();
        $paths = array_filter(array_map(
            /**
             * Extracts error path.
             *
             * @param Invalid $error the exception
             *
             * @return array|null
             */
            function(Invalid $error) {
                return $error->getPath();
            },
            $this->errors
        ));

        if ($paths && ($max = max(array_map('count', $paths))) > $depth) {
            $depth = $max;
        }

        return $depth;
    }
559822
public static function getAncestorModels($ancestor)
    {
        if (empty($ancestor) || !is_array($ancestor)) {
            return [];
        }
        $models = [];
        foreach ($ancestor as $self) {
            $models[] = static::findOne($self);
        }
        return $models;
    }
591420
public function depthFirst($tree = [], \Closure $callback = null)
    {
        if (!$tree) {
            $tree = $this->tree;
        }
        foreach ($tree as $node) {
            if ($callback) {
                call_user_func_array($callback, ['node' => $node]);
            }
            $children = $node['children'];
            if ($children) {
                $this->depthFirst($children, $callback);
            }
        }
    }
706298
public function getLogEntriesQueryRoot($entity, $rootVersion = null)
    {
        $wrapped = new EntityWrapper($entity, $this->_em);
        $objectClass = $wrapped->getMetadata()->name;
        $meta = $this->getClassMetadata();
        $dql = "SELECT log FROM {$meta->name} log";
        $dql .= " WHERE log.objectId = :objectId";
        $dql .= " AND log.objectClass = :objectClass";
        $dql .= " AND log.rootVersion <= :rootVersion";
        $dql .= " ORDER BY log.version DESC";

        $objectId = $wrapped->getIdentifier();
        $q = $this->_em->createQuery($dql);
        $q->setParameters(compact('objectId', 'objectClass', 'rootVersion'));

        return $q;
    }
800079
function(depth) {
        if (depth >= this.depth || depth < 0)  {
            this.logger.log("illegal getAncestor depth: " + depth);
            return null;
        }

        var p = this.parent;
        
        while (p.depth > depth) {
            p = p.parent;
        }

        return p;
    }
936465
public function getAncestry($id)
    {
        $tbl = $this->hierarchyTable;
        $recursive = "SELECT c.term_id, c.parent_id from $tbl as c join :tmp_tbl as p on p.parent_id = c.term_id";

        $raw_query = $this->assembleQuery($this->getAncestryInitialQuery(), $recursive);

        return $this->runQuery($raw_query, $id);
    }
1240476
public function getParent()
    {
        $depth = $this->iterator->getDepth();

        return $depth === 0
            ? $this->id
            : $this->iterator->getSubIterator($depth - 1)->key();
    }
1129518
protected function getNodeDepth(DomNode $node)
    {
        // initial depth for top level elements (to avoid "ifs")
        $depth = -2;

        while ($node) {
            ++$depth;
            $node = $node->parentNode;
        }

        return $depth;
    }
380662
protected function arrayDepth($element, $depth = 1) {
        if (is_array($element)) {
            $maxDepth = $depth;
            foreach($element as $el) {
                $d = $this->arrayDepth($el, $depth + 1);
                if ($d > $maxDepth) {
                    $maxDepth = $d;
                }
            }
            return $maxDepth;
        } else {
            return $depth;
        }
    }
425367
def deepest_common_ancestor(goterms, godag):
    '''
        
    '''
    # Take the element at maximum depth.
    return max(common_parent_go_ids(goterms, godag), key=lambda t: godag[t].depth)
216712
def get_ancestors(self, include_self=False, depth=None):
        """"""
        if self.is_root_node():
            if not include_self:
                return self._toplevel().objects.none()
            else:
                # Filter on pk for efficiency.
                return self._toplevel().objects.filter(pk=self.pk)

        params = {"%s__child" % self._closure_parentref():self.pk}
        if depth is not None:
            params["%s__depth__lte" % self._closure_parentref()] = depth
        ancestors = self._toplevel().objects.filter(**params)
        if not include_self:
            ancestors = ancestors.exclude(pk=self.pk)
        return ancestors.order_by("%s__depth" % self._closure_parentref())
1287494
public function setDepth(int $depth): int
    {
        $oldDepth = $this->depth;
        $this->depth = $depth;

        return $oldDepth;
    }