- Модуль: socialnetwork
- Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/group.php
- Класс: CAllSocNetGroup
- Вызов: CAllSocNetGroup::createGroup
static function createGroup($ownerID, $arFields, $bAutoSubscribe = true)
{
global $APPLICATION, $DB;
$ownerID = (int)$ownerID;
if ($ownerID <= 0)
{
$APPLICATION->ThrowException(GetMessage("SONET_UR_EMPTY_OWNERID").". ", "ERROR_OWNERID");
return false;
}
if (!isset($arFields) || !is_array($arFields))
{
$APPLICATION->ThrowException(GetMessage("SONET_UR_EMPTY_FIELDS").". ", "ERROR_FIELDS");
return false;
}
if (!empty($arFields['SCRUM_MASTER_ID']) && CModule::includeModule("tasks"))
{
if (ScrumLimit::isLimitExceeded())
{
$APPLICATION->ThrowException("Scrum limit exceeded");
return false;
}
}
$DB->StartTransaction();
if (!isset($arFields["DATE_CREATE"]))
{
$arFields["=DATE_CREATE"] = CDatabase::currentTimeFunction();
}
if (!isset($arFields["DATE_UPDATE"]))
{
$arFields["=DATE_UPDATE"] = CDatabase::currentTimeFunction();
}
if (!isset($arFields["DATE_ACTIVITY"]))
{
$arFields["=DATE_ACTIVITY"] = CDatabase::currentTimeFunction();
}
$arFields["ACTIVE"] = "Y";
$arFields["OWNER_ID"] = $ownerID;
if (!is_set($arFields, "SPAM_PERMS") || $arFields["SPAM_PERMS"] == '')
{
$arFields["SPAM_PERMS"] = SONET_ROLES_OWNER;
}
$groupID = CSocNetGroup::add($arFields);
if (
!$groupID
|| $groupID <= 0
)
{
$errorMessage = $errorID = "";
if ($e = $APPLICATION->getException())
{
$errorMessage = $e->GetString();
$errorID = $e->GetID();
if (
$errorID == ''
&& isset($e->messages)
&& is_array($e->messages)
&& is_array($e->messages[0])
&& array_key_exists("id", $e->messages[0])
)
{
$errorID = $e->messages[0]["id"];
}
}
if ($errorMessage == '')
{
$errorMessage = GetMessage("SONET_UR_ERROR_CREATE_GROUP").". ";
}
if ($errorID == '')
{
$errorID = "ERROR_CREATE_GROUP";
}
$APPLICATION->ThrowException($errorMessage, $errorID);
$DB->Rollback();
return false;
}
$arFields1 = array(
"USER_ID" => $ownerID,
"GROUP_ID" => $groupID,
"ROLE" => SONET_ROLES_OWNER,
"=DATE_CREATE" => $DB->CurrentTimeFunction(),
"=DATE_UPDATE" => $DB->CurrentTimeFunction(),
"INITIATED_BY_TYPE" => SONET_INITIATED_BY_USER,
"INITIATED_BY_USER_ID" => $ownerID,
"MESSAGE" => false
);
if (!CSocNetUserToGroup::Add($arFields1))
{
$errorMessage = "";
if ($e = $APPLICATION->GetException())
{
$errorMessage = $e->GetString();
}
if ($errorMessage == '')
{
$errorMessage = GetMessage("SONET_UR_ERROR_CREATE_U_GROUP").". ";
}
$APPLICATION->ThrowException($errorMessage, "ERROR_CREATE_GROUP");
$DB->Rollback();
return false;
}
if ($bAutoSubscribe)
{
CSocNetLogEvents::AutoSubscribe($ownerID, SONET_ENTITY_GROUP, $groupID);
}
CSocNetSubscription::Set($ownerID, "SG".$groupID, "Y");
$DB->Commit();
return $groupID;
}