• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/lib/componenthelper.php
  • Класс: BitrixSocialnetworkComponentHelper
  • Вызов: ComponentHelper::convertSelectorRequestData
static function convertSelectorRequestData(array &$postFields = [], array $params = []): void
{
	$perms = (string)($params['perms'] ?? '');
	$crm = (bool)($params['crm'] ?? false);

	$mapping = [
		'DEST_DATA' => 'DEST_CODES',
		'GRAT_DEST_DATA' => 'GRAT_DEST_CODES',
	];

	foreach ($mapping as $from => $to)
	{
		if (isset($postFields[$from]))
		{
			try
			{
				$entities = Json::decode($postFields[$from]);
			}
			catch (ArgumentException $e)
			{
				$entities = [];
			}

			$postFields[$to] = array_merge(
				($postFields[$to] ?? []),
				BitrixMainUIEntitySelectorConverter::convertToFinderCodes($entities)
			);
		}
	}

	$mapping = [
		'DEST_CODES' => 'SPERM',
		'GRAT_DEST_CODES' => 'GRAT',
		'EVENT_DEST_CODES' => 'EVENT_PERM'
	];

	foreach ($mapping as $from => $to)
	{
		if (isset($postFields[$from]))
		{
			if (
				!isset($postFields[$to])
				|| !is_array($postFields[$to])
			)
			{
				$postFields[$to] = [];
			}

			foreach ($postFields[$from] as $destCode)
			{
				if ($destCode === 'UA')
				{
					if (empty($postFields[$to]['UA']))
					{
						$postFields[$to]['UA'] = [];
					}
					$postFields[$to]['UA'][] = 'UA';
				}
				elseif (preg_match('/^UE(.+)$/i', $destCode, $matches))
				{
					if (empty($postFields[$to]['UE']))
					{
						$postFields[$to]['UE'] = [];
					}
					$postFields[$to]['UE'][] = $matches[1];
				}
				elseif (preg_match('/^U(d+)$/i', $destCode, $matches))
				{
					if (empty($postFields[$to]['U']))
					{
						$postFields[$to]['U'] = [];
					}
					$postFields[$to]['U'][] = 'U' . $matches[1];
				}
				elseif (
					$from === 'DEST_CODES'
					&& $perms === BLOG_PERMS_FULL
					&& preg_match('/^UP(d+)$/i', $destCode, $matches)
					&& Loader::includeModule('blog')
				)
				{
					if (empty($postFields[$to]['UP']))
					{
						$postFields[$to]['UP'] = [];
					}
					$postFields[$to]['UP'][] = 'UP' . $matches[1];
				}
				elseif (preg_match('/^SG(d+)$/i', $destCode, $matches))
				{
					if (empty($postFields[$to]['SG']))
					{
						$postFields[$to]['SG'] = [];
					}
					$postFields[$to]['SG'][] = 'SG' . $matches[1];
				}
				elseif (preg_match('/^DR(d+)$/i', $destCode, $matches))
				{
					if (empty($postFields[$to]['DR']))
					{
						$postFields[$to]['DR'] = [];
					}
					$postFields[$to]['DR'][] = 'DR' . $matches[1];
				}
				elseif ($crm && preg_match('/^CRMCONTACT(d+)$/i', $destCode, $matches))
				{
					if (empty($postFields[$to]['CRMCONTACT']))
					{
						$postFields[$to]['CRMCONTACT'] = [];
					}
					$postFields[$to]['CRMCONTACT'][] = 'CRMCONTACT' . $matches[1];
				}
				elseif ($crm && preg_match('/^CRMCOMPANY(d+)$/i', $destCode, $matches))
				{
					if (empty($postFields[$to]['CRMCOMPANY']))
					{
						$postFields[$to]['CRMCOMPANY'] = [];
					}
					$postFields[$to]['CRMCOMPANY'][] = 'CRMCOMPANY' . $matches[1];
				}
				elseif ($crm && preg_match('/^CRMLEAD(d+)$/i', $destCode, $matches))
				{
					if (empty($postFields[$to]['CRMLEAD']))
					{
						$postFields[$to]['CRMLEAD'] = [];
					}
					$postFields[$to]['CRMLEAD'][] = 'CRMLEAD' . $matches[1];
				}
				elseif ($crm && preg_match('/^CRMDEAL(d+)$/i', $destCode, $matches))
				{
					if (empty($postFields[$to]['CRMDEAL']))
					{
						$postFields[$to]['CRMDEAL'] = [];
					}
					$postFields[$to]['CRMDEAL'][] = 'CRMDEAL' . $matches[1];
				}
			}

			unset($postFields[$from]);
		}
	}
}