• Модуль: bizproc
  • Путь к файлу: ~/bitrix/modules/bizproc/lib/integration/rest/appconfiguration.php
  • Класс: BitrixBizprocIntegrationRestAppConfiguration
  • Вызов: AppConfiguration::changeDealCategoryAction
static function changeDealCategoryAction($data, $ratioRegEx, $ratioReplace, $ratio)
{
	if (is_string($data))
	{
		$data = preg_replace($ratioRegEx, $ratioReplace, $data);
	}
	elseif (is_array($data))
	{
		if (
			isset($data['field'])
			&& $data['field'] == 'CATEGORY_ID'
			&& $data['value'] > 0
			&& $ratio[$data['value']] > 0
		)
		{
			$data['value'] = $ratio[$data['value']];
		}

		foreach ($data as $key => $value)
		{
			$newKey = static::changeDealCategoryAction($key, $ratioRegEx, $ratioReplace, $ratio);
			if ($newKey != $key)
			{
				unset($data[$key]);
			}

			if ($newKey == 'CATEGORY_ID')
			{
				if (is_array($value))
				{
					if (isset($value['Options']) && is_array($value['Options']))
					{
						$data[$newKey]['Options'] = [];
						foreach ($value['Options'] as $dealId => $title)
						{
							if (isset($ratio[$dealId]))
							{
								$data[$newKey]['Options'][$ratio[$dealId]] = $title;
							}
						}
					}
					else
					{
						$data[$newKey] = static::changeDealCategoryAction(
							$value,
							$ratioRegEx,
							$ratioReplace,
							$ratio
						);
					}
				}
				elseif (is_string($value) && isset($ratio[$value]))
				{
					$data[$newKey] = $ratio[$value];
				}
				else
				{
					$data[$newKey] = static::changeDealCategoryAction(
						$value,
						$ratioRegEx,
						$ratioReplace,
						$ratio
					);
				}
			}
			elseif ($newKey == 'CategoryId' && intVal($value) > 0 && !empty($ratio[$value]))
			{
				$data[$newKey] = $ratio[$value];
			}
			else
			{
				$data[$newKey] = static::changeDealCategoryAction(
					$value,
					$ratioRegEx,
					$ratioReplace,
					$ratio
				);
			}
		}
	}

	return $data;
}