Documentation

AddToUserGroup

bool
CBlogUser::AddToUserGroup(
 int    ID,
 int    blogID,
 array  arGroups = array(),
 string joinStatus = "Y",
 int    selectType = BLOG_BY_BLOG_USER_ID,
 int    action = BLOG_CHANGE
);

Adds a user with ID to arGroups user groups for the blog with blogID. Static method.

Method parameters

ParameterDescription
ID User ID.
blogID Blog ID.
arGroups Array of IDs for blog user groups, to which the user must be associated with. Optional.
joinStatus Optional. By default - "Y". This parameter temporarily is not used.
selectType Specified bu which ID the user must be searched. Possible values:
  • BLOG_BY_USER_ID - by the site user ID;
  • BLOG_BY_BLOG_USER_ID - by the blog user ID.
Необязательный. По умолчанию BLOG_BY_BLOG_USER_ID - by the blog user ID.
action Performed action. Possible values:
  • BLOG_ADD - adding user to a group;
  • BLOG_CHANGE - modifying already existing associations.
Optional. By default, BLOG_CHANGE - changing the already existing associations.

Returned values

The method returns true on success, otherwise returns false, and exceptions will contain errors.

Examples of use

<?
// add the current user into the groups with ID = 1, 2, 3 of the blog users with ID = 1
$ID = $USER->GetID();
if(!CBlogUser::AddToUserGroup($ID, 1, array(1,2,3), "", BLOG_BY_USER_ID, BLOG_ADD))
{
    if ($ex = $APPLICATION->GetException())
        echo $ex->GetString();
}
else
{
    echo 'User ['.$ID.'] is added to the blog user groups';
}
?>


© «Bitrix24», 2001-2024