Beispiel #1
0
 public static function GetAllowableUserGroups($documentType)
 {
     $documentType = trim($documentType);
     if (strlen($documentType) <= 0) {
         return false;
     }
     $arDocumentID = self::GetDocumentInfo($documentType);
     if ($arDocumentID !== false) {
         $documentType = $arDocumentID['TYPE'];
     }
     $arResult = array('author' => GetMessage('CRM_DOCUMENT_AUTHOR'));
     $arGroupsID = array(1);
     $arUsersID = array();
     $arRelations = CCrmPerms::GetEntityRelations($documentType, BX_CRM_PERM_SELF);
     foreach ($arRelations as $relation) {
         $preffix = substr($relation, 0, 1);
         if ($preffix === 'G') {
             $arGroupsID[] = intval(substr($relation, 1));
         } elseif ($preffix === 'U') {
             $arUsersID[] = substr($relation, 1);
         }
     }
     //Crutch for Bitrix24 context (user group management is not suppotted)
     if (IsModuleInstalled('bitrix24')) {
         $siteID = CAllSite::GetDefSite();
         $dbResult = CGroup::GetList($by = '', $order = '', array('STRING_ID' => 'EMPLOYEES_' . $siteID, 'STRING_ID_EXACT_MATCH' => 'Y'));
         if ($arEmloyeeGroup = $dbResult->Fetch()) {
             $employeeGroupID = intval($arEmloyeeGroup['ID']);
             if (!in_array($employeeGroupID, $arGroupsID, true)) {
                 $arGroupsID[] = $employeeGroupID;
             }
         }
     }
     if (!empty($arGroupsID)) {
         $dbGroupList = CGroup::GetListEx(array('NAME' => 'ASC'), array('ID' => $arGroupsID));
         while ($arGroup = $dbGroupList->Fetch()) {
             $arResult[$arGroup['ID']] = $arGroup['NAME'];
         }
     }
     if (isset(self::$UNGROUPED_USERS[$documentType])) {
         unset(self::$UNGROUPED_USERS[$documentType]);
     }
     self::$UNGROUPED_USERS[$documentType] = $arUsersID;
     if (!empty($arUsersID)) {
         //Group with empty name will be hidden in group list
         $arResult['ungrouped'] = '';
         //$arResult['ungrouped'] = GetMessage('CRM_DOCUMENT_UNGROUPED_USERS');
     }
     return $arResult;
 }