• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/access/user/usersubordinate.php
  • Класс: BitrixMainAccessUserUserSubordinate
  • Вызов: UserSubordinate::getDepartmentsByUserId
static function getDepartmentsByUserId(int $userId): array
{
	$key = 'DEP_'.$userId;
	if (!array_key_exists($key, static::$cache))
	{
		$res = BitrixMainUserTable::getList(
			[
				'filter' => [
					'=ID' => $userId,
				],
				'select' => ['UF_DEPARTMENT']
			]
		);

		$departments = [];
		while ($row = $res->fetch())
		{
			if (is_array($row['UF_DEPARTMENT']))
			{
				$departments = array_merge($departments, $row['UF_DEPARTMENT']);
			}
		}

		static::$cache[$key] = $departments;
	}

	return static::$cache[$key];
}