• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/access/user/usersubordinate.php
  • Класс: BitrixMainAccessUserUserSubordinate
  • Вызов: UserSubordinate::getSubordinate
public function getSubordinate(int $userId): int
{
	if ($this->userId === $userId)
	{
		return self::RELATION_HIMSELF;
	}

	if (!CModule::IncludeModule('intranet'))
	{
		return self::RELATION_OTHER;
	}

	$key = 'SUB_' . $this->userId .'_'. $userId;
	if (
		array_key_exists($key, static::$cache)
	)
	{
		return static::$cache[$key];
	}

	$managers = self::getAllManagers();

	$selfDepartments = self::getUserDepartments($this->userId);
	$foreignDepartments = self::getUserDepartments($userId);

	$inDepartment = !empty(array_intersect($selfDepartments, $foreignDepartments));

	$selfManagers = $this->getDepartmentsManagers($selfDepartments);
	$foreignManagers = $this->getDepartmentsManagers($foreignDepartments, true);

	if (in_array($this->userId, $foreignManagers))
	{
		static::$cache[$key] = self::RELATION_SUBORDINATE;
	}
	elseif (in_array($userId, $selfManagers))
	{
		static::$cache[$key] = self::RELATION_DIRECTOR;
	}
	elseif ($inDepartment)
	{
		static::$cache[$key] = self::RELATION_DEPARTMENT;
	}
	elseif (in_array($userId, $managers))
	{
		static::$cache[$key] = self::RELATION_OTHER_DIRECTOR;
	}
	else
	{
		static::$cache[$key] = self::RELATION_OTHER;
	}

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