Move a block to a new parent in a specific placeholder and order (sort)

This method performs the change and persists/flushes to the database.

@param integer $id
@param integer $parentId
@param integer $placeholder
@param array   $sort
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);
            }
        }
    }
1108361
public void setParentId(String parentId)
   {
      this.parentId = (parentId == null || parentId.equals("") ? null : parentId);
      setGroupName(groupName);
   }
676090
public function listForId($orderId, array $parameters = [])
    {
        $this->parentId = $orderId;

        return parent::rest_list(null, null, $parameters);
    }
226187
public function find($parentId, $id)
    {
        $resource = $this->createPartialResourceUrlForView($parentId, $id);
        $data = $this->client->get($resource);

        return $this->fromArray(reset($data));
    }
100078
public function handleSort(int $item_id = null, $prev_id = null, $next_id = null, $parent_id = null): void
	{
		if ($this->isAjax()) {
			$page = $this->orm->pages->getById($item_id);
			if (!$page->isHomePage) {
				$page->parent = $parent_id;
				$this->orm->persistAndFlush($page);

				$this->orm->pages->changeSort((int) $item_id, (int) $prev_id, (int) $next_id, $this->locale);
			}
		} else {
			$this->terminate();
		}
	}
822941
public function move($pid, $order = null)
  {
    $this->getParent()->channelMove($this->getId(), $pid, $order);
  }
1304611
public static function move_up_issuer($id) {
        require_capability('moodle/site:config', context_system::instance());
        $current = new issuer($id);

        $sortorder = $current->get('sortorder');
        if ($sortorder == 0) {
            return false;
        }

        $sortorder = $sortorder - 1;
        $current->set('sortorder', $sortorder);

        $filters = array('sortorder' => $sortorder);
        $children = issuer::get_records($filters, 'id');
        foreach ($children as $needtoswap) {
            $needtoswap->set('sortorder', $sortorder + 1);
            $needtoswap->update();
        }

        // OK - all set.
        $result = $current->update();

        return $result;
    }
499190
public function updateParents($id, $data) {
		// find
		$model = $this->get($id);

		if ($model === null) {
			return new NotFound(['message' => 'Skill not found.']);
		}

		// pass update to internal logic
		try {
			$this->doUpdateParent($model, $data);
		} catch (ErrorsException $e) {
			return new NotValid(['errors' => $e->getErrors()]);
		}

		// save and dispatch events
		$this->dispatch(SkillEvent::PRE_CHILDREN_UPDATE, $model, $data);
		$this->dispatch(SkillEvent::PRE_SAVE, $model, $data);
		$rows = $model->save();
		$this->dispatch(SkillEvent::POST_CHILDREN_UPDATE, $model, $data);
		$this->dispatch(SkillEvent::POST_SAVE, $model, $data);

		if ($rows > 0) {
			return Updated(['model' => $model]);
		}

		return NotUpdated(['model' => $model]);
	}
404730
public function moveUpAction(Request $request, $id)
    {
        return parent::doMoveUpAction($this->getAdminListConfigurator(), $id, $request);
    }
483149
protected function _changeParent(Model $model, $id = null, $parentId = null) {
		$parentField = $this->_getBehaviorConfig($model, 'parent');
		if (empty($id) || ($parentField === null)) {
			return false;
		}

		$model->recursive = -1;
		$treeItem = $model->read(null, $id);
		if (empty($treeItem)) {
			return false;
		}

		$treeItem[$model->alias][$parentField] = $parentId;
		$result = (bool)$model->save($treeItem);

		return $result;
	}
1045887
public function byParentByFolderNameAndByOrganization($parentId , $parent_name , $organizationId, $databaseConnectionName = null)
  {
    if(empty($databaseConnectionName))
    {
      $databaseConnectionName = $this->databaseConnectionName;
    }

    return $this->File->setConnection($databaseConnectionName)
      ->where('type', '=', 'C')
      ->where('parent_file_id', '=' , $parentId)
      ->where('name', '=', $parent_name)
      ->where('organization_id', '=', $organizationId)
      ->get();
  }
1233685
public function setParentId( $parentid )
	{
		if ( $parentid == $this->getParentId() ) { return; }

		$this->_values['parentid'] = (int) $parentid;
		$this->setModified();
	}
1352017
public function changeSort(int $id, ?int $prevId, ?int $nextId)
	{
		$this->mapper->changeSort('position', $id, $prevId, $nextId);
	}
1204113
protected function reorderSiblings($parentIdChanged = false)
    {
        list($range, $action) = $this->setupReordering($parentIdChanged);

        $positionColumn = $this->getPositionColumn();

        // As the method called twice (before moving and after moving),
        // first we gather "old" siblings by the old parent id value of the model.
        if ($parentIdChanged === true) {
            $query = $this->siblings(false, $this->old_parent_id);
        } else {
            $query = $this->siblings();
        }

        if ($action) {
            $query->buildWherePosition($positionColumn, $range)
                ->where($this->getKeyName(), '<>', $this->getKey())
                ->$action($positionColumn);
        }
    }
626187
public function iHaveUserGroupWithIdInGroup( $name, $id, $parentGroup )
    {
        $userGroup = $this->getUserGroupManager()->ensureUserGroupExists( $name, $parentGroup );
        $this->addValuesToMap( $id, $userGroup->id );
    }
1210466
public function moveDownAction(Request $request, $id)
    {
        return parent::doMoveDownAction($this->getAdminListConfigurator(), $id, $request);
    }
693517
public function setInheritSort($nodeId, $sort)
    {
        if (!isset($this->attributes['inheritSort'])) {
            $this->attributes['inheritSort'] = [];
        }

        $this->attributes['inheritSort'][$nodeId] = $sort;

        return $this;
    }