• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/statistics/activitychannelstatisticentry.php
  • Класс: Bitrix\Crm\Statistics\ActivityChannelStatisticEntry
  • Вызов: ActivityChannelStatisticEntry::register
static function register($ownerID, $channelTypeID, array $bindingParams = null, array $entityFields = null, array $options = null)
{
	if(!is_int($ownerID))
	{
		$ownerID = (int)$ownerID;
	}

	if($ownerID <= 0)
	{
		throw new Main\ArgumentException('Owner ID must be greater than zero.', 'ownerID');
	}

	if($channelTypeID <= 0)
	{
		throw new Main\ArgumentException('Owner ID must be greater than zero.', 'channelTypeID');
	}

	if(!is_array($entityFields))
	{
		$dbResult = \CCrmActivity::GetList(
			array(),
			array('=ID' => $ownerID, 'CHECK_PERMISSIONS' => 'N'),
			false,
			false,
			array('RESPONSIBLE_ID', 'COMPLETED', 'CREATED', 'LAST_UPDATED', "DIRECTION")
		);
		$entityFields = is_object($dbResult) ? $dbResult->Fetch() : null;
		if(!is_array($entityFields))
		{
			return;
		}
	}
	$completed = isset($entityFields['COMPLETED']) ? $entityFields['COMPLETED'] : 'N';
	$responsibleID = isset($entityFields['RESPONSIBLE_ID']) ? (int)$entityFields['RESPONSIBLE_ID'] : 0;
	$direction = isset($entityFields['DIRECTION']) ? $entityFields['DIRECTION'] : \CCrmActivityDirection::Outgoing;

	/** @var Date $date */
	$date = self::parseDateString(isset($entityFields['CREATED']) ? $entityFields['CREATED'] : '');
	if($date === null)
	{
		$date = new Date();
	}

	$latest = self::get($ownerID, $channelTypeID);
	if(is_array($latest)
		&& $responsibleID === (int)$latest['RESPONSIBLE_ID']
		&& $completed === $latest['COMPLETED']
	)
	{
		return;
	}


	$data = array(
		'OWNER_ID' => $ownerID,
		'CREATED_DATE' => $date,
		'CHANNEL_TYPE_ID' => $channelTypeID,
		'CHANNEL_ORIGIN_ID' => isset($bindingParams['ORIGIN_ID']) ? $bindingParams['ORIGIN_ID'] : '',
		'CHANNEL_COMPONENT_ID' => isset($bindingParams['COMPONENT_ID']) ? $bindingParams['COMPONENT_ID'] : '',
		'RESPONSIBLE_ID' => $responsibleID,
		'COMPLETED' => $completed,
		'DIRECTION' => $direction
	);

	ActivityChannelStatisticsTable::upsert($data);
}