• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/location/name/nameentity.php
  • Класс: BitrixSaleLocationNameNameEntity
  • Вызов: NameEntity::updateMultipleForOwner
static function updateMultipleForOwner($primaryOwner, $names)
{
	$primaryOwner = Assert::expectIntegerPositive($primaryOwner, '$primaryOwner');

	if(!is_array($names))
		$names = array();

	$langField = static::getLanguageFieldName();
	$refField = static::getReferenceFieldName();

	// get already existed name records
	$res = static::getList(array(
		'filter' => array($refField => $primaryOwner),
		'select' => array('ID', $langField)
	));
	$existed = array();
	while($item = $res->Fetch())
		$existed[$item[$langField]] = $item['ID'];

	foreach($names as $lid => $name)
	{
		$lid = Assert::castTrimLC($lid);

		$empty = true;
		foreach($name as $arg)
		{
			if($arg <> '')
			{
				$empty = false;
				break;
			}
		}

		if(!isset($existed[$lid]))
		{
			if(!$empty)
			{
				$res = static::add(array_merge(
					array(
						$langField => $lid,
						$refField => $primaryOwner
					),
					$name
				));
				if(!$res->isSuccess())
					throw new MainSystemException(Loc::getMessage('SALE_LOCATION_NAME_NAME_ENTITY_CANNOT_ADD_NAMES_EXCEPTION'));
			}
		}
		else
		{
			if($empty)
			{
				$res = static::delete($existed[$lid]);
				if(!$res->isSuccess())
					throw new MainSystemException(Loc::getMessage('SALE_LOCATION_NAME_NAME_ENTITY_CANNOT_DELETE_NAMES_EXCEPTION'));
			}
			else
			{
				$res = static::update($existed[$lid], $name);
				if(!$res->isSuccess())
					throw new MainSystemException(Loc::getMessage('SALE_LOCATION_NAME_NAME_ENTITY_CANNOT_UPDATE_NAMES_EXCEPTION'));
			}
		}
	}
}