CBPAllStateService::SetStatePermissions: Bitrix method

      
<?php 
//  CBPAllStateService :: SetStatePermissions()
//  /dist/bitrix/modules/bizproc/classes/general/stateservice.php:28

    
public function SetStatePermissions($workflowId$arStatePermissions = array(), $bRewrite true)
    {
        global 
$DB;

        
$workflowId trim($workflowId);
        if (
strlen($workflowId) <= 0)
            throw new 
Exception("workflowId");

        
// @TODO: add new logic to CBPSetPermissionsMode::Rewrite
        
if (!is_array($bRewrite) && $bRewrite == true
            
|| is_array($bRewrite) && isset($bRewrite['setMode']) && $bRewrite['setMode'] == CBPSetPermissionsMode::Clear)
        {
            
$DB->Query(
                
"DELETE FROM b_bp_workflow_permissions ".
                
"WHERE WORKFLOW_ID = '".$DB->ForSql($workflowId)."' "
            
);
        }
        
$arState self::GetWorkflowState($workflowId);
        
$documentService $this->runtime->GetService("DocumentService");
        
$documentService->SetPermissions($arState["DOCUMENT_ID"], $workflowId$arStatePermissions$bRewrite);
        
$documentType $documentService->GetDocumentType($arState["DOCUMENT_ID"]);
        if (
$documentType)
            
$arStatePermissions $documentService->toInternalOperations($documentType$arStatePermissions);

        foreach (
$arStatePermissions as $permission => $arObjects)
        {
            foreach (
$arObjects as $object)
            {
                
$DB->Query(
                    
"INSERT INTO b_bp_workflow_permissions (WORKFLOW_ID, OBJECT_ID, PERMISSION) ".
                    
"VALUES ('".$DB->ForSql($workflowId)."', '".$DB->ForSql($object)."', '".$DB->ForSql($permission)."')"
                
);
            }
        }
    }