Move element

@param integer $id
@param string $position
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()));
    }
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;
    }
80089
public function move($destinationId){
        $parameter = new ClientValueObject();
        $parameter->setProperty("DestinationId",$destinationId);
        $qry = new InvokePostMethodQuery($this->getResourcePath(),"Move",null,$parameter);
        $this->getContext()->addQuery($qry);
    }
413397
protected function moveUp($id)
    {
        $model = $this->getModel($id);
        $orderAttrName = $this->positionAttribute;
        $orderDir = SORT_DESC;

        $swapModel = $model::find()
            ->where(['<', $orderAttrName, $model->$orderAttrName])
            ->orderBy([$orderAttrName => $orderDir])
            ->one();

        if ($swapModel) {
            $newOrderNumeric = $swapModel->$orderAttrName;
            $swapModel->$orderAttrName = $model->$orderAttrName;
            $model->$orderAttrName = $newOrderNumeric;
            $swapModel->save() && $model->save();
        }

        return $this->redirect($model);
    }
724986
public function setPosition($position)
    {
        switch ($position) {
            case Modification::POSITION_ANY:
            case Modification::POSITION_NTERM:
            case Modification::POSITION_CTERM:
            case Modification::POSITION_PROTEIN_NTERM:
            case Modification::POSITION_PROTEIN_CTERM:
                $this->position = $position;
                
                break;
            default:
                throw new \InvalidArgumentException('Postion must be any or terminus (see POSITION_XXXX)');
        }
    }
107089
public function moveUpdateToTop($id)
    {
        return $this->send($this->getHttp()->post($this->url.'updates/'.$id.'/move_to_top.json'));
    }
775551
public function move(Node\NodeInterface $node, $pos, $levelDiff)
	{
		// Current node's interval
		$left = $node->getLeftValue();
		$right = $node->getRightValue();
		
		// How big is the node
		$spaceUsed = $right - $left + 1;
		
		// Tells for how much index the node will be moved
		$moveA = 0;
		
		// Tells for how much index the nodes between the node's current and 
		// future position will be moved
		$moveB = 0;
		
		// Tells the interval for indeces to be moved which are not inside the 
		// node interval (usually $a <= $b)
		$a = $b = 0;
		
		// Move to the right
		if ($pos > $left) {
			$a = $right + 1;
			$b = $pos - 1;
			$moveA = $pos - $left - $spaceUsed;
			$moveB = - $spaceUsed;
			
		// Move to the left
		} else {
			$a = $pos;
			$b = $left - 1;
			$moveA = $pos - $left;
			$moveB = $spaceUsed;
		}
		
		// There is nothing to move
		if ($moveA == 0 && $levelDiff == 0) {
			return;
		}
		
		foreach ($this->array as $item) {
			/* @var $item Node\NodeInterface */
			$itemLeft = $item->getLeftValue();
			$itemRight = $item->getRightValue();
			
			// Children of the page being moved
			if (self::isBetween($itemLeft, $left, $right)) {
				
				if ( ! self::isBetween($itemRight, $left, $right)) {
					throw new Exception\InvalidStructure("Node $item left index is between $node index but the right isn't");
				}

				$this->moveNode($item, $moveA, $moveA, $levelDiff);

//				$item->moveLeftValue($moveA);
//				$item->moveRightValue($moveA);
//				$item->moveLevel($levelDiff);
				continue;
			}

			// Left index matches the interval
			if (self::isBetween($itemLeft, $a, $b)) {
				$this->moveNode($item, $moveB, 0, 0);
//				$item->moveLeftValue($moveB);
			}
			
			// Right index matches the interval
			if (self::isBetween($itemRight, $a, $b)) {
				$this->moveNode($item, 0, $moveB, 0);
//				$item->moveRightValue($moveB);
			}
		}
	}
1119392
public function setPosition($position)
    {
        if (false === Numeric::isPositiveInteger($position, false)) {
            throw new InvalidArgumentException('A position must be a positive integer.');
        }
        $this->_position = $position;
        return $this;
    }
1210466
public function moveDownAction(Request $request, $id)
    {
        return parent::doMoveDownAction($this->getAdminListConfigurator(), $id, $request);
    }
1290307
protected function incrementPositionsOfItemsAbove($position = null)
    {
        if ($this->isNotInList()) return;

        if (null === $position) {
            $position = $this->getListifyPosition();
        }

        $this->listifyScopedQuery()
            ->where($this->positionColumn(), '<', $position)
            ->increment($this->positionColumn());
    }
1208085
def move_to_position(
        self,
        resource_id,
        to_position,
        new_parent_id=noop,
        db_session=None,
        *args,
        **kwargs
    ):
        
        return self.service.move_to_position(
            resource_id=resource_id,
            to_position=to_position,
            new_parent_id=new_parent_id,
            db_session=db_session,
            *args,
            **kwargs
        )
1310622
public function actionTreeMove($id, $pid)
    {
        $child = $this->findModel($id);
        $oldParent = $this->findModel($pid);
        $newParent = $this->findModel(Yii::$app->request->post('pid'));
        $child->move($oldParent, $newParent);
        echo json_encode($child->nodeAttributes($child, $newParent->id, time()));
    }
1299742
public function seek($position)
    {
        $position = (int) $position;
        if ($position < 0 || $position >= $this->_count) {
            // require_once 'Zend/Db/Table/Rowset/Exception.php';
            throw new Zend_Db_Table_Rowset_Exception("Illegal index $position");
        }
        $this->_pointer = $position;
        return $this;
    }
551692
public function relativeMove($model, $position)
    {
        $conditionAttributes = (array)$this->conditionAttributes;
        $owner = $this->owner;

        if (!empty($conditionAttributes)) {
            $sameCondition = true;
            foreach ($conditionAttributes as $attr) {
                if ($owner->getAttribute($attr) != $model->getAttribute($attr)) {
                    $sameCondition = false;
                    break;
                }
            }
            if (!$sameCondition) {
                // move in other condition category
                $this->moveToTop();
                // update condition attribute
                $condition = [];
                foreach ($conditionAttributes as $attr) {
                    $condition[$attr] = $model->getAttribute($attr);
                }
                $condition[$this->sortAttribute] = $owner->find()->andWhere($this->getCondition())->count() - 1;
                $owner->updateAttributes($condition);
            }
        }
        // calculate pos change
        $currentPos = $owner->getAttribute($this->sortAttribute);
        $destinationPos = $model->getAttribute($this->sortAttribute);
        if ($position == 'after') {
            $newPos = $destinationPos > $currentPos ? $destinationPos - 1 : $destinationPos;
        } else {
            $newPos = $destinationPos > $currentPos ? $destinationPos : $destinationPos + 1;
        }
        $this->moveToPosition($newPos);
    }
1099812
public function str_insert_i(string $insert, int $position): self
    {
        $insert = $this->inputConv($insert);
        $this->str = \substr_replace($this->str, $insert, $position << 2, 0);

        return $this;
    }
1352255
public function placeAt(Sortable $movedNode, Sortable $newParent, $position)
    {
        // 1. movedNode.parentId = newDescendant.parentId, movedNode.position = MAX(newDescendant.position,1)
        // 2. removeFromSort(movedNode) like delete without delete
        // 2. UPDATE SET position = position+1 WHERE parentId = newAncestor.parentId
        //    AND position >= movedNode.position
        // 3. movedNode.save()

        $targetParentId = $newParent->getId();
        $targetPosition = $position;
        $oldParentId = $movedNode->getParentId();
        $oldPosition = $movedNode->getPosition();

        // Nothing to do
        if ($targetParentId == $oldParentId &&
            $targetPosition == $oldPosition &&
            $movedNode->exists) {
            return $this;
        }

        $movedNode[$this->getParentIdName()] = $targetParentId;
        $movedNode[$this->getPositionName()] = $targetPosition;

        // Remove node from old parent
        $this->decrementOrderAfter($oldParentId, $oldPosition);

        // Create space for new position
        $this->incrementOrderAfter($targetParentId, $targetPosition-1);

        $movedNode->save();

        return $this;

    }
1112860
public function addPositions($id, $data) {
		// find
		$model = $this->get($id);

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

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

		// save and dispatch events
		$this->dispatch(SportEvent::PRE_POSITIONS_ADD, $model, $data);
		$this->dispatch(SportEvent::PRE_SAVE, $model, $data);
		$rows = $model->save();
		$this->dispatch(SportEvent::POST_POSITIONS_ADD, $model, $data);
		$this->dispatch(SportEvent::POST_SAVE, $model, $data);

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

		return NotUpdated(['model' => $model]);
	}