- Модуль: socialnetwork
- Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/event_user_view.php
- Класс: CAllSocNetEventUserView
- Вызов: CAllSocNetEventUserView::SetGroup
static function SetGroup($entityID, $bSetFeatures = false)
{
global $APPLICATION, $DB;
$entityID = intval($entityID);
if ($entityID <= 0)
{
$GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_EUV_EMPTY_ENTITY_ID"), "ERROR_EMPTY_ENTITY_ID");
return false;
}
$arGroup = CSocNetGroup::GetByID($entityID);
if (!$arGroup)
{
$GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_EUV_NO_ENTITY"), "SONET_EUV_NO_ENTITY");
return false;
}
$arLogEvent = array();
$arSocNetLogEvents = CSocNetAllowed::GetAllowedLogEvents();
foreach ($arSocNetLogEvents as $event_tmp_id => $arLogEventTmp)
{
if (
!array_key_exists("ENTITIES", $arLogEventTmp)
|| !array_key_exists(SONET_SUBSCRIBE_ENTITY_GROUP, $arLogEventTmp["ENTITIES"])
)
continue;
if (
array_key_exists("NO_SET", $arLogEventTmp)
&& $arLogEventTmp["NO_SET"]
)
continue;
$arLogEvent[] = $event_tmp_id;
if (
array_key_exists("COMMENT_EVENT", $arLogEventTmp)
&& is_array($arLogEventTmp["COMMENT_EVENT"])
&& array_key_exists("EVENT_ID", $arLogEventTmp["COMMENT_EVENT"])
&& $arLogEventTmp["COMMENT_EVENT"]["EVENT_ID"] <> ''
)
$arLogEvent[] = $arLogEventTmp["COMMENT_EVENT"]["EVENT_ID"];
}
$arLogEvent = array_unique($arLogEvent);
foreach ($arLogEvent as $event_tmp_id)
{
if (!CSocNetEventUserView::Delete(SONET_ENTITY_GROUP, $entityID, $event_tmp_id))
{
$GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_EUV_ERROR_DELETE"), "ERROR_DELETE");
return false;
}
}
$dbResult = CSocNetUserToGroup::GetList(
array(),
array(
"GROUP_ID" => $entityID,
"<=ROLE" => SONET_ROLES_USER,
"USER_ACTIVE" => "Y"
),
false,
false,
array("USER_ID")
);
while ($arResult = $dbResult->Fetch())
{
foreach ($arLogEvent as $event_tmp_id)
{
$arFields = array(
"ENTITY_TYPE" => SONET_ENTITY_GROUP,
"ENTITY_ID" => $entityID,
"EVENT_ID" => $event_tmp_id,
"USER_ID" => $arResult["USER_ID"],
"USER_ANONYMOUS" => "N"
);
if (!CSocNetEventUserView::Add($arFields))
{
$errorMessage = "";
if ($e = $APPLICATION->GetException())
$errorMessage = $e->GetString();
if ($errorMessage == '')
$errorMessage = GetMessage("SONET_EUV_ERROR_SET");
$APPLICATION->ThrowException($errorMessage, "ERROR_SET");
return false;
}
}
}
if ($bSetFeatures)
{
$arActiveFeatures = array_keys(CSocNetFeatures::GetActiveFeaturesNames(SONET_ENTITY_GROUP, $entityID));
foreach ($arActiveFeatures as $feature)
{
CSocNetEventUserView::SetFeature(SONET_ENTITY_GROUP, $entityID, $feature);
}
}
return true;
}