CCrmDocumentDeal::performTypeCast4CategoryAndStage

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmDocumentDeal
  4. performTypeCast4CategoryAndStage
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_document_deal.php
  • Класс: \CCrmDocumentDeal
  • Вызов: CCrmDocumentDeal::performTypeCast4CategoryAndStage
static function performTypeCast4CategoryAndStage(array $fields, int $presentCategoryID = null): array
{
	if (!isset($fields['STAGE_ID']))
	{
		return $fields;
	}

	if($fields['STAGE_ID'] === '')
	{
		unset($fields['STAGE_ID']);

		return $fields;
	}

	$stageID = $fields['STAGE_ID'];
	$stageCategoryID = DealCategory::resolveFromStageID($stageID);
	if($presentCategoryID === null && !isset($fields['CATEGORY_ID']))
	{
		$fields['CATEGORY_ID'] = $stageCategoryID;

		return $fields;
	}

	$categoryID = $presentCategoryID ?? (int)$fields['CATEGORY_ID'];
	if($categoryID !== $stageCategoryID)
	{
		throw new Exception(
			GetMessage(
				'CRM_DOCUMENT_DEAL_STAGE_MISMATCH_ERROR',
				[
					'#CATEGORY#' => DealCategory::getName($categoryID),
					'#TARG_CATEGORY#' => DealCategory::getName($stageCategoryID),
					'#TARG_STAGE#' => DealCategory::getStageName($stageID, $stageCategoryID)
				]
			)
		);
	}

	return $fields;
}

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