Move a node (model) below the parent and in between left and right

@param integer $id the primaryKey of the moved node
@return array
@throws NotFoundHttpException
503975
public function run($id)
    {
        /** @var ActiveRecord $model */
        $model = new $this->modelClass;

        /*
         * Locate the supplied model, left, right and parent models
         */
        $pkAttribute = $model->getTableSchema()->primaryKey[0];

        /** @var ActiveRecord|NestedSetsBehavior $model */
        $model = $model::find()->where([$pkAttribute => $id])->one();

        if ($model == null) {
            throw new NotFoundHttpException('Node not found');
        }

        $model->deleteWithChildren();

        return null;
    }
217678
protected function _removeNode($id, $index) {
        $pk = $this->getRepository()->getPrimaryKey();

        foreach ([$this->getConfig('leftField'), $this->getConfig('rightField')] as $field) {
            $this->_moveNode(function(Query $query) use ($field, $index, $id, $pk) {
                $query->where($field, '>=', $index);

                if ($id) {
                    $query->where($pk, '!=', $id);
                }
            }, [
                $field => Query::expr($field, '-', 2)
            ]);
        }
    }
88710
public function loadRegion($id)
    {
        $blocks = $this->entityTypeManager->getStorage('block')->loadByProperties([
            'region' => $id,
            'theme'  => $this->themeName
        ]);

        $result = [];
        foreach($blocks as $id => $values)
        {
            $result[] = $this->loadBlock($id);
        }


        return $result;
    }
962341
public function moveBlock($id, $parentId, $placeholder, $sort, $draft = true)
    {
        $block = $this->find($id, $draft);

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

        $block->setPosition($placeholder);

        $block->setParent($parent);

        if ($parent) {
            $parent->addChild($block);
        }

        $this->save($block);

        array_walk($sort, function (&$id) { $id = (int) $id; });
        $contained = $this->findById($sort, $draft);

        if ($contained) {
            $contained = $this->setSortsByDirective($contained, $sort);

            foreach ($contained as $node) {
                if ($node->getOwner()->getId() == $block->getOwner()->getId()) {
                    $this->save($node);
                }
            }
        }
    }
16561
public function moveToTrash($id)
    {
        $user = AppUser::find($id);

        if (!$user) {
            return response()->json(null, 404);
        }

        if (!$user->delete()) {
            return response()->json(null, 500); // @codeCoverageIgnore
        }

        return response()->json(null, 204);
    }
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;
    }
1017295
public function moveTo($id, $parent_id) {
        $pk = $this->getRepository()->getPrimaryKey();
        $node = $this->getNode($id);

        if (!$node || $node[$this->getConfig('parentField')] == $parent_id) {
            return false;
        }

        $left = $this->getConfig('leftField');
        $right = $this->getConfig('rightField');
        $data = [];

        // Remove the node and reset others
        $this->_removeNode($id, $node[$left]);

        // Insert into parent
        if ($parent_id && ($parentNode = $this->getNode($parent_id))) {
            $data = [
                $left => $parentNode[$right],
                $right => $parentNode[$right] + 1
            ];

        // Or the root
        } else if ($lastNode = $this->getLastNode()) {
            $data = [
                $left => $lastNode[$right] + 1,
                $right => $lastNode[$right] + 2
            ];
        }

        // Move it
        $this->_moveNode(function(Query $query) use ($pk, $id) {
            $query->where($pk, $id);
        }, $data + [
            $this->getConfig('parentField') => $parent_id
        ]);

        $this->_insertNode($id, $data[$left]);

        return true;
    }
165262
public function getHierarchy($id)
    {
        $location = $this
            ->locationRepository
            ->findOneBy([
                'id' => $id,
            ]);

        if (empty($location)) {
            throw new EntityNotFoundException();
        }

        $parents = $location->getAllParents();
        $hierarchy = array_merge(
            $parents,
            [$location]
        );

        return $this->formatOutputLocationArray(
            $hierarchy
        );
    }
844203
public function findParentNodesByChildId($id)
	{
        // To be returned
        $result = array();

        $rl = $this->getRelations();
        $data = $rl[RelationBuilder::TREE_PARAM_ITEMS];

        // If can't find, then return empty array
        if (!isset($data[$id])) {
            return array();
        }

        $current = $data[$id];
        $parentId = $current[RelationBuilder::TREE_PARAM_PARENT_ID];

        while (isset($data[$parentId])) {
            $current = $data[$parentId];
            $parentId = $current[RelationBuilder::TREE_PARAM_PARENT_ID];

            array_push($result, $current);
        }

        return $result;
    }
68418
public function getSubtree($id)
    {
        $primaryKey = $this->mapper->getPrimaryKey($this->getTable());
        $entities = $this->getSubtreeData($id, $primaryKey);
        $children = array();
        foreach ($entities as $entity) {
            $key = $entity->ancestor->id;
            if (!isset($children[$key])) {
                $children[$key] = array();
            }
            $children[$key][] = $entity;
        }

        return $this->getChildNodes($id, $children, $entities, $primaryKey);
    }
624053
function descendants($ID)
	{
		$res = $this->{$this->type ()}->descendantsConditional(/* absolute depths*/false, "ID=?", $ID );
		$out = array ();
		if (is_array ( $res ))
			foreach ( $res as $v )
				$out [$v ['Title']] = $v;
		return $out;
	}
1247177
public function actionRemove(string $id): array
    {
        $items = Yii::$app->getRequest()->post('items', []);
        $model = $this->findModel($id);
        $model->removeChildren($items);

        return array_merge($model->getItems());
    }
1058385
public function getNode($id)
    {
        if (!isset($this->nodes[$id])) {
            throw new InvalidArgumentException(sprintf('There is no node with id "%s".', $id));
        }

        return $this->nodes[$id];
    }
683280
public function load($id)
    {
        $row = $this->gateway->loadUrlWildcardData($id);

        if (empty($row)) {
            throw new NotFoundException('UrlWildcard', $id);
        }

        return $this->mapper->extractUrlWildcardFromRow($row);
    }
120892
public function getChildren($id)
    {
        $location = $this
            ->locationRepository
            ->findOneBy([
                'id' => $id,
            ]);

        if (empty($location)) {
            throw new EntityNotFoundException();
        }

        return $this->formatOutputLocationArray(
            $location->getChildren()
        );
    }
347651
public function moveAction($id, $childId = null, $position)
    {

        $objectId = $childId !== null ? $childId : $id;

        $object = $this->admin->getObject($objectId);

        $sortableHandler = $this->get('picoss.sonataextraadmin.handler.sortable');
        $lastPosition = $sortableHandler->getLastPosition($object);
        $position = $sortableHandler->getPosition($object, $position, $lastPosition);

        $object->setPosition($position);
        $this->admin->update($object);

        if ($this->isXmlHttpRequest()) {
            return $this->renderJson(array(
                'result' => 'ok',
                'objectId' => $this->admin->getNormalizedIdentifier($object)
            ));
        }
        $this->addFlash('sonata_flash_info', $this->get('translator')->trans('flash_position_updated_successfully', array(), 'PicossSonataExtraAdminBundle'));

        return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
    }
1362630
private function _getAncectors($id)
    {
        $nodes = [];
        foreach ($this->_tree as $key => $value) {
            if ($value['id'] == $id) {
                $nodes[] = $value;
                if ($value[$this->_parentSign] != 0) {
                    $nodes = array_merge($nodes, $this->_getAncectors($value[$this->_parentSign]));
                }
            }
        }
        return $nodes;
    }