CAllCrmLead::SynchronizeMultifieldMarkers

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CAllCrmLead
  4. SynchronizeMultifieldMarkers
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_lead.php
  • Класс: \CAllCrmLead
  • Вызов: CAllCrmLead::SynchronizeMultifieldMarkers
static function SynchronizeMultifieldMarkers($sourceID, array $fields = null)
{
	global $DB;

	if($sourceID <= 0)
	{
		return;
	}

	if($fields === null)
	{
		$dbResult = self::GetListEx(
			array(),
			array('=ID' => $sourceID, 'CHECK_PERMISSIONS' => 'N'),
			false,
			false,
			array('ID', 'HAS_EMAIL', 'HAS_PHONE', 'HAS_IMOL')
		);

		if(is_object($dbResult))
		{
			$fields = $dbResult->Fetch();
		}
	}

	if($fields === null)
	{
		return;
	}

	$multifields = isset($fields['FM']) && is_array($fields['FM']) ? $fields['FM'] : null;
	if($multifields === null)
	{
		$multifields = DuplicateCommunicationCriterion::prepareEntityMultifieldValues(
			CCrmOwnerType::Lead,
			$sourceID
		);
	}

	$hasEmail = CCrmFieldMulti::HasValues($multifields, CCrmFieldMulti::EMAIL) ? 'Y' : 'N';
	$hasPhone = CCrmFieldMulti::HasValues($multifields, CCrmFieldMulti::PHONE) ? 'Y' : 'N';
	$hasImol = CCrmFieldMulti::HasImolValues($multifields) ? 'Y' : 'N';

	if(!isset($fields['HAS_EMAIL']) || $fields['HAS_EMAIL'] !== $hasEmail ||
		!isset($fields['HAS_PHONE']) || $fields['HAS_PHONE'] !== $hasPhone ||
		!isset($fields['HAS_IMOL']) || $fields['HAS_IMOL'] !== $hasImol
	)
	{
		$DB->Query("UPDATE b_crm_lead SET HAS_EMAIL = '{$hasEmail}', HAS_PHONE = '{$hasPhone}', HAS_IMOL = '{$hasImol}' WHERE ID = {$sourceID}", false, 'FILE: '.__FILE__.'
LINE: '.__LINE__); } }

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