IsRepeatedApproach::isPreviousSuccessfulItemExists

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. IsRepeatedApproach
  4. isPreviousSuccessfulItemExists
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/Field/IsRepeatedApproach.php
  • Класс: Bitrix\Crm\Field\IsRepeatedApproach
  • Вызов: IsRepeatedApproach::isPreviousSuccessfulItemExists
private function isPreviousSuccessfulItemExists(Item $item): bool
{
	$getItemsParams = [
		'select' => [Item::FIELD_NAME_ID],
		'filter' => [
			'=' . Item::FIELD_NAME_STAGE_SEMANTIC_ID => PhaseSemantics::SUCCESS,
		],
		'limit' => 1,
		'order' => [
			Item::FIELD_NAME_ID => 'ASC',
		],
	];

	if ($item->getCompanyId() > 0)
	{
		$getItemsParams['filter']['=' . Item::FIELD_NAME_COMPANY_ID] = $item->getCompanyId();
	}
	elseif (!is_null($item->getPrimaryContact()))
	{
		$getItemsParams['filter']['=' . Item::FIELD_NAME_CONTACT_ID] = $item->getPrimaryContact()->getId();
		$getItemsParams['filter']['<=' . Item::FIELD_NAME_COMPANY_ID] = 0;
	}
	else
	{
		throw new InvalidOperationException('The item has no client');
	}

	$factory = Container::getInstance()->getFactory($item->getEntityTypeId());

	if (!$factory)
	{
		return false;
	}

	$previousSuccessfulItem = $factory->getItems($getItemsParams)[0] ?? null;

	return !is_null($previousSuccessfulItem);
}

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