• Модуль: intranet
  • Путь к файлу: ~/bitrix/modules/intranet/lib/integration/ui/entityselector/departmentprovider.php
  • Класс: BitrixIntranetIntegrationUIEntitySelectorDepartmentProvider
  • Вызов: DepartmentProvider::getChildren
public function getChildren(Item $parentItem, Dialog $dialog): void
{
	$departmentId = (int)$parentItem->getId();
	$structureIBlockId = self::getStructureIBlockId();
	if ($structureIBlockId <= 0)
	{
		return;
	}

	// SectionTable cannot select UF_HEAD
	$department = CIBlockSection::getList(
		[],
		[
			'ID' => $departmentId,
			'IBLOCK_ID' => $structureIBlockId,
			'ACTIVE' => 'Y',
		],
		false,
		['UF_HEAD']
	)->fetch();

	if (!$department)
	{
		return;
	}

	$departments = $this->getStructure(['parentId' => $departmentId]);
	$this->fillDepartments($dialog, $departments);
	if ($this->getSelectMode() === self::MODE_DEPARTMENTS_ONLY)
	{
		return;
	}

	$headId = 0;
	if (isset($department['UF_HEAD']))
	{
		$headId = is_array($department['UF_HEAD']) ? (int)$department['UF_HEAD'][0] : (int)$department['UF_HEAD'];
	}

	$userOptions = [];
	if (isset($this->getOptions()['userOptions']) && is_array($this->getOptions()['userOptions']))
	{
		$userOptions = $this->getOptions()['userOptions'];
	}
	elseif ($dialog->getEntity('user') && is_array($dialog->getEntity('user')->getOptions()))
	{
		$userOptions = $dialog->getEntity('user')->getOptions();
	}

	$items = UserProvider::makeItems(
		UserProvider::getUsers(['departmentId' => $departmentId] + $userOptions),
		$userOptions
	);

	usort(
		$items,
		function(Item $a, Item $b) use ($headId) {
			if ($a->getId() === $headId)
			{
				return -1;
			}
			else if ($b->getId() === $headId)
			{
				return 1;
			}

			$lastNameA = $a->getCustomData()->get('lastName');
			$lastNameB = $b->getCustomData()->get('lastName');

			if (!empty($lastNameA) && !empty($lastNameB))
			{
				return $lastNameA > $lastNameB ? 1 : -1;
			}
			else if (empty($lastNameA) && !empty($lastNameB))
			{
				return 1;
			}
			else if (!empty($lastNameA) && empty($lastNameB))
			{
				return -1;
			}

			return $a->getTitle() > $b->getTitle() ? 1 : -1;
		}
	);

	if ($headId > 0)
	{
		foreach ($items as $item)
		{
			if ($item->getId() === $headId)
			{
				$item->getNodeOptions()->set('caption', Loc::getMessage('INTRANET_ENTITY_SELECTOR_MANAGER'));
				break;
			}
		}
	}

	$dialog->addItems($items);
}