• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/Service/DynamicTypesMap.php
  • Класс: Bitrix\Crm\Service\DynamicTypesMap
  • Вызов: DynamicTypesMap::load
public function load(array $params = []): self
{
	$isLoadStages = $params['isLoadStages'] ?? true;
	$isLoadCategories = $params['isLoadCategories'] ?? true;
	if($isLoadStages)
	{
		// we have to load categories to properly load stages
		$isLoadCategories = true;
	}

	if ($this->isTypesLoaded
		&& (
			($isLoadCategories && $this->isCategoriesLoaded)
			|| !$isLoadCategories
		)
		&&
		(
			($isLoadStages && $this->isStagesLoaded)
			|| !$isLoadStages
		)
	)
	{
		// loaded everything that needed
		return $this;
	}

	if(!$this->isTypesLoaded)
	{
		$this->isTypesLoaded = true;
		foreach ($this->getTypesCollection() as $type)
		{
			if (!\CCrmOwnerType::isPossibleDynamicTypeId($type->getEntityTypeId()))
			{
				continue;
			}
			$factory = Container::getInstance()->getDynamicFactoryByType($type);
			$stagesFieldName = null;
			if ($factory->isStagesSupported())
			{
				$stagesFieldName = $factory->getEntityFieldNameByMap(Item::FIELD_NAME_STAGE_ID);
			}
			$this->types[$type->getEntityTypeId()] = $type;
			$this->stageFieldNames[$type->getEntityTypeId()] = $stagesFieldName;
			$this->isAutomationEnabled[$type->getEntityTypeId()] = $factory->isAutomationEnabled();
		}
	}
	$entityTypeIds = array_keys($this->types);

	if (empty($entityTypeIds))
	{
		$this->isCategoriesLoaded = true;
		$this->isStagesLoaded = true;
		return $this;
	}

	if (!$isLoadCategories)
	{
		return $this;
	}

	if(!$this->isCategoriesLoaded)
	{
		foreach (static::$categoryDataClass::getList([
				'filter' => [
					'@ENTITY_TYPE_ID' => $entityTypeIds,
				],
			])->fetchCollection() as $category)
		{
			$entityTypeId = $category->getEntityTypeId();
			$this->categoryIds[$category->getId()] = $entityTypeId;
			$this->categories[$entityTypeId][$category->getId()] = $category;
			if($category->getIsDefault())
			{
				$this->defaultCategoryIds[$entityTypeId] = $category->getId();
			}
			$stagesEntityId = Container::getInstance()
				->getDynamicFactoryByType($this->types[$entityTypeId])
				->getStagesEntityId($category->getId());
			if($stagesEntityId)
			{
				$this->stageEntityIds[$stagesEntityId] = $this->combineEntityAndCategory($entityTypeId, $category->getId());
			}
		}
		$this->isCategoriesLoaded = true;
	}

	if (empty($this->stageEntityIds) || !$isLoadStages)
	{
		return $this;
	}

	if(!$this->isStagesLoaded)
	{
		foreach (static::$stagesDataClass::getList([
				'order' => [
					'SORT' => 'ASC',
				],
				'filter' => [
					'@ENTITY_ID' => array_keys($this->stageEntityIds),
				]
			])->fetchCollection() as $stage)
		{
			$this->stages[$stage->getEntityId()][$stage->getStatusId()] = $stage;
		}
		$this->isStagesLoaded = true;
	}

	return $this;
}