public static function getDepartmentUsers($sectionId, $siteId, $arSubDeps, $arManagers, $ynShowInactiveUsers, $nameTemplate) { static $arCacheUsers = array(); $cacheKey = (string) $sectionId . '|' . (string) $siteId . '|' . serialize($arSubDeps) . '|' . serialize($arManagers) . '|' . $ynShowInactiveUsers; static $arCUserRequestedFields = array('ID', 'PERSONAL_PHOTO', 'PERSONAL_GENDER', 'LOGIN', 'EMAIL', 'WORK_POSITION', 'PERSONAL_PROFESSION', 'UF_DEPARTMENT', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'EMAIL'); // Precache data, if need if (!array_key_exists($cacheKey, $arCacheUsers)) { $arFilter = array(); $filterACTIVE = 'Y'; if ($ynShowInactiveUsers === 'Y') { $filterACTIVE = ''; } $arFilter['ACTIVE'] = $filterACTIVE; // Prevent using users, that doesn't activate it's account // http://jabber.bx/view.php?id=29118 if (IsModuleInstalled('bitrix24')) { $arFilter['CONFIRM_CODE'] = false; } if ($sectionId == "extranet") { $arFilter['GROUPS_ID'] = array(COption::GetOptionInt("extranet", "extranet_group", "")); // $arFilter['UF_DEPARTMENT'] = false; } else { $arFilter['UF_DEPARTMENT'] = $sectionId; } $arUsers = array(); if ($sectionId != "extranet") { $ufHead = CIntranetUtils::getDepartmentManagerID($sectionId); if ($ufHead > 0) { $arHeadFilter = array('ID' => $ufHead, 'ACTIVE' => $filterACTIVE); if (IsModuleInstalled('bitrix24')) { $arHeadFilter['CONFIRM_CODE'] = false; } //fetch only one manager by Section $dbUsers = CUser::GetList($sort_by = 'last_name', $sort_dir = 'asc', $arHeadFilter, array('SELECT' => $arCUserRequestedFields)); if ($arRes = $dbUsers->GetNext()) { $arFilter['!ID'] = $arRes['ID']; $arUsers[] = array('ID' => $arRes['ID'], 'NAME' => CUser::FormatName($nameTemplate, array("NAME" => $arRes["~NAME"], "LAST_NAME" => $arRes["~LAST_NAME"], "LOGIN" => $arRes["~LOGIN"], "SECOND_NAME" => $arRes["~SECOND_NAME"]), true, false), 'LOGIN' => $arRes['LOGIN'], 'EMAIL' => $arRes['EMAIL'], 'WORK_POSITION' => $arRes['~WORK_POSITION'] ? $arRes['~WORK_POSITION'] : $arRes['~PERSONAL_PROFESSION'], 'PHOTO' => (string) CIntranetUtils::createAvatar($arRes, array(), $siteId), 'HEAD' => true, 'UF_DEPARTMENT' => $arRes['UF_DEPARTMENT'], 'SUBORDINATE' => is_array($arSubDeps) && is_array($arRes['UF_DEPARTMENT']) && array_intersect($arRes['UF_DEPARTMENT'], $arSubDeps) ? 'Y' : 'N', 'SUPERORDINATE' => in_array($arRes["ID"], $arManagers) ? 'Y' : 'N'); } } } $dbRes = CUser::GetList($by = 'last_name', $order = 'asc', $arFilter, array('SELECT' => $arCUserRequestedFields)); while ($arRes = $dbRes->GetNext()) { $arUsers[] = array('ID' => $arRes['ID'], 'NAME' => CUser::FormatName($nameTemplate, array("NAME" => $arRes["~NAME"], "LAST_NAME" => $arRes["~LAST_NAME"], "LOGIN" => $arRes["~LOGIN"], "SECOND_NAME" => $arRes["~SECOND_NAME"]), true, false), 'LOGIN' => $arRes['LOGIN'], 'EMAIL' => $arRes['EMAIL'], 'WORK_POSITION' => $arRes['~WORK_POSITION'] ? $arRes['~WORK_POSITION'] : $arRes['~PERSONAL_PROFESSION'], 'PHOTO' => (string) CIntranetUtils::createAvatar($arRes, array(), $siteId), 'HEAD' => false, 'UF_DEPARTMENT' => $arRes['UF_DEPARTMENT'], 'SUBORDINATE' => is_array($arSubDeps) && is_array($arRes['UF_DEPARTMENT']) && array_intersect($arRes['UF_DEPARTMENT'], $arSubDeps) ? 'Y' : 'N', 'SUPERORDINATE' => in_array($arRes["ID"], $arManagers) ? 'Y' : 'N'); } $arCacheUsers[$cacheKey] = array_values(array_filter($arUsers, array('CIntranetUserSelectorHelper', 'filterViewableUsers'))); } return $arCacheUsers[$cacheKey]; }
} if (!isset($arStructure['TREE'][$iblockSectionId])) { $arStructure['TREE'][$iblockSectionId] = array(); } $arStructure['TREE'][$iblockSectionId][] = $item['ID']; } } CIntranetUserSelectorHelper::drawEmployeeStructure($arStructure['TREE'], $arStructure['DATA'], $sectionId, $selectorName, !$showUsers); } $arFilter['UF_DEPARTMENT'] = $sectionId; } $arUsers = array(); if ($showUsers) { $arFilter["CONFIRM_CODE"] = false; if ($sectionId != "extranet") { $ufHead = CIntranetUtils::getDepartmentManagerID($sectionId); if ($ufHead > 0) { $arHeadFilter = array('ID' => $ufHead, 'ACTIVE' => $showActiveUsers, 'CONFIRM_CODE' => false); $dbUsers = CUser::GetList($sort_by = 'last_name', $sort_dir = 'asc', $arHeadFilter, array('SELECT' => array('UF_DEPARTMENT'))); if ($arRes = $dbUsers->Fetch()) { $arFilter['!ID'] = $arRes['ID']; $arUsers[] = array('ID' => $arRes['ID'], 'NAME' => CUser::FormatName($nameTemplate, $arRes, $bUseLogin, false), 'LOGIN' => $arRes['LOGIN'], 'EMAIL' => $arRes['EMAIL'], 'WORK_POSITION' => $arRes['WORK_POSITION'] ? $arRes['WORK_POSITION'] : $arRes['PERSONAL_PROFESSION'], 'PHOTO' => (string) CIntranetUtils::createAvatar($arRes, array()), 'HEAD' => true, 'UF_DEPARTMENT' => $arRes['UF_DEPARTMENT'], 'SUBORDINATE' => is_array($arSubDeps) && is_array($arRes['UF_DEPARTMENT']) && array_intersect($arRes['UF_DEPARTMENT'], $arSubDeps) ? 'Y' : 'N', 'SUPERORDINATE' => in_array($arRes["ID"], $arManagers) ? 'Y' : 'N'); } } } $dbRes = CUser::GetList($by = 'last_name', $order = 'asc', $arFilter, array('SELECT' => array('UF_DEPARTMENT'))); while ($arRes = $dbRes->Fetch()) { //exclude extranet users in accordance with SHOW_EXTRANET_USER parameter if (($showExtranetUsers == SHOW_FROM_MY_GROUPS || $showExtranetUsers == SHOW_FROM_EXACT_GROUP) && $arRes["UF_DEPARTMENT"] == false && !in_array($arRes["ID"], $arFilteredUserIDs)) { continue; }