QuoteContactTable::bindContacts

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. QuoteContactTable
  4. bindContacts
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/binding/quotecontact.php
  • Класс: Bitrix\Crm\Binding\QuoteContactTable
  • Вызов: QuoteContactTable::bindContacts
static function bindContacts($quoteID, array $bindings)
{
	$quoteID = (int)$quoteID;
	if($quoteID <= 0)
	{
		throw new Main\ArgumentException('Must be greater than zero', 'quoteID');
	}

	$qty = count($bindings);
	if($qty === 0)
	{
		return;
	}

	$processed = 0;
	for($i = 0; $i < $qty; $i++)
	{
		$binding = $bindings[$i];

		$contactID = isset($binding['CONTACT_ID']) ? (int)$binding['CONTACT_ID'] : 0;
		if($contactID <= 0)
		{
			continue;
		}

		self::upsert(
			array(
				'QUOTE_ID' => $quoteID,
				'CONTACT_ID' => $contactID,
				'SORT' => isset($binding['SORT']) ? (int)$binding['SORT'] : (10 * ($i + 1)),
				'ROLE_ID' => isset($binding['ROLE_ID']) ? (int)$binding['ROLE_ID'] : EntityBinding::ROLE_UNDEFINED,
				'IS_PRIMARY' => isset($binding['IS_PRIMARY']) ? $binding['IS_PRIMARY'] : ''
			)
		);
		$processed++;
	}

	if($processed > 0)
	{
		Main\Application::getConnection()->queryExecute(
			/** @lang text*/
			"UPDATE b_crm_quote SET CONTACT_ID =
			(SELECT MIN(CONTACT_ID) FROM b_crm_quote_contact WHERE IS_PRIMARY = 'Y' AND QUOTE_ID = {$quoteID})
			WHERE ID = {$quoteID}"
		);
	}
}

Добавить комментарий