Moves a node by given nodes with `parent_id`, `prev_id` and `next_id`.

@param integer $id the primary key of the moved node
@return array
559386
public function run($id)
    {
        if (Yii::$app->request->isAjax) {
            Yii::$app->response->format = Response::FORMAT_JSON;

            $model = $this->findModel($id);

            if (Yii::$app->request->isPost) {
                $post = Yii::$app->request->post();
                $parentId = isset($post['parent_id']) ? $post['parent_id'] : 0;
                $prevId = isset($post['prev_id']) ? $post['prev_id'] : 0;
                $nextId = isset($post['next_id']) ? $post['next_id'] : 0;

                try {
                    if (empty($parentId)) {
                        if ($this->isMultipleTree) {    ///[isMultipleTree]
                            if (!$model->isRoot()) {
                                $result = $model->makeRoot();
                            }

                            ///?????root sorting logic

                        } else {
                            return [
                                'status' => 'error',
                                'error' => 'Tree root operations are protected when "isMultipleTree" is false!',
                            ];
                        }
                    } elseif (!empty($prevId)) {
                        $prevModel = $this->findModel($prevId);
                        $result = $model->insertAfter($prevModel);
                    } elseif (!empty($nextId)) {
                        $nextModel = $this->findModel($nextId);
                        $result = $model->insertBefore($nextModel);
                    } else {
                        $parentModel = $this->findModel($parentId);
                        $result = $model->appendTo($parentModel);
                    }
                } catch (\Exception $e) {
                    return [
                        'status' => 'error',
                        'error' => $e->getMessage(),
                    ];
                }

                ///Note: remove `save()` when using `creocoder/yii2-nested-sets`!
                return is_bool($result) ? $result : $result->save();
            }
        }

        ///Redirect to this controller's default action
        return $this->controller->redirect([$this->controller->defaultAction]);
    }
1305818
public function getPathwayByChildId($id)
    {

        $select = $this->getSql()->select();
        $select->from(['child' => $this->getTable()])
            ->columns([])
            ->join(
                ['parent' => $this->getTable()],
                'child.' . self::COLUMN_LEFT . ' BETWEEN parent.' . self::COLUMN_LEFT . ' AND parent.' . self::COLUMN_RIGHT,
                [Select::SQL_STAR],
                Select::JOIN_INNER
            )
            ->where(['child.' . $this->getPrimaryKey() . ' = ?' => $id])
            ->order('parent.' . self::COLUMN_LEFT);

        return $select;
    }
1135911
public function getSons($id)
    {
        $sons = [];
        foreach ($this->_tree as $key => $value) {
            if ($value[$this->_parentSign] == $id) {
                $sons[] = $value;
            }
        }
        return $sons;
    }
498863
public function selectedNodeId($id=null){
        
        if(is_integer($id)){
          $this->selectedid =$id;    
          $this->selectednodeid =$id;    
        }
        return $this->selectedid;
        
    }
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);
    }
547874
public function moveBlock($id, $parentId, $placeholder, $sort)
    {
        $block = $this->find($id);
        $version = $this->getNewVersion($block);
        $block = $this->find($id, $version);

        $parent = ($parentId) ? $this->find($parentId) : $block->getOwner();

        $block->setPosition($placeholder);
        $block->setRootVersion($version);

        $block->setParent($parent);
        $parent->addChild($block);

        $this->save($block);

        $siblings = $this->getSiblings($block, $version);

        if ($siblings) {
            $siblings = $this->sortBlocksByDirective($siblings, $sort);

            foreach ($siblings as $sibling) {
                $sibling->setRootVersion($version);
                $block->setSort($sibling->getSort());
                $this->save($sibling);
            }
        }
    }
1312463
protected function getAnchorsInPage($id)
    {
        $page = SiteTree::get()->byID($id);

        if (!$page || !$page->canView()) {
            return [];
        }

        return $page->getAnchorsOnPage();
    }
491439
public function exportById($id): array
    {
        $categoryGroup = Craft::$app->categories->getGroupById((int) $id);

        return $this->export($categoryGroup);
    }
1086093
public function exportById($id): array
    {
        $user = Craft::$app->users->getUserById($id);
        return $this->export($user);
    }
865491
public function moveDown($id, $count = 1) {
        $pk = $this->getRepository()->getPrimaryKey();
        $node = $this->getNode($id, true);

        if (!$node || empty($node['Parent']['id'])) {
            return false;
        }

        $left = $this->getConfig('leftField');
        $right = $this->getConfig('rightField');
        $nodeLeft = $node[$left];
        $nodeRight = $node[$right];
        $inc = ($count * 2);

        $newNodeLeft = $nodeLeft + $inc;
        $newNodeRight = $nodeRight + $inc;

        // Can't go outside of the parent
        $parentRight = $node['Parent'][$right];

        if ($newNodeLeft >= $parentRight) {
            $newNodeLeft = $parentRight - 2;
            $newNodeRight = $parentRight - 1;
        }

        // Exit early if the values are the same
        if ($nodeLeft === $newNodeLeft) {
            return true;
        }

        // Move following nodes up
        $this->_moveNode(function(Query $query) use ($left, $right, $nodeRight, $newNodeRight) {
            $query->where($left, '>', $nodeRight)->where($right, '<=', $newNodeRight);
        }, [
            $left => Query::expr($left, '-', 2),
            $right => Query::expr($right, '-', 2)
        ]);

        // Move node down
        $this->_moveNode(function(Query $query) use ($pk, $id) {
            $query->where($pk, $id);
        }, [
            $left => $newNodeLeft,
            $right => $newNodeRight
        ]);

        return true;
    }
225870
public function move_item_left($id) {
        global $DB;

        $item = $this->find_item($id);
        if (!isset($item->parentlist->parentitem->parentlist)) {
            print_error('listcantmoveleft');
        } else {
            $newpeers = $this->get_items_peers($item->parentlist->parentitem->id);
            if (isset($item->parentlist->parentitem->parentlist->parentitem)) {
                $newparent = $item->parentlist->parentitem->parentlist->parentitem->id;
            } else {
                $newparent = $this->get_top_level_parent_id($item);
            }
            $DB->set_field($this->table, "parent", $newparent, array("id"=>$item->id));
            $oldparentkey = array_search($item->parentlist->parentitem->id, $newpeers);
            $neworder = array_merge(array_slice($newpeers, 0, $oldparentkey+1), array($item->id), array_slice($newpeers, $oldparentkey+1));
            $this->reorder_peers($neworder);
        }
        return $item->parentlist->parentitem;
    }
394886
public function nextChild($id)
    {
        $child = $this->getChild($id);
        $next  = $this->children[$child->id()]['next'];

        return $this->getChild($next);
    }
336834
public function exportById($id): array
    {
        $globalSet = Craft::$app->globals->getSetById((int) $id);

        return $this->export($globalSet);
    }
1058379
public function removeChild(int $id): InnerNode
    {
        if ( ! isset($this->children[$id])) {
            return $this;
        }

        // handle moving next and previous assignments.
        $next = $this->children[$id]['next'];
        $prev = $this->children[$id]['prev'];
        if ( ! is_null($next)) {
            $this->children[$next]['prev'] = $prev;
        }
        if ( ! is_null($prev)) {
            $this->children[$prev]['next'] = $next;
        }

        // remove the child
        unset($this->children[$id]);

        //clear any cache
        $this->clear();

        return $this;
    }
1285841
protected function getJunctionKeys($id): array
	{
		$ids = [];

		foreach((is_array($id) ? $id : [$id]) as $value)
		{
			if($value instanceof $this->model)
			{
				$value = $value->getPrimaryKeyValue();
			}

			$ids[] = $value;
		}

		return $ids;
	}
959874
public static function node($id)
    {
        $id = intval($id);
        if (empty($id)) return null;
        
        if (!static::$caching || empty(static::$_nodes[$id])) {
            $result = static::findOne($id);
            if (static::$caching) {
                static::$_nodes[$id] = $result;
            } else {
                return $result;
            }
        }
        return static::$_nodes[$id];
    }
534989
public function deletePublicKey(int $id): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/user/keys/:id', (string)$id),
            Request::METHOD_DELETE);
    }