CBPHelper::UsersStringToArray: Bitrix method

      
<?php 
//  CBPHelper :: UsersStringToArray()
//  /dist/bitrix/modules/bizproc/classes/general/helper.php:119

    
public static function UsersStringToArray($strUsers$documentType, &$arErrors$callbackFunction null)
    {
        
$arErrors = [];

        
$strUsers trim($strUsers);
        if (
strlen($strUsers) <= 0)
        {
            return (
$callbackFunction != null) ? array(array(), array()) : array();
        }

        if (
CBPActivity::isExpression($strUsers))
        {
            return (
$callbackFunction != null) ? array(array($strUsers), array()) : array($strUsers);
        }

        
$arUsers = [];
        
$strUsers str_replace(";"","$strUsers);
        
$arUsersTmp explode(","$strUsers);
        foreach (
$arUsersTmp as $user)
        {
            
$user trim($user);
            if (
strlen($user) > 0)
            {
                
$arUsers[] = $user;
            }
        }

        
$arAllowableUserGroups null;

        
$arResult $arResultAlt = [];
        foreach (
$arUsers as $user)
        {
            
$bCorrectUser false;
            
$bNotFoundUser true;
            if (
preg_match(CBPActivity::ValuePattern$user$arMatches))
            {
                
$bCorrectUser true;
                
$arResult[] = $arMatches[0];
            }
            else
            {
                if (
$arAllowableUserGroups == null)
                {
                    
$arAllowableUserGroups = [];
                    
$arAllowableUserGroupsTmp CBPDocument::GetAllowableUserGroups($documentType);
                    foreach (
$arAllowableUserGroupsTmp as $k1 => $v1)
                    {
                        
$arAllowableUserGroups[strtolower($k1)] = strtolower($v1);
                    }
                }

                if (
array_key_exists(strtolower($user), $arAllowableUserGroups))
                {
                    
$bCorrectUser true;
                    
$arResult[] = $user;
                }
                elseif ((
$k1 array_search(strtolower($user), $arAllowableUserGroups)) !== false)
                {
                    
$bCorrectUser true;
                    
$arResult[] = $k1;
                }
                elseif (
preg_match('#\[([A-Z]{1,}[0-9A-Z_]+)\]#i'$user$arMatches))
                {
                    
$bCorrectUser true;
                    
$arResult[] = "group_".strtolower($arMatches[1]);
                }
                else
                {
                    
$ar self::SearchUserByName($user);
                    
$cnt count($ar);
                    if (
$cnt == 1)
                    {
                        
$bCorrectUser true;
                        
$arResult[] = "user_".$ar[0];
                    }
                    elseif (
$cnt 1)
                    {
                        
$bNotFoundUser false;
                        
$arErrors[] = array(
                            
"code" => "Ambiguous",
                            
"message" => str_replace("#USER#"htmlspecialcharsbx($user), GetMessage("BPCGHLP_AMBIGUOUS_USER")),
                        );
                    }
                    elseif (
$callbackFunction != null)
                    {
                        
$s call_user_func_array($callbackFunction, array($user));
                        if (
$s != null)
                        {
                            
$arResultAlt[] = $s;
                            
$bCorrectUser true;
                        }
                    }
                }
            }

            if (!
$bCorrectUser)
            {
                if (
$bNotFoundUser)
                {
                    
$arErrors[] = array(
                        
"code" => "NotFound",
                        
"message" => str_replace("#USER#"htmlspecialcharsbx($user), GetMessage("BPCGHLP_INVALID_USER")),
                    );
                }
            }
        }

        return (
$callbackFunction != null) ? array($arResult$arResultAlt) : $arResult;
    }