• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/requisite/importhelper.php
  • Класс: Bitrix\Crm\Requisite\ImportHelper
  • Вызов: ImportHelper::updatePresetCacheByName
protected function updatePresetCacheByName($presetName, $countryId)
{
	if (!is_int($countryId))
		$countryId = (int)$countryId;
	if ($countryId < 0)
		$countryId = 0;
	if (!is_string($presetName))
		$presetName = strval($presetName);
	if (mb_strlen($presetName) > 255)
		$presetName = mb_substr($presetName, 0, 255);

	if (!isset(self::$presetCacheByName[$presetName][$countryId]))
	{
		if ($presetName <> '')
		{
			$preset = EntityPreset::getSingleInstance();
			$presetList = array();
			$filter = array('=NAME' => $presetName);
			if ($countryId > 0)
				$filter['=COUNTRY_ID'] = $countryId;
			$res = $preset->getList(
				array(
					'order' => array('SORT' => 'ASC', 'ID' => 'ASC'),
					'filter' => $filter,
					'select' => array('ID', 'COUNTRY_ID', 'SETTINGS')
				)
			);
			while ($row = $res->fetch())
			{
				$id = (int)$row['ID'];
				$presetFieldMap = array();
				if (is_array($row['SETTINGS']))
				{
					$presetFieldsInfo = $preset->settingsGetFields($row['SETTINGS']);
					foreach ($presetFieldsInfo as $fieldInfo)
					{
						if (isset($fieldInfo['FIELD_NAME']) && !empty($fieldInfo['FIELD_NAME']))
							$presetFieldMap[$fieldInfo['FIELD_NAME']] = true;
					}
					unset($presetFieldsInfo, $fieldInfo);
				}
				$presetInfo = array(
					'ID' => $id,
					'COUNTRY_ID' => (int)$row['COUNTRY_ID'],
					'FIELD_MAP' => $presetFieldMap
				);
				$presetList[] = $presetInfo;
				if (!isset(self::$presetCacheById[$id]))
					self::$presetCacheById[$id] = $presetInfo;
			}
			if ($countryId <= 0)
			{
				$currentCountryId = EntityPreset::getCurrentCountryId();
				$allowedCountries = EntityRequisite::getAllowedRqFieldCountries();
				if ($currentCountryId > 0 && in_array($currentCountryId, $allowedCountries, true))
				{
					$upperPresets = array();

					foreach ($presetList as $key => $row)
					{
						if ($row['COUNTRY_ID'] === $currentCountryId)
						{
							$upperPresets[] = $row;
							unset($presetList[$key]);
						}
					}
					if (count($upperPresets) > 0)
						$presetList = array_merge($upperPresets, $presetList);
				}
			}
			if (count($presetList) > 0)
				self::$presetCacheByName[$presetName][$countryId] = $presetList;
			unset($presetList);
		}
		if (!isset(self::$presetCacheByName[$presetName][$countryId]))
		{
			self::$presetCacheByName[$presetName][$countryId] = false;
		}
	}
}