Documentation

CreateGroup

int
CSocNetGroup::CreateGroup(
 int ownerID,
 array arFields,
 bool bAutoSubscribe = true
);

The static method creates new workgroup. Define user access permissions to create a group (Parameters INITIATE_PERMS and SPAM_PERMS). Use constants are most suitable (see array keys); however, symbols can be used as well:

  • A (Only group owner),
  • E (Group owner and group moderator),
  • K (All group members).

Note: when method is executed, the events are called: [link=191850]OnBeforeSocNetGroupAdd[/link] and [link=191906]OnSocNetGroupAdd[/link].

Parameters

Parameter Description Available from version
ownerID User ID - owner of the new workgroup.
arFields Parameter array for the new group. Available array keys:
SITE_ID - site ID (required field),
NAME - group name (required field),
DESCRIPTION - group description,
VISIBLE - Y/N flag - group visibility in the group list,
OPENED - Y/N flag- is the group open for users to join freely,
SUBJECT_ID - topic ID (required field),
KEYWORDS - keywords,
IMAGE_ID - group icon,
INITIATE_PERMS - who has permissions to invite users to the workgroup (required field): SONET_ROLES_OWNER - only the group owner, SONET_ROLES_MODERATOR - group owner and group moderators, SONET_ROLES_USER - all group members,
CLOSED - Y/N flag - archive group status,
SPAM_PERMS - who has permissions to end messages to the group (required field): SONET_ROLES_OWNER - only the group owner, SONET_ROLES_MODERATOR - group owner and group moderators, SONET_ROLES_USER - all group members, SONET_ROLES_ALL - all users.
PROJECT Y/N. Is the group a project or not. Default value - group is not a project. (From version 18.0.0)
PROJECT_DATE_FINISH Project finish date is set. (From version 18.0.0)
PROJECT_DATE_START Project start date is set. (From version 18.0.0)
bAutoSubscribe Autosubscription to the created topic. Optional parameter. Default value is true.

Returned value

The method returns ID of the newly created group or returns false otherwise.

Examples

<?
$arImageID = $GLOBALS["HTTP_POST_FILES"]["GROUP_IMAGE_ID"];
if (StrLen($arImageID["tmp_name"]) > 0)
	CFile::ResizeImage($arImageID, array("width" => 300, "height" => 300), BX_RESIZE_IMAGE_PROPORTIONAL);

$arFields = array(
	"SITE_ID" => SITE_ID,
	"NAME" => $_POST["GROUP_NAME"],
	"DESCRIPTION" => $_POST["GROUP_DESCRIPTION"],
	"VISIBLE" => ($_POST["GROUP_VISIBLE"] == "Y" ? "Y" : "N"),
	"OPENED" => ($_POST["GROUP_OPENED"] == "Y" ? "Y" : "N"),
	"CLOSED" => ($_POST["GROUP_CLOSED"] == "Y" ? "Y" : "N"),
	"SUBJECT_ID" => $_POST["GROUP_SUBJECT_ID"],
	"KEYWORDS" => $_POST["GROUP_KEYWORDS"],
	"IMAGE_ID" => $arImageID,
	"INITIATE_PERMS" => $_POST["GROUP_INITIATE_PERMS"],
	"SPAM_PERMS" => $_POST["GROUP_SPAM_PERMS"],
);

$groupId = CSocNetGroup::CreateGroup($GLOBALS["USER"]->GetID(), $arFields);
if (!$groupId)
{
	if ($e = $GLOBALS["APPLICATION"]->GetException())
		$errorMessage .= $e->GetString();
}
?>


© «Bitrix24», 2001-2022
Up