• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/Field/Stage.php
  • Класс: Bitrix\Crm\Field\Stage
  • Вызов: Stage::pickFirstStageIdInCurrentCategory
private function pickFirstStageIdInCurrentCategory(Factory $factory, Item $item): ?string
{
	$currentStage = $factory->getStage((string)$item->get($this->getName()));

	$currentStageSemantics = $currentStage ? $currentStage->getSemantics() : null;
	if (!PhaseSemantics::isDefined($currentStageSemantics))
	{
		$currentStageSemantics = PhaseSemantics::PROCESS;
	}

	$stagesInCurrentCategory = $factory->getStages($item->getCategoryId());

	foreach($stagesInCurrentCategory as $stage)
	{
		if(
			$stage->getSemantics() === $currentStageSemantics
			|| (
				(
					empty($stage->getSemantics())
					|| $stage->getSemantics() === PhaseSemantics::PROCESS
				)
				&&
				(
					empty($currentStageSemantics)
					|| $currentStageSemantics === PhaseSemantics::PROCESS
				)
			)
		)
		{
			return $stage->getStatusId();
		}
	}

	return null;
}