CBlogPost :: SetPostPerms: Bitrix method

      
<?php 
//  CBlogPost :: SetPostPerms()
//  /dist/bitrix/modules/blog/general/blog_post.php:326

    
function SetPostPerms($ID$arPerms = array(), $permsType BLOG_PERMS_POST)
    {
        global 
$DB;

        
$ID IntVal($ID);
        
$permsType = (($permsType == BLOG_PERMS_COMMENT) ? BLOG_PERMS_COMMENT BLOG_PERMS_POST);
        if(!
is_array($arPerms))
            
$arPerms = array();

        
$arPost CBlogPost::GetByID($ID);
        if (
$arPost)
        {
            
$arInsertedGroups = array();
            foreach (
$arPerms as $key => $value)
            {
                
$dbGroupPerms CBlogUserGroupPerms::GetList(
                    array(),
                    array(
                        
"BLOG_ID" => $arPost["BLOG_ID"],
                        
"USER_GROUP_ID" => $key,
                        
"PERMS_TYPE" => $permsType,
                        
"POST_ID" => $arPost["ID"]
                    ),
                    
false,
                    
false,
                    array(
"ID")
                );
                if (
$arGroupPerms $dbGroupPerms->Fetch())
                {
                    
CBlogUserGroupPerms::Update(
                        
$arGroupPerms["ID"],
                        array(
                            
"PERMS" => $value,
                            
"AUTOSET" => "N"
                        
)
                    );
                }
                else
                {
                    
CBlogUserGroupPerms::Add(
                        array(
                            
"BLOG_ID" => $arPost["BLOG_ID"],
                            
"USER_GROUP_ID" => $key,
                            
"PERMS_TYPE" => $permsType,
                            
"POST_ID" => $arPost["ID"],
                            
"AUTOSET" => "N",
                            
"PERMS" => $value
                        
)
                    );
                }

                
$arInsertedGroups[] = $key;
            }

            
$dbResult CBlogUserGroupPerms::GetList(
                array(),
                array(
                    
"BLOG_ID" => $arPost["BLOG_ID"],
                    
"PERMS_TYPE" => $permsType,
                    
"POST_ID" => 0,
                    
"!USER_GROUP_ID" => $arInsertedGroups
                
),
                
false,
                
false,
                array(
"ID""USER_GROUP_ID""PERMS")
            );
            while (
$arResult $dbResult->Fetch())
            {
                
$dbGroupPerms CBlogUserGroupPerms::GetList(
                    array(),
                    array(
                        
"BLOG_ID" => $arPost["BLOG_ID"],
                        
"USER_GROUP_ID" => $arResult["USER_GROUP_ID"],
                        
"PERMS_TYPE" => $permsType,
                        
"POST_ID" => $arPost["ID"]
                    ),
                    
false,
                    
false,
                    array(
"ID")
                );
                if (
$arGroupPerms $dbGroupPerms->Fetch())
                {
                    
CBlogUserGroupPerms::Update(
                        
$arGroupPerms["ID"],
                        array(
                            
"PERMS" => $arResult["PERMS"],
                            
"AUTOSET" => "Y"
                        
)
                    );
                }
                else
                {
                    
CBlogUserGroupPerms::Add(
                        array(
                            
"BLOG_ID" => $arPost["BLOG_ID"],
                            
"USER_GROUP_ID" => $arResult["USER_GROUP_ID"],
                            
"PERMS_TYPE" => $permsType,
                            
"POST_ID" => $arPost["ID"],
                            
"AUTOSET" => "Y",
                            
"PERMS" => $arResult["PERMS"]
                        )
                    );
                }
            }
        }
    }