CBPHelper :: ExtractUsers: Bitrix method

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

    
public static function ExtractUsers($arUsersDraft$documentId$bFirst false)
    {
        
$result = [];

        if (!
is_array($arUsersDraft))
        {
            
$arUsersDraft = array($arUsersDraft);
        }

        
$l strlen("user_");
        
$documentService CBPRuntime::GetRuntime(true)->getDocumentService();

        foreach (
$arUsersDraft as $user)
        {
            if (!
is_scalar($user))
            {
                continue;
            }

            if (
substr($user0$l) === "user_")
            {
                
$user intval(substr($user$l));
                if ((
$user 0) && !in_array($user$result))
                {
                    if (
$bFirst)
                    {
                        return 
$user;
                    }
                    
$result[] = $user;
                }
            }
            elseif (\
CBPActivity::isExpression($user))
            {
                
$parsed = \CBPActivity::parseExpression($user);
                if (
$parsed && $parsed['object'] === 'Document')
                {
                    
$document $documentService->GetDocument($documentId);
                    if (
$document && $document[$parsed['field']])
                    {
                        foreach ((array) 
$document[$parsed['field']] as $docUser)
                        {
                            if (
substr($docUser0$l) === "user_")
                            {
                                
$user intval(substr($docUser$l));
                                if ((
$user 0) && !in_array($user$result))
                                {
                                    if (
$bFirst)
                                    {
                                        return 
$user;
                                    }
                                    
$result[] = $user;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                
$users self::extractUsersFromExtendedGroup($user);
                if (
$users === false)
                {
                    
$users $documentService->GetUsersFromUserGroup($user$documentId);
                }
                foreach (
$users as $u)
                {
                    
$u = (int)$u;
                    if ((
$u 0) && !in_array($u$result))
                    {
                        if (
$bFirst)
                        {
                            return 
$u;
                        }
                        
$result[] = $u;
                    }
                }
            }
        }

        if (!
$bFirst)
        {
            return 
$result;
        }

        if (
count($result) > 0)
        {
            return 
$result[0];
        }

        return 
null;
    }