Forked from wateryoma/user_ department_check.php
Last active
August 29, 2015 14:06
-
-
Save waspar/118e1742293b3615e94e to your computer and use it in GitHub Desktop.
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