• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/item/task/collection/checklist.php
  • Класс: BitrixTasksItemTaskCollectionCheckList
  • Вызов: CheckList::moveItemAfter
public function moveItemAfter($id, $afterId)
{
	$result = new Result();

	if(!$this->containsId($id))
	{
		$result->addError('ITEM_NOT_FOUND', 'Item with ID='.$id.' not found in the collection.');
	}

	$afterId = intval($afterId);
	if($afterId && !$this->containsId($afterId))
	{
		$result->addError('ITEM_NOT_FOUND', 'Item with ID='.$afterId.' not found in the collection.');
	}

	if($result->isSuccess())
	{
		$ix = $this->getItemIndexById($id);
		$item = $this->getItemById($id);

		// it is a mess...
		if($afterId)
		{
			$ixAfter = $this->getItemIndexById($afterId);
			if($ixAfter == (count($this->values) - 1))
			{
				unset($this->values[$ix]);
				$this->values[] = $item;
			}
			else
			{
				unset($this->values[$ix]);
				$newVal = array();
				foreach($this->values as $k => $v)
				{
					$newVal[] = $v;

					if($k == $ixAfter)
					{
						$newVal[] = $item;
					}
				}

				$this->values = $newVal;
			}
		}
		else
		{
			unset($this->values[$ix]);
			array_unshift($this->values, $item);
		}

		$this->onChange();
		$this->setSortByValueOrder();
	}

	return $result;
}