Created
August 27, 2014 16:10
-
-
Save wateryoma/3c03c65e9bd8e465a854 to your computer and use it in GitHub Desktop.
BITRIX: Is User in department check. Check if user in department, or subdepartment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* check if user in department | |
* | |
* @param int $iUserID | |
* @param int $iDepartmentID | |
* @param bool $bCheckSubDepartments | |
* @return bool | |
*/ | |
function IsInDepartment($iUserID, $iDepartmentID, $bCheckSubDepartments = true) | |
{ | |
$arUserDepartments = CIntranetUtils::GetUserDepartments($iUserID); | |
$arDepartments[] = $iDepartmentID; | |
if ($bCheckSubDepartments) { | |
$arSubDepartments = CIntranetUtils::GetDeparmentsTree($iDepartmentID); | |
if (!empty($arSubDepartments)) { | |
foreach ($arSubDepartments as $_arDepartments) { | |
$arDepartments = array_merge($arDepartments, $_arDepartments); | |
} | |
} | |
} | |
$arDepartmentsIntersection = array_intersect($arUserDepartments, $arDepartments); | |
if (!empty($arDepartmentsIntersection)) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment