src/Mapper.php
public function changeSort(string $column, $id, $prevId, $nextId): void
	{
		$repo = $this->getRepository();
		$entity = $repo->getById($id);
		$prevEntity = $repo->getById($prevId);
		$nextEntity = $repo->getById($nextId);

		if ($nextEntity !== null && $entity->$column > $nextEntity->$column) {
			try {
				$this->connection->transactional(function (Connection $connection) use ($column, $entity, $nextEntity) {
					$connection->query('UPDATE %table SET %column = %column + 1 WHERE %column BETWEEN %i AND %i', $this->getTableName(), $column, $column, $column, $nextEntity->$column, $entity->$column);
				});
			} catch (\Exception $ex) {
				throw new $ex;
			}
			$entity->$column = $nextEntity->$column;
		} elseif ($prevEntity !== null) {
			try {
				$this->connection->transactional(function (Connection $connection) use ($column, $entity, $prevEntity) {
					$connection->query('UPDATE %table SET %column = %column - 1 WHERE %column BETWEEN %i AND %i', $this->getTableName(), $column, $column, $column, $entity->$column, $prevEntity->$column);
				});
			} catch (\Exception $ex) {
				throw new $ex;
			}
			$entity->$column = $prevEntity->$column;
		} else {
			$entity->$column = 1;
		}
		$repo->persistAndFlush($entity);
	}
public function changeSort(string $column, $id, $prevId, $nextId): void
	{
		$repo = $this->getRepository();
		$entity = $repo->getById($id);
		$prevEntity = $repo->getById($prevId);
		$nextEntity = $repo->getById($nextId);

		if ($nextEntity !== null && $entity->$column > $nextEntity->$column) {
			try {
				$this->connection->transactional(function (Connection $connection) use ($column, $entity, $nextEntity) {
					$connection->query('UPDATE %table SET %column = %column + 1 WHERE %column BETWEEN %i AND %i', $this->getTableName(), $column, $column, $column, $nextEntity->$column, $entity->$column);
				});
			} catch (\Exception $ex) {
				throw new $ex;
			}
			$entity->$column = $nextEntity->$column;
		} elseif ($prevEntity !== null) {
			try {
				$this->connection->transactional(function (Connection $connection) use ($column, $entity, $prevEntity) {
					$connection->query('UPDATE %table SET %column = %column - 1 WHERE %column BETWEEN %i AND %i', $this->getTableName(), $column, $column, $column, $entity->$column, $prevEntity->$column);
				});
			} catch (\Exception $ex) {
				throw new $ex;
			}
			$entity->$column = $prevEntity->$column;
		} else {
			$entity->$column = 1;
		}
		$repo->persistAndFlush($entity);
	}
Zmeni razeni
@param string $column
@param mixed $id
@param mixed $prevId
@param mixed $nextId
@throws QueryException
@throws DriverException