• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/exclusion/entity/exclusion.php
  • Класс: Bitrix\Crm\Exclusion\Entity\ExclusionTable
  • Вызов: ExclusionTable::addExclusionBatch
static function addExclusionBatch(array $list)
{
	$updateList = array();
	$sqlHelper = Application::getConnection()->getSqlHelper();
	$dateInsert = new DateTime();

	sort($list);
	foreach ($list as $index => $item)
	{
		$item = explode(';', $item);
		TrimArr($item);
		if (!$item[0])
		{
			continue;
		}

		$code = $item[0];
		$name = isset($item[1]) ? $item[1] : null;
		$name = is_string($name) ? trim($name) : null;
		$name = Encoding::convertEncodingToCurrent($name);

		$typeId = Communication\Type::detect($code);
		if (!$typeId)
		{
			continue;
		}

		$code = Communication\Normalizer::normalize($code, $typeId);
		if (!$code)
		{
			continue;
		}

		$updateItem = array(
			'TYPE_ID' => $typeId,
			'CODE' => $code,
			'COMMENT' => $name,
			'DATE_INSERT' => $dateInsert,
		);
		$updateList[] = $updateItem;
	}

	if (count($updateList) === 0)
	{
		return;
	}

	foreach (static::divideList($updateList) as $list)
	{
		$keys = implode(', ', array_keys(current($list)));
		$values = [];
		foreach ($list as $item)
		{
			$values[] = implode(
				", ",
				[
					(int) $item['TYPE_ID'],
					"'" . $sqlHelper->forSql($item['CODE']) . "'",
					$item['COMMENT'] ? "'" . $sqlHelper->forSql($item['COMMENT'], 255) . "'" : 'NULL',
					$sqlHelper->convertToDbDateTime($item['DATE_INSERT']),
				]
			);
		}
		$values = implode('), (', $values);

		$tableName = static::getTableName();
		$sql = "INSERT IGNORE $tableName($keys) VALUES($values)";
		Application::getConnection()->query($sql);
	}
}