• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/location/connector.php
  • Класс: BitrixSaleLocationConnector
  • Вызов: Connector::updateMultipleLinkType
static function updateMultipleLinkType($entityPrimary, $links, $existed, $linkType = self::DB_LOCATION_FLAG, $doRemove = true)
{
	$useGroups = static::getUseGroups();

	$smthAdded = false;
	foreach($links as $k => $loc)
	{
		if(!isset($existed[$loc]))
		{
			$data = array(
				static::getLinkField() => $entityPrimary,
				static::getLocationLinkField() => $loc
			);
			if($useGroups)
				$data[static::getTypeField()] = $linkType;

			$res = static::add($data);
			if(!$res->isSuccess())
				throw new MainSystemException(Loc::getMessage('SALE_LOCATION_CONNECTOR_ENTITY_CANNOT_ADD_EXCEPTION'));

			$smthAdded = true;
		}
		else
			unset($existed[$loc]);
	}

	if($doRemove && !empty($existed))
	{
		foreach($existed as $loc => $k)
		{
			$data = array(
				static::getLinkField() => $entityPrimary,
				static::getLocationLinkField() => $loc
			);
			if($useGroups)
				$data[static::getTypeField()] = $linkType;

			$res = static::delete($data);
			if(!$res->isSuccess())
				throw new MainSystemException(Loc::getMessage('SALE_LOCATION_CONNECTOR_ENTITY_CANNOT_DELETE_EXCEPTION'));
		}
	}
}