• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/lib/item/usertogroup.php
  • Класс: BitrixSocialnetworkItemUserToGroup
  • Вызов: UserToGroup::getConnectedGroups
static function getConnectedGroups($departmentList): array
{
	static $structureIBlockId = false;
	static $departmentChainCache = [];

	$result = [];

	if ($structureIBlockId === false)
	{
		$structureIBlockId = (int)Option::get('intranet', 'iblock_structure', 0);
	}

	if ((int)$structureIBlockId <= 0)
	{
		return $result;
	}

	$userDepartmentList = [];

	foreach($departmentList as $departmentId)
	{
		$departmentChain = [];
		if (isset($departmentChainCache[$departmentId]))
		{
			$departmentChain = $departmentChainCache[$departmentId];
		}
		else
		{
			$res = CIBlockSection::getNavChain($structureIBlockId, $departmentId, [ 'ID' ]);
			while ($section = $res->fetch())
			{
				if ((int)$section['ID'] > 0)
				{
					$departmentChain[] = (int)$section['ID'];
				}
			}
			$departmentChainCache[$departmentId] = $departmentChain;
		}
		$userDepartmentList = array_merge($userDepartmentList, $departmentChain);
	}

	$userDepartmentList = array_unique($userDepartmentList);

	if (!empty($userDepartmentList))
	{
		$res = WorkgroupTable::getList([
			'filter' => [
				'@UF_SG_DEPT' => $userDepartmentList,
			],
			'select' => [ 'ID' ],
		]);
		while ($group = $res->fetch())
		{
			if ((int)$group['ID'] > 0)
			{
				$result[] = (int)$group['ID'];
			}
		}
	}

	return array_unique($result);
}