SyncCountableDataAgent::resetCounterByEntity

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. SyncCountableDataAgent
  4. resetCounterByEntity
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/agent/activity/synccountabledataagent.php
  • Класс: Bitrix\Crm\Agent\Activity\SyncCountableDataAgent
  • Вызов: SyncCountableDataAgent::resetCounterByEntity
private function resetCounterByEntity($entityTypeId,  $entityId, ?int $oldResponsibleId = null): void
{
	$factory = Container::getInstance()->getFactory($entityTypeId);
	if (!$factory)
	{
		return;
	}
	if (!$factory->isCountersEnabled())
	{
		return;
	}
	$assignedByFiledName = $factory->getEntityFieldNameByMap(Item::FIELD_NAME_ASSIGNED);
	$categoryIdFieldName = $factory->getEntityFieldNameByMap(Item::FIELD_NAME_CATEGORY_ID);

	$select = [
		Item::FIELD_NAME_ID,
	];
	if ($factory->isFieldExists(Item::FIELD_NAME_ASSIGNED))
	{
		$select[] = $assignedByFiledName;
	}
	if ($factory->isFieldExists(Item::FIELD_NAME_CATEGORY_ID))
	{
		$select[] = $categoryIdFieldName;
	}

	$entity = $factory->getDataClass()::query()
		->setSelect($select)
		->whereIn('ID', $entityId)
		->fetch()
	;
	$extras = [];
	$responsibleId = null;
	if ($entity)
	{
		if ($factory->isCategoriesEnabled())
		{
			$extras['CATEGORY_ID'] = $entity[$categoryIdFieldName];
		}
		$responsibleId = $entity[$assignedByFiledName];
	}

	$counterCodes = EntityCounterManager::prepareCodes(
		$entityTypeId,
		EntityCounterType::getAll(true),
		$extras
	);
	$users = [];
	if ($oldResponsibleId)
	{
		$users[] = $oldResponsibleId;
	}
	if ($responsibleId)
	{
		$users[] = $responsibleId;
	}

	if(!empty($counterCodes))
	{
		EntityCounterManager::reset($counterCodes, $users);
		EntityCounterManager::resetExcludeUsersCounters($counterCodes, $users);
	}
}

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