- Модуль: socialnetwork
- Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/group_features.php
- Класс: CAllSocNetFeatures
- Вызов: CAllSocNetFeatures::SetFeature
static function SetFeature($type, $id, $feature, $active, $featureName = false)
{
global $arSocNetAllowedEntityTypes, $APPLICATION, $CACHE_MANAGER;
$type = Trim($type);
if (($type == '') || !in_array($type, $arSocNetAllowedEntityTypes))
{
$APPLICATION->ThrowException(GetMessage("SONET_GF_ERROR_NO_ENTITY_TYPE"), "ERROR_EMPTY_TYPE");
return false;
}
$id = intval($id);
if ($id <= 0)
{
$APPLICATION->ThrowException(GetMessage("SONET_GF_EMPTY_ENTITY_ID"), "ERROR_EMPTY_ENTITY_ID");
return false;
}
$feature = mb_strtolower(Trim($feature));
if ($feature == '')
{
$APPLICATION->ThrowException(GetMessage("SONET_GF_EMPTY_FEATURE_ID"), "ERROR_EMPTY_FEATURE_ID");
return false;
}
$arSocNetFeaturesSettings = CSocNetAllowed::GetAllowedFeatures();
if (
!array_key_exists($feature, $arSocNetFeaturesSettings)
|| !in_array($type, $arSocNetFeaturesSettings[$feature]["allowed"])
)
{
$APPLICATION->ThrowException(GetMessage("SONET_GF_ERROR_NO_FEATURE_ID"), "ERROR_NO_FEATURE_ID");
return false;
}
$active = ($active ? "Y" : "N");
$dbResult = CSocNetFeatures::GetList(
array(),
array(
"ENTITY_TYPE" => $type,
"ENTITY_ID" => $id,
"FEATURE" => $feature
),
false,
false,
array("ID", "ACTIVE")
);
if ($arResult = $dbResult->Fetch())
{
$r = CSocNetFeatures::Update(
$arResult["ID"],
array(
"FEATURE_NAME" => $featureName,
"ACTIVE" => $active,
"=DATE_UPDATE" => CDatabase::CurrentTimeFunction()
)
);
if ($r)
{
$CACHE_MANAGER->clearByTag("sonet_feature_all_".$type."_".$feature);
}
}
else
{
$r = CSocNetFeatures::Add(array(
"ENTITY_TYPE" => $type,
"ENTITY_ID" => $id,
"FEATURE" => $feature,
"FEATURE_NAME" => $featureName,
"ACTIVE" => $active,
"=DATE_UPDATE" => CDatabase::CurrentTimeFunction(),
"=DATE_CREATE" => CDatabase::CurrentTimeFunction()
));
}
if ($feature === 'chat')
{
$chatData = IntegrationImChatWorkgroup::getChatData(Array(
'group_id' => $id,
'skipAvailabilityCheck' => true
));
if (
$active === 'Y'
&& (
empty($chatData[$id])
|| (int)$chatData[$id] <= 0
)
)
{
IntegrationImChatWorkgroup::createChat(Array(
'group_id' => $id
));
}
elseif (
$active === 'N'
&& !empty($chatData[$id])
&& (int)$chatData[$id] > 0
)
{
BitrixSocialnetworkIntegrationImChatWorkgroup::unlinkChat(array(
'group_id' => $id
));
}
}
if (!$r)
{
$errorMessage = "";
if ($e = $APPLICATION->GetException())
$errorMessage = $e->GetString();
if ($errorMessage == '')
$errorMessage = GetMessage("SONET_GF_ERROR_SET").".";
$APPLICATION->ThrowException($errorMessage, "ERROR_SET_RECORD");
return false;
}
return $r;
}