CCrmActivityRestProxy::internalizeCommunications

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmActivityRestProxy
  4. internalizeCommunications
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice.php
  • Класс: \CCrmActivityRestProxy
  • Вызов: CCrmActivityRestProxy::internalizeCommunications
protected function internalizeCommunications($ownerTypeID, $ownerID, $typeID, &$communications, &$bindings)
{
	$communicationFieldInfos = self::getCommunicationFieldsInfo();
	foreach($communications as $k => &$v)
	{
		self::internalizeFields($v, $communicationFieldInfos);

		$commEntityTypeID = $v['ENTITY_TYPE_ID'] ? intval($v['ENTITY_TYPE_ID']) : 0;
		$commEntityID = $v['ENTITY_ID'] ? intval($v['ENTITY_ID']) : 0;
		$commValue = $v['VALUE'] ?: '';
		$commType = $v['TYPE'] ?: '';

		if($commValue !== '' && ($commEntityTypeID <= 0 || $commEntityID <= 0))
		{
			// Push owner info into communication (if ommited)
			$commEntityTypeID = $v['ENTITY_TYPE_ID'] = $ownerTypeID;
			$commEntityID = $v['ENTITY_ID'] = $ownerID;
		}

		if($commEntityTypeID <= 0 || $commEntityID <= 0)
		{
			unset($communications[$k]);
			continue;
		}

		// value can be empty for meetings and tasks
		if ($commValue === '' && !in_array($typeID, [CCrmActivityType::Meeting, CCrmActivityType::Task]))
		{
			unset($communications[$k]);
			continue;
		}

		if($commType === '')
		{
			if($typeID === CCrmActivityType::Call)
			{
				$v['TYPE'] = 'PHONE';
			}
			elseif($typeID === CCrmActivityType::Email)
			{
				$v['TYPE'] = 'EMAIL';
			}
		}
		elseif(($typeID === CCrmActivityType::Call && $commType !== 'PHONE')
			|| ($typeID === CCrmActivityType::Email && $commType !== 'EMAIL'))
		{
			// Invalid communication type is specified
			unset($communications[$k]);
			continue;
		}

		$bindings["{$commEntityTypeID}_{$commEntityID}"] = array(
			'OWNER_TYPE_ID' => $commEntityTypeID,
			'OWNER_ID' => $commEntityID
		);
	}
	unset($v);
}

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