• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/integration/intranet/user.php
  • Класс: BitrixTasksIntegrationIntranetis
  • Вызов: is::getSubordinate
static function getSubordinate($userId = 0, $allowedDepartments = null, $includeSubDepartments = false, $withFired = false)
{
	if(!static::includeModule())
	{
		return array();
	}

	$arDepartmentHeads = array();

	$arQueueDepartmentsEmployees = array();	// IDs of departments where we need employees

	// Departments where given user is head

	$arManagedDepartments = CIntranetUtils::getSubordinateDepartments($userId ? $userId : null, $includeSubDepartments);

	if (is_array($allowedDepartments))
	{
		$arManagedDepartments = array_intersect(
			$arManagedDepartments,
			$allowedDepartments
		);
	}

	if (is_array($arManagedDepartments))
	{
		foreach ($arManagedDepartments as $departmentId)
		{
			$arQueueDepartmentsEmployees[] = $departmentId;

			$result = static::searchImmediateEmployeesInSubDepartments($departmentId);

			$arDepartmentHeads = array_merge(
				$arDepartmentHeads,
				$result['arDepartmentHeads']
			);

			$arQueueDepartmentsEmployees = array_merge(
				$arQueueDepartmentsEmployees,
				$result['arQueueDepartmentsEmployees']
			);
		}
	}

	$arEmployees = $arDepartmentHeads;

	if ( ! empty($arQueueDepartmentsEmployees) )
	{
		$arEmployees = array_merge(
			$arEmployees,
			static::getDepartmentsUsersIds($arQueueDepartmentsEmployees, $withFired)
		);
	}

	if ( ! empty($arEmployees) )
	{
		$arEmployees = array_unique(array_filter($arEmployees));

		// Remove itself
		$curUserIndex = array_search($userId, $arEmployees);
		if ($curUserIndex !== false)
		{
			unset($arEmployees[$curUserIndex]);
		}
	}

	return ($arEmployees);
}