Creates an SQL part to exclude the parent node from a query to fetch children of the node $nodeID, if needed

@param int $nodeID
@param int|bool $depth
@param string $depthOperator
@return string
776414
static function createNotEqParentSQLString( $nodeID, $depth = false, $depthOperator = 'le' )
    {
        $notEqParentString  = '';
        if( !$depth || $depthOperator == 'le' || $depthOperator == 'lt' )
        {
            $notEqParentString  = "ezcontentobject_tree.node_id != $nodeID AND";
        }

        return $notEqParentString;
    }
243514
public function rebuildTree($idParent = 0, $left = 1, $depth = 0)
    {
        ini_set('xdebug.max_nesting_level', 10000);
        ini_set('memory_limit', '-1');

        if ($childs = $this->qb
            ->table($this->table)
            ->select('id')
            ->where($this->parentKey, $idParent)
            ->orderBy('id')
            ->get()) {

            $right = $left + 1;

            $i = 0;
            foreach ($childs as $child) {
                if ($i == 0) {
                    $this->qb
                        ->from($this->table)
                        ->where('id', $child->id)
                        ->update($update = [
                            'record_left'  => $left,
                            'record_right' => $right,
                            'record_depth' => $depth,
                        ]);
                } else {
                    $this->qb
                        ->from($this->table)
                        ->where('id', $child->id)
                        ->update($update = [
                            'record_left'  => $left = $right + 1,
                            'record_right' => $right = $left + 1,
                            'record_depth' => $depth,
                        ]);
                }

                $update[ 'id' ] = $child->id;

                if ($this->qb
                    ->table($this->table)
                    ->select('id')
                    ->where($this->parentKey, $child->id)
                    ->orderBy('id')
                    ->get()) {
                    $right = $this->rebuildTree($child->id, $right, $depth + 1);
                    $this->qb
                        ->from($this->table)
                        ->where('id', $child->id)
                        ->update($update = [
                            'record_right' => $right,
                        ]);
                    $update[ 'id' ] = $child->id;
                }

                $i++;
            }
        }

        return $right + 1;
    }
1129810
public function getHtml($nodeId, $level)
    {
        $classes = $level == 0 ? 'level-top' : '';
        $node = $this->nodes[$nodeId];
        $url = $this->_storeManager->getStore()->getBaseUrl() . $node->getContent();
        $title = $node->getTitle();

        return <<<HTML
<a href="$url" class="$classes" role="menuitem"><span>$title</span></a>
HTML;
    }
472453
private function createWebspaceNode(
        $webspaceKey,
        $languageCode,
        $depth = 1,
        $excludeGhosts = false
    ) {
        $webspace = $this->webspaceManager->getWebspaceCollection()->getWebspace($webspaceKey);

        if ($depth > 0) {
            $nodes = $this->getMapper()->loadByParent(
                null,
                $webspaceKey,
                $languageCode,
                $depth,
                false,
                false,
                $excludeGhosts
            );
            $embedded = $this->prepareNodesTree($nodes, $webspaceKey, $languageCode, true, $excludeGhosts, $depth);
        } else {
            $embedded = [];
        }

        return [
            'id' => $this->sessionManager->getContentNode($webspace->getKey())->getIdentifier(),
            'path' => '/',
            'title' => $webspace->getName(),
            'hasSub' => true,
            'publishedState' => true,
            '_embedded' => $embedded,
            '_links' => [
                'children' => [
                    'href' => $this->apiBasePath . '?depth=' . $depth . '&webspace=' . $webspaceKey .
                        '&language=' . $languageCode . (true === $excludeGhosts ? '&exclude-ghosts=true' : ''),
                ],
            ],
        ];
    }
820178
private function searchTree($depth = 0)
    {
        $this->depth = $depth;
        foreach ($this->children->getList() as $node) {
            if ($depth > count($this->treePath)) {
                break;
            }

            if ($this->treePath[$depth] != $node->key) {
                continue;
            }

            /**
             * @var $node TreeNode
             */
            if (count($this->treePath) > $depth && $this->allowedToDiveDeeper($depth)) {
                $node->setTreepath($this->treePath);

                return $node->searchTree(++$depth);
            }
        }

        return $this;
    }
132873
public static function getCategoryTreeIds($categoryId, $depth = 1)
    {
        $result = \is_array($categoryId) ? $categoryId : [ $categoryId ];

        if ($depth > 1) {
            $categories = self::create()
                ->filterByParent($categoryId, Criteria::IN)
                ->withColumn('id')
                ->find();

            foreach ($categories as $category) {
                $result = array_merge(
                    $result,
                    self::getCategoryTreeIds($category->getId(), $depth - 1)
                );
            }
        }

        return $result;
    }
588659
public function moveNodeTo($ancestorId = null)
    {
        $table = $this->getPrefixedTable();
        $ancestor = $this->getAncestorColumn();
        $descendant = $this->getDescendantColumn();
        $depth = $this->getDepthColumn();

        $thisAncestorId = $this->ancestor;
        $thisDescendantId = $this->descendant;

        // Prevent constraint collision
        if (!is_null($ancestorId) && $thisAncestorId === $ancestorId) {
            return;
        }

        $this->unbindRelationships();

        // Since we have already unbound the node relationships,
        // given null ancestor id, we have nothing else to do,
        // because now the node is already root.
        if (is_null($ancestorId)) {
            return;
        }

        $query = "
            INSERT INTO {$table} ({$ancestor}, {$descendant}, {$depth})
            SELECT supertbl.{$ancestor}, subtbl.{$descendant}, supertbl.{$depth}+subtbl.{$depth}+1
            FROM {$table} as supertbl
            CROSS JOIN {$table} as subtbl
            WHERE supertbl.{$descendant} = {$ancestorId}
            AND subtbl.{$ancestor} = {$thisDescendantId}
        ";

        DB::connection($this->connection)->statement($query);
    }
322976
public function createQueryBuilderWithParentRoot($parent_id, $include_parent = true)
    {
        $query = $this->createQueryBuilder();
        return $this->alterQueryBuilderWithParentRoot($query, $parent_id, $include_parent);
    }
695699
public static function existsInParentsChain($nodeId, $parentId)
    {
        $nextParentId = $parentId;
        $exists = false;
        while (true) {
            if ($nodeId == $nextParentId) {
                $exists = true;
                break;
            }

            $nextParentNode = static::node($nextParentId);
            if (empty($nextParentNode)) break;

            $nextParentId = $nextParentNode['parent_id'];
         }

         return $exists;
    }
39430
private static function displayInventoryTreeHelper(
        AdUnit $root,
        array $treeMap,
        $depth
    ) {
        $rootId = $root->getId();

        printf(
            "%s%s(%s)%s",
            self::generateTab($depth),
            $root->getName(),
            $rootId,
            PHP_EOL
        );

        if (!array_key_exists($rootId, $treeMap) || empty($treeMap[$rootId])) {
            return;
        }

        foreach ($treeMap[$rootId] as $child) {
            self::displayInventoryTreeHelper($child, $treeMap, $depth + 1);
        }
    }
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;
    }
831901
public function getAncestors($levelLimit = 0, $includeNode = false)
	{
		$left = $this->getLeftValue();
		$right = $this->getRightValue();
		$level = $this->getLevel();

		$searchCondition = $this->repository->createSearchCondition();
		
		// Will include the self node if required in the end
		$searchCondition->leftLessThan($left)
				->rightGreaterThan($right);

		if ($levelLimit < 0) {
			throw new Exception\Domain("Level limit cannot be negative in getAncestors method");
		} elseif ($levelLimit > 0) {
			$searchCondition->levelGreaterThanOrEqualsTo($level - $levelLimit);
		}

		$orderRule = $this->repository->createSelectOrderRule()
				->byLevelDescending();

		$ancestors = $this->repository->search($searchCondition, $orderRule);
		
		// Fixes not flushed node returning
		if ($includeNode) {
			if (isset($this->masterNode)) {
				array_unshift($ancestors, $this->masterNode);
			} else {
				array_unshift($ancestors, $this);
			}
		}
		
		return $ancestors;
	}
124658
public function getAncestor($itemName, $depth = 0)
    {
        $ancestors = array();
        $parents = $this->getParents($itemName);
        if (empty($parents)) {
            $parents = $this->owner->db->createCommand()
                ->select('parent')
                ->from($this->owner->itemChildTable)
                ->where('child=:child', array(':child' => $itemName))
                ->queryColumn();
            $this->setItemParents($itemName, $parents);
        }

        foreach ($parents as $parent) {
            $ancestors[] = array(
                'name' => $parent,
                'item' => $this->owner->getAuthItem($parent),
                'parents' => $this->getAncestor($parent, $depth + 1),
                'depth' => $depth
            );
        }
        return $ancestors;
    }
543747
public function populateTree($depth = null)
    {
        /** @var ActiveRecord|MaterializedPathBehavior $nodes */
        $nodes = $this
            ->getDescendants($depth)
            ->indexBy($this->keyAttribute)
            ->all();
        $relates = [];
        foreach ($nodes as $key => $node) {
            $parentKey = $node->getParentKey();
            if (!isset($relates[$parentKey])) {
                $relates[$parentKey] = [];
            }
            $relates[$parentKey][] = $node;
        }
        $nodes[$this->owner->{$this->keyAttribute}] = $this->owner;
        foreach ($relates as $key => $children) {
            $nodes[$key]->populateRelation('children', $children);
        }
        return $this->owner;
    }
711234
public function getNode($nodeId)
    {
        static $instance = array();
        if (isset($instance[$nodeId]))
            return $instance[$nodeId];
        $nodes = $this->nodeSet;
        if (empty($nodes))
            return NULL;
        foreach ($nodes as $node):
            if ($node->getId() == $nodeId):
                $instance[$nodeId] = &$node;
                break;
            endif;
        endforeach;
        return NULL;
    }
630408
def nodes(self, alias, depth=10, bank_id=None):
        
        if bank_id:
            return self._root + self._safe_alias(alias) + '/child/nodes/' + bank_id + '?descendentlevels=' + str(depth)
        else:
            return self._root + self._safe_alias(alias) + '/root/nodes?descendentlevels=' + str(depth)
303358
private static function filterAndOr($operation, QueryBuilder $queryBuilder)
    {
        $children = $operation['children'];

        if (empty($children)) {
            return;
        }

        $whereOperation = strtolower($operation['operation']) . 'Where';

        foreach ($children as $child) {
            $queryBuilder->{$whereOperation}(static::calculateSubFilter($child, $queryBuilder));
        }
    }