Inserts record at the given position.
This re-arranges the affected surrounding records.

@param integer $position default is listifyTop()
@return $this
160492
public function insertAt($position = null)
    {
        if (null === $position) {
            $position = $this->listifyTop();
        }

        $this->insertAtPositionAndReorder($position);

        return $this;
    }
153482
public function setPosition($position)
	{
		if ( $position == $this->getPosition() ) { return; }

		$this->_values['pos'] = (int) $position;
		$this->setModified();
	}
517381
public function insert() {
    $this->db()->insert($this->table, $this->record);
    $id = $this->db()->lastInsertId();
    $this->record[$this->id_name] = $id;
    $this->isDirty = FALSE;

    return $this;
  }
630399
protected function decrementPositionsOfItemsBelow($position = null)
    {
        if ($this->isNotInList()) return;

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

        $this->listifyScopedQuery()
            ->where($this->positionColumn(), '>', $position)
            ->decrement($this->positionColumn());
    }
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)');
        }
    }
1305395
public function moveToBottom()
    {
        if ($this->isNotInList()) return $this;

        $this->getConnection()->transaction(function() {

            $this->decrementPositionsOfItemsBelow();

            $bottomPosition = $this->getBottomPositionValue($this);
            $newPosition    = (null === $bottomPosition) ? $this->listifyTop() : $bottomPosition + 1;

            $this->setListPosition($newPosition);
        });

        return $this;
    }
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;
    }
1052267
public function removeSegment($position = 1)
	{
		if (array_key_exists($position, $this->pattern))
		{
			unset($this->pattern[$position]);
		}

		return $this;
	}
291843
public function getPositionAfter(TablePosition $position, $offset = 1)
    {
        $cellsToMove = $offset;
        $newRow = $position->getRow();
        $newCell = $position->getCell();

        while ($cellsToMove > 0 && $newRow < count($this->rows)) {
            $cellCount = count($this->getRow($newRow)->getCells());

            $cellsLeft = $cellCount - $newCell - 1;

            if ($cellsToMove > $cellsLeft) {
                ++$newRow;
                $cellsToMove -= $cellsLeft - 1;
                $newCell = 0;
            } else {
                $newCell = $newCell + $cellsToMove;
                $cellsToMove -= $cellsLeft;
            }
        }

        if ($newRow >= 0 && $newCell >= 0) {
            return new TablePosition($newRow, $newCell);
        }

        return;
    }
166058
public function addAt(Item $item, $position = null)
    {
        if (0 === $position) {
            array_unshift($this->items, $item);
        } else if (null === $position) {
            $this->items[] = $item;
        } else if (count($this->items) <= $position) {
            $this->items[] = $item;
        } else {
            array_splice($this->items, $position, 0, [$item]);
        }

        $this->isUpdated = true;

        return $this;
    }
870636
public function moveAction($position)
    {
        $translator = $this->get('translator');

        if (!$this->admin->isGranted('EDIT')) {
            $this->addFlash(
                'sonata_flash_error',
                $translator->trans('flash_error_no_rights_update_position')
            );

            return new RedirectResponse($this->admin->generateUrl(
                'list',
                array('filter' => $this->admin->getFilterParameters())
            ));
        }

        /** @var PositionHandler $positionHandler */
        $positionHandler = $this->get('pix_sortable_behavior.position');
        $object          = $this->admin->getSubject();

        $lastPositionNumber = $positionHandler->getLastPosition($object);
        $newPositionNumber  = $positionHandler->getPosition($object, $position, $lastPositionNumber);

        $accessor = PropertyAccess::createPropertyAccessor();
        $accessor->setValue($object, $positionHandler->getPositionFieldByEntity($object), $newPositionNumber);

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

        if ($this->isXmlHttpRequest()) {
            return $this->renderJson(array(
                'result' => 'ok',
                'objectId' => $this->admin->getNormalizedIdentifier($object)
            ));
        }

        $this->addFlash(
            'sonata_flash_success',
            $translator->trans('flash_success_position_updated')
        );

        return new RedirectResponse($this->admin->generateUrl(
            'list',
            array('filter' => $this->admin->getFilterParameters())
        ));
    }
163045
public function seek($position)
    {
        reset($this->_storage);
        while (($key = key($this->_storage)) !== null && $key !== $position)
        {
            next($this->_storage);
        }
    }
1364269
public static function createInvalidStringPosition($name, $position)
    {
        return new self(sprintf(
            'The %s form uses position as string which can only be "first" or "last" (current: %s).',
            self::decorateValue($name),
            self::decorateValue($position)
        ));
    }
1228146
public function setArgument($argument, $position = null)
    {
        array_splice($this->arguments, $position ?: count($this->arguments), 0, array($argument));

        return $this;
    }
123674
public function moveToTop()
    {
        if ($this->isNotInList()) return $this;

        $this->getConnection()->transaction(function() {

            $this->incrementPositionsOfItemsAbove();

            $this->setListPosition($this->listifyTop());
        });

        return $this;
    }
9557
public function insert($position, $string)
	{
		ArgumentValidator::validateUnsignedInteger($position);
		ArgumentValidator::validateScalar($string);
		if ($position >= $this->length()) {
			throw new \InvalidArgumentException('Position invalid');
		}
		$this->string = mb_substr($this->string, 0, $position) . (string)$string . mb_substr($this->string, $position);
		return $this;
	}
1269263
public function setPosition(Model $model, $position)
    {
        if ($position === $model->getListifyPosition()) {
            return $position;
        }

        switch ($position) {

            case null:
            case OrderablePosition::REMOVE:
                $model->removeFromList();
                break;

            case OrderablePosition::UP:
                $model->moveHigher();
                break;

            case OrderablePosition::DOWN:
                $model->moveLower();
                break;

            case OrderablePosition::TOP:
                if ($model->isInList()) {
                    $model->moveToTop();
                } else {
                    $model->insertAt();
                }
                break;

            case OrderablePosition::BOTTOM:
                if ($model->isInList()) {
                    $model->moveToBottom();
                } else {
                    $model->insertAt();
                    $model->moveToBottom();
                }
                break;

            default:
                $position = (int) $position;

                $model->insertAt($position);
        }

        return $model->getListifyPosition();
    }