Helper::prepareUserSelectorEntities: Bitrix method

      
<?php 
//  Bitrix\Bizproc\Automation\Helper :: prepareUserSelectorEntities()
//  /dist/bitrix/modules/bizproc/lib/automation/helper.php:16

    
public static function prepareUserSelectorEntities(array $documentType$users$config = []): array
    {
        
$result = [];
        
$users = (array)$users;
        
$documentUserFields = static::getDocumentFields($documentType'user');
        
$documentUserGroups self::getDocumentUserGroups($documentType);

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

            if (
substr($user05) === "user_")
            {
                
$user intval(substr($user5));
                if ((
$user 0) && !in_array($user$result))
                {
                    
$userInfo self::getUserInfo($user);
                    
$result[] = [
                        
'id'         => 'U'.$user,
                        
'entityId'   => $user,
                        
'name'       => htmlspecialcharsBx($userInfo['fullName']),
                        
'photoSrc'       => $userInfo['photoSrc'],
                        
'url'       => $userInfo['url'],
                        
'entityType' => 'users',
                    ];
                }
            }
            elseif (
$user === 'author' &&
                (
                    isset(
$documentUserFields['ASSIGNED_BY_ID']) ||
                    isset(
$documentUserFields['RESPONSIBLE_ID'])
                )
            )
            {
                
$responsibleKey = isset($documentUserFields['ASSIGNED_BY_ID']) ? 'ASSIGNED_BY_ID' 'RESPONSIBLE_ID';

                
$result[] = array(
                    
'id'         => $documentUserFields[$responsibleKey]['Expression'],
                    
'entityId'   => $documentUserFields[$responsibleKey]['Expression'],
                    
'name'       => htmlspecialcharsBx($documentUserFields[$responsibleKey]['Name']),
                    
'entityType' => 'bpuserroles'
                
);
            }
            elseif (isset(
$documentUserGroups[$user]))
            {
                
$result[] = array(
                    
'id'         => $user,
                    
'entityId'   => $user,
                    
'name'       => htmlspecialcharsBx($documentUserGroups[$user]),
                    
'entityType' => 'bpuserroles'
                
);
            }
            else
            {
                
$found false;
                foreach (
$documentUserFields as $field)
                {
                    if (
$user === $field['Expression'] || $user === $field['SystemExpression'])
                    {
                        
$result[] = array(
                            
'id'       => $field['Expression'],
                            
'entityId' => $field['Expression'],
                            
'name'     => htmlspecialcharsBx($field['Name']),
                            
'entityType' => 'bpuserroles'
                        
);
                        
$found true;
                    }
                }

                if (!
$found && isset($config['additionalFields']))
                {
                    foreach (
$config['additionalFields'] as $field)
                    {
                        if (
$user === $field['entityId'])
                        {
                            
$result[] = array(
                                
'id'       => $field['id'],
                                
'entityId' => $field['entityId'],
                                
'name'     => htmlspecialcharsBx($field['name']),
                                
'entityType' => 'bpuserroles'
                            
);
                        }
                    }
                }
            }
        }
        return 
$result;
    }