Updating descendants nodes

@param Tree       $node           Updated node
@param Collection $oldDescendants Old descendants collection (just before modify parent)
422708
protected function updateDescendants(Tree $node, $oldDescendants)
    {
        $refs                  = [];
        $refs[$node->getKey()] = &$node; // Updated node
        foreach ($oldDescendants as &$child) {
            $refs[$child->getKey()] = $child;
            $parent_id              = $child->{$this->getTreeColumn('parent')};
            if (!empty($refs[$parent_id])) {
                if ($refs[$parent_id]->path != $refs[$child->getKey()]->removeLastNodeFromPath()) {
                    $refs[$child->getKey()]->level = $refs[$parent_id]->level + 1; // New level
                    $refs[$child->getKey()]->path  = $refs[$parent_id]->path . $child->getKey() . '/'; // New path
                    DB::table($this->getTable())
                        ->where($child->getKeyName(), '=', $child->getKey())
                        ->update(
                            [
                                $this->getTreeColumn('level') => $refs[$child->getKey()]->level,
                                $this->getTreeColumn('path')  => $refs[$child->getKey()]->path
                            ]
                        );
                }
            }
        }
        $this->fireModelEvent('updatedDescendants', false);
    }
1267161
function addDescendantsToDrag(node, opts) {
    if (!node.cy().hasCompoundNodes()) {
      return;
    }

    if (opts.inDragLayer == null && opts.addToList == null) {
      return;
    } // nothing to do


    var innerNodes = node.descendants();

    if (opts.inDragLayer) {
      innerNodes.forEach(setInDragLayer);
      innerNodes.connectedEdges().forEach(setInDragLayer);
    }

    if (opts.addToList) {
      opts.addToList.unmerge(innerNodes);
    }
  }
1327182
function addNodesToDrag(nodes, opts) {
    opts = opts || {};
    var hasCompoundNodes = nodes.cy().hasCompoundNodes();

    if (opts.inDragLayer) {
      nodes.forEach(setInDragLayer);
      nodes.neighborhood().stdFilter(function (ele) {
        return !hasCompoundNodes || ele.isEdge();
      }).forEach(setInDragLayer);
    }

    if (opts.addToList) {
      nodes.forEach(function (ele) {
        addToDragList(ele, opts);
      });
    }

    addDescendantsToDrag(nodes, opts); // always add to drag
    // also add nodes and edges related to the topmost ancestor

    updateAncestorsInDragLayer(nodes, {
      inDragLayer: opts.inDragLayer
    });
    r.updateCachedGrabbedEles();
  }
249453
public function visitAfter(Node $node): void
    {
        foreach ($this->visitors as $visitor) {
            $visitor->visitAfter($node);
        }

        parent::visitAfter($node);
    }
1060295
public function setNodes($akTopicParentNodeID, $akTopicTreeID)
    {
        /** @var TopicsSettings $type */
        $type = $this->getAttributeKey()->getAttributeKeySettings();
        $type->setParentNodeID($akTopicParentNodeID);
        $type->setTopicTreeID($akTopicTreeID);
        $this->entityManager->persist($type);
        $this->entityManager->flush();
    }
83195
public function childrenHierarchyWithNodes($node = null, $direct = false, array $options = [], $includeNode = false)
    {
        $tree = $this->childrenHierarchy($node, $direct, $options, $includeNode);

        return $this->fillTreeNodes($tree);
    }
944763
function(node) { 
        var p = node.parent;

        // Update the parent's collection of children
        var a = [];

        for (var i=0, len=p.children.length;i<len;++i) {
            if (p.children[i] != node) {
                a[a.length] = p.children[i];
            }
        }

        p.children = a;

        // reset the childrenRendered flag for the parent
        p.childrenRendered = false;

         // Update the sibling relationship
        if (node.previousSibling) {
            node.previousSibling.nextSibling = node.nextSibling;
        }

        if (node.nextSibling) {
            node.nextSibling.previousSibling = node.previousSibling;
        }

		if (this.currentFocus == node) {
			this.currentFocus = null;
		}
		if (this._currentlyHighlighted == node) {
			this._currentlyHighlighted = null;
		}

        node.parent = null;
        node.previousSibling = null;
        node.nextSibling = null;
        node.tree = null;

        // Update the tree's node collection 
        delete this._nodes[node.index];
    }
834620
protected function ancestorsIndividuals(Tree $tree, Collection $ancestors): ResponseInterface
    {
        $this->layout = 'layouts/ajax';

        return $this->viewResponse('lists/individuals-table', [
            'individuals' => $ancestors,
            'sosa'        => true,
            'tree'        => $tree,
        ]);
    }
317336
private function siblingOfRoot(Tree $node, Collection $roots)
    {
        return (bool) $roots->filter(
            function ($item) use ($node) {
                return $node->isSibling($item);
            }
        )->first();
    }
1369367
private function descendantsFamilies(Tree $tree, Collection $families): ResponseInterface
    {
        $this->layout = 'layouts/ajax';

        return $this->viewResponse('lists/families-table', [
            'families' => $families,
            'tree'     => $tree,
        ]);
    }
1308357
public function cleanUpAutoCreatedChildNodes(NodeInterface $node, NodeType $oldNodeType)
    {
        $newNodeType = $node->getNodeType();
        $autoCreatedChildNodesForNewNodeType = $newNodeType->getAutoCreatedChildNodes();
        $autoCreatedChildNodesForOldNodeType = $oldNodeType->getAutoCreatedChildNodes();
        $removedChildNodesFromOldNodeType = array_diff(
            array_keys($autoCreatedChildNodesForOldNodeType),
            array_keys($autoCreatedChildNodesForNewNodeType)
        );
        /** @var NodeInterface $childNode */
        foreach ($node->getChildNodes() as $childNode) {
            if (in_array($childNode->getName(), $removedChildNodesFromOldNodeType)) {
                $childNode->remove();
            }
        }
    }
1149960
public function childrenOf(Node $node, array $columns=[])
    {
        $columns = $this->pickColumns($columns);
        $columnsId = $this->getColumnsCacheId($columns);
    }
1098357
protected function insertIntoTree(&$node, $existingNode = null)
    {

        $treeOriginTagDef = $node->getNodeRef()->getElement()->getSchema()->getTreeOriginTagDef();

        if(empty($treeOriginTagDef))
            throw new NodeException('Cannot insert a node in tree order mode without a tree origin tag definition');

        if($treeOriginTagDef->isMultiple())
            throw new NodeException('Cannot have more than 1 tree origin tag');

        if($treeOriginTagDef->Direction == 'out')
            $treeOrigin = $node->getOutTag($treeOriginTagDef->Id);
        else
            $treeOrigin = $node->getInTag($treeOriginTagDef->Id);

        if(empty($treeOrigin))
            throw new NodeException('Cannot insert a node into the tree without the tree origin tag');

        $treeOriginPartial = $treeOrigin->toPartial();

        $parentTreeID = '';
        if($node->getTreeParent() != false)
        {
            $parentNode = $this->NodeLookupDAO->getByNodeRef(new NodeRef($node->getNodeRef()->getElement(), $node->getTreeParent()));

            $parentTreeID = $parentNode->TreeID;
        }

        // fetch max tree id (if parentTreeID is blank, return last top-level tree id)
        $maxChildTreeID = $this->fetchMaxChildTreeID($node, $treeOriginTagDef, $treeOriginPartial, $parentTreeID);

        if(!is_null($existingNode) && $maxChildTreeID == $existingNode->TreeID)
        {
            $node->TreeID = $existingNode->TreeID;
            return;
        }

        if(empty($maxChildTreeID))
        {
            $newTreeID = $parentTreeID . '0001';

        // add this to the children
        } else {

            $last4 = substr($maxChildTreeID, -4);
            if(strtolower($last4) == 'ffff')
                throw new NodeException('This tree leaf has reached the limit of its children');

            $newTreeID = $parentTreeID . str_pad(dechex(hexdec($last4)+1), 4, '0', STR_PAD_LEFT);
        }

        while(!$this->Locks->getLock('treeid:'.$treeOriginPartial.':'.$newTreeID, 0)) {

            $last4 = substr($newTreeID, -4);
            if(strtolower($last4) == 'ffff')
                throw new NodeException('This tree leaf has reached the limit of its children');

            $newTreeID = $parentTreeID . str_pad(dechex(hexdec($last4)+1), 4, '0', STR_PAD_LEFT);

        }

        $node->TreeID = $newTreeID;
    }
702618
function( ancestor, descendant, within )
    {
        var node = within ? descendant.parentNode : descendant;
        while( node )
        {
            if( node === ancestor )
                return true;
            node = node.parentNode;
        }
        return false;
    }
646378
protected function createNodes($root_node, $nodes)
    {
        foreach ($nodes as $node_name => $node_children) {

            // Create the highest level child node.
            $child_node = $root_node->children()->create([
                'name' => $node_name
            ]);

            // Update the description, just for fun
            /** @var Category $child_node */
            $child_node->description = $child_node->path;
            $child_node->save();

            // Create all of the children of the child node, if there are any.
            if (! empty($node_children)) {
                $this->createNodes($child_node, $node_children);
            }
        }
    }
1237203
private function deleteChildren( $node ) {
		while ( isset( $node->firstChild ) ) {
			$this->deleteChildren( $node->firstChild );
			$node->removeChild( $node->firstChild );
		}
	}
884926
protected function onAttrChanged(string $key, $oldValue, $newValue)
	{
		$this->getGraph()->nodeAttrChanged($this, $key, $oldValue, $newValue);
	}