• Модуль: intranet
  • Путь к файлу: ~/bitrix/modules/intranet/lib/integration/ui/entityselector/departmentprovider.php
  • Класс: BitrixIntranetIntegrationUIEntitySelectorDepartmentProvider
  • Вызов: DepartmentProvider::getDepartments
public function getDepartments(array $ids, array $options = []): array
{
	$structureIBlockId = self::getStructureIBlockId();
	if ($structureIBlockId <= 0)
	{
		return [];
	}

	$query = SectionTable::query();
	$query->setSelect(['ID', 'NAME', 'DEPTH_LEVEL', 'IBLOCK_SECTION_ID', 'LEFT_MARGIN', 'RIGHT_MARGIN']);
	$query->setOrder(['LEFT_MARGIN' => 'asc']);
	$query->where('IBLOCK_ID', $structureIBlockId);

	// ids = [1, '1:F', '10:F', '5:F', 5]
	$integerIds = array_map('intval', $ids);
	$idMap = array_combine($ids, $integerIds);
	$query->whereIn('ID', array_unique($integerIds));

	$active = isset($options['active']) ? $options['active'] : true;
	if (is_bool($active))
	{
		$query->where('ACTIVE', $active ? 'Y' : 'N');
	}

	$items = [];
	$departments = $query->exec()->fetchCollection();
	if ($departments->count() > 0)
	{
		foreach ($idMap as $id => $integerId)
		{
			$department = $departments->getByPrimary($integerId);
			if (!$department)
			{
				continue;
			}

			$isFlatDepartment = is_string($id) && $id[-1] === 'F';
			$availableInRecentTab = false;
			if ($isFlatDepartment)
			{
				$availableInRecentTab =
					$this->getSelectMode() === self::MODE_USERS_AND_DEPARTMENTS &&
					$this->options['allowFlatDepartments'] === true
				;
			}
			else
			{
				$availableInRecentTab = $this->getSelectMode() !== self::MODE_USERS_ONLY;
				if ($department->getDepthLevel() === 1 && !$this->options['allowSelectRootDepartment'])
				{
					$availableInRecentTab = false;
				}
			}

			$titlePostfix =
				$isFlatDepartment
					? ' ' . Loc::getMessage('INTRANET_ENTITY_SELECTOR_ONLY_EMPLOYEES')
					: ''
			;

			$items[] = new Item([
				'id' => $id,
				'entityId' => 'department',
				'title' => $department->getName() . $titlePostfix,
				'availableInRecentTab' => $availableInRecentTab,
				'searchable' => $availableInRecentTab,
			]);
		}
	}

	return $items;
}