• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/location/admin/helper.php
  • Класс: BitrixSaleLocationAdminHelper
  • Вызов: Helper::resetLocationsForEntity
static function resetLocationsForEntity($entityId, $locations, $entityName, $expectCodes = false)
{
	$locList = array();

	if(is_array($locations) && !empty($locations))
	{
		foreach($locations as $loc)
		{
			if($loc['LOCATION_TYPE'] == 'L')
				$locList[LocationConnector::DB_LOCATION_FLAG][] = $loc['LOCATION_ID'];
			elseif($loc['LOCATION_TYPE'] == 'G')
				$locList[LocationConnector::DB_GROUP_FLAG][] = $loc['LOCATION_ID'];
		}
	}

	$entityClass = $entityName.'Table';

	try
	{
		if(!empty($locList) && !$expectCodes)
		{
			$locList[LocationConnector::DB_LOCATION_FLAG] = $entityClass::normalizeLocationList($locList[LocationConnector::DB_LOCATION_FLAG]);

			$gf = LocationConnector::DB_GROUP_FLAG;
			if(!empty($locList[$gf]))
			{
				$groupCodes = array();
				$locList[$gf] = array_flip($locList[$gf]);
				// here we must get codes by ids for groups. There will be no thousands of groups, so we can do the following:
				$res = LocationGroupTable::getList(array('select' => array('ID', 'CODE')));
				while($item = $res->fetch())
				{
					if(isset($locList[$gf][$item['ID']]))
						$groupCodes[$item['CODE']] = 1;
				}

				$locList[$gf] = array_keys($groupCodes);
			}
		}

		$entityClass::resetMultipleForOwner($entityId, $locList);
	}
	catch(Exception $e)
	{
	}
}