• Модуль: timeman
  • Путь к файлу: ~/bitrix/modules/timeman/classes/general/timeman.php
  • Класс: CTimeMan
  • Вызов: CTimeMan::GetDirectAccess
static function GetDirectAccess($USER_ID = false)
{
	global $USER;
	$USER_ID = intval($USER_ID);
	if ($USER_ID <= 0)
	{
		$USER_ID = $USER->GetID();
	}
	$arSDeps = CIntranetUtils::GetSubordinateDepartments($USER_ID, true);
	$arStruct = CIntranetUtils::GetStructure();
	$arEmployees = [];
	foreach ($arSDeps as $dpt)
	{
		$arCurDpt = $arStruct['DATA'][$dpt];

		$employee = (($arCurDpt["UF_HEAD"]) ? $arCurDpt["UF_HEAD"] ://have we a manager?
			((count($arCurDpt["EMPLOYEES"]) > 0) ? $arCurDpt["EMPLOYEES"][0] : false//first employee of the dep
			)
		);
		if ($employee && $employee == $USER_ID)//this user is a head manager
		{
			foreach ($arCurDpt["EMPLOYEES"] as $empUser)
			{
				$arEmployees[] = $empUser;
			}
		}
		elseif ($employee)//no head manager or this user is no head manager
		{

			$headManager = CTimeMan::GetUserManagers($employee);//find head manager of employee
			if ($USER_ID == $headManager[0])//
			{
				if ($arCurDpt["UF_HEAD"])
				{
					$arEmployees[] = $employee;
				}
				else
				{
					foreach ($arCurDpt["EMPLOYEES"] as $empUser)
					{
						$arEmployees[] = $empUser;
					}
				}
			}
		}
	}

	return array_unique($arEmployees);
}