CCrmEvent::RegisterViewEvent

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmEvent
  4. RegisterViewEvent
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_event.php
  • Класс: \CCrmEvent
  • Вызов: CCrmEvent::RegisterViewEvent
public function RegisterViewEvent($entityTypeID, $entityID, $userID = 0)
{
	$entityTypeName = CCrmOwnerType::ResolveName($entityTypeID);

	if(is_int($entityID))
	{
		$entityID = (int)$entityID;
	}

	if($userID <= 0)
	{
		$userID = CCrmSecurityHelper::GetCurrentUserID();
	}

	if($userID <= 0)
	{
		return false;
	}
	$user = \Bitrix\Main\UserTable::query()
		->where('ID', $userID)
		->setSelect(['IS_REAL_USER'])
		->fetch();
	if (!$user || $user['IS_REAL_USER'] !== 'Y')
	{
		return false;
	}

	$timestamp = time() + CTimeZone::GetOffset();
	//Event grouping interval in seconds
	$interval = HistorySettings::getCurrent()->getViewEventGroupingInterval() * 60;

	$query = new Bitrix\Main\Entity\Query(Bitrix\Crm\EventTable::getEntity());
	$query->setSelect(['ID']);
	$query->addFilter('=EVENT_TYPE', CCrmEvent::TYPE_VIEW);
	$query->addFilter('>=DATE_CREATE', ConvertTimeStamp(($timestamp - $interval), 'FULL'));
	$query->addFilter('=CREATED_BY_ID', $userID);
	$query->registerRuntimeField(
		'',
		new ReferenceField('RELATIONS',
			Bitrix\Crm\EventRelationsTable::getEntity(),
			[
				'ref.EVENT_ID' => 'this.ID',
				'ref.ENTITY_TYPE' => new \Bitrix\Main\DB\SqlExpression('?s', $entityTypeName),
				'ref.ENTITY_ID' => new \Bitrix\Main\DB\SqlExpression('?i', $entityID),
			],
			['join_type' => Join::TYPE_INNER]
		)
	);
	$query->setLimit(1);

	$dbResult = $query->exec()->fetch();
	if ($dbResult)
	{
		return false;
	}

	$entity = new CCrmEvent();
	$entity->Add(
		array(
			'USER_ID' => $userID,
			'ENTITY_ID' => $entityID,
			'ENTITY_TYPE' => $entityTypeName,
			'EVENT_TYPE' => CCrmEvent::TYPE_VIEW,
			'EVENT_NAME' => CCrmEvent::GetEventTypeName(CCrmEvent::TYPE_VIEW),
			'DATE_CREATE' => ConvertTimeStamp($timestamp, 'FULL', SITE_ID)
		),
		false
	);
	return true;
}

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