• Модуль: landing
  • Путь к файлу: ~/bitrix/modules/landing/lib/landing.php
  • Класс: BitrixLandingLanding
  • Вызов: Landing::sortBlock
protected function sortBlock(int $id, string $action): bool
{
	$id = intval($id);
	if (isset($this->blocks[$id]))
	{
		$blocks = array_keys($this->blocks);
		for ($i = 0, $c = count($blocks); $i < $c; $i++)
		{
			if ($blocks[$i] == $id)
			{
				// change sort between two blocks
				$targetKey = $i + ($action === 'up' ? -1 : 1);
				if (isset($blocks[$targetKey]))
				{
					$thisBlock = $this->blocks[$id];
					$targetBlock = $this->blocks[$blocks[$targetKey]];
					$thisBlockSort = $thisBlock->getSort();
					$targetBlockSort = $targetBlock->getSort();

					$thisBlock->setSort($targetBlockSort);
					$targetBlock->setSort($thisBlockSort);
					$res1 = $thisBlock->save();
					$res2 = $targetBlock->save();

					$this->error->copyError($thisBlock->getError());
					$this->error->copyError($targetBlock->getError());

					if ($res1 || $res2)
					{
						$this->touch();
					}

					return $res1 && $res2;
				}

				$this->error->addError(
					'BLOCK_WRONG_SORT',
					Loc::getMessage('LANDING_BLOCK_WRONG_SORT')
				);

				return false;
			}
		}
	}
	else
	{
		$this->error->addError(
			'BLOCK_NOT_FOUND',
			Loc::getMessage('LANDING_BLOCK_NOT_FOUND')
		);
	}

	return false;
}