LeadContactTable::upsert

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. LeadContactTable
  4. upsert
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/binding/leadcontact.php
  • Класс: Bitrix\Crm\Binding\LeadContactTable
  • Вызов: LeadContactTable::upsert
static function upsert(array $data)
{
	$leadID = isset($data['LEAD_ID']) ? (int)$data['LEAD_ID'] : 0;
	if($leadID <= 0)
	{
		throw new Main\ArgumentException('Must contains LEAD_ID field.', 'data');
	}

	$contactID = isset($data['CONTACT_ID']) ? (int)$data['CONTACT_ID'] : 0;
	if($contactID <= 0)
	{
		throw new Main\ArgumentException('Must contains CONTACT_ID field.', 'data');
	}

	$sort = isset($data['SORT']) ? (int)$data['SORT'] : 0;
	$roleID = isset($data['ROLE_ID']) ? (int)$data['ROLE_ID'] : 0;
	$primary = isset($data['IS_PRIMARY']) && mb_strtoupper($data['IS_PRIMARY']) === 'Y' ? 'Y' : 'N';

	$connection = Main\Application::getConnection();
	$queries = $connection->getSqlHelper()->prepareMerge(
		'b_crm_lead_contact',
		array('LEAD_ID', 'CONTACT_ID'),
		array('LEAD_ID' => $leadID, 'CONTACT_ID' => $contactID, 'SORT' => $sort, 'ROLE_ID' => $roleID, 'IS_PRIMARY' => $primary),
		array('SORT' => $sort, 'ROLE_ID' => $roleID, 'IS_PRIMARY' => $primary)
	);

	foreach($queries as $query)
	{
		$connection->queryExecute($query);
	}
}

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