- Модуль: socialnetwork
- Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/group_features.php
- Класс: CAllSocNetFeatures
- Вызов: CAllSocNetFeatures::IsActiveFeature
static function IsActiveFeature($type, $id, $feature)
{
global $arSocNetAllowedEntityTypes, $APPLICATION;
$arReturn = [];
$type = trim($type);
if (
$type == ''
|| !in_array($type, $arSocNetAllowedEntityTypes)
)
{
$APPLICATION->ThrowException(GetMessage("SONET_GF_ERROR_NO_ENTITY_TYPE"), "ERROR_EMPTY_TYPE");
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 (
!isset($arSocNetFeaturesSettings[$feature]['allowed'])
|| !in_array($type, $arSocNetFeaturesSettings[$feature]['allowed'], true)
)
{
$APPLICATION->ThrowException(GetMessage("SONET_GF_ERROR_NO_FEATURE_ID"), "ERROR_NO_FEATURE_ID");
return false;
}
$arFeatures = [];
if (is_array($id))
{
$arGroupToGet = array();
foreach($id as $group_id)
{
if ($group_id <= 0)
{
$arReturn[$group_id] = false;
}
elseif (
isset($GLOBALS['SONET_FEATURES_CACHE'][$type][$group_id])
&& is_array($GLOBALS['SONET_FEATURES_CACHE'][$type][$group_id])
)
{
$arFeatures[$group_id] = $GLOBALS["SONET_FEATURES_CACHE"][$type][$group_id];
if (!array_key_exists($feature, $arFeatures[$group_id]))
{
$arReturn[$group_id] = true;
continue;
}
$arReturn[$group_id] = ($arFeatures[$group_id][$feature]['ACTIVE'] === "Y");
}
else
{
$arGroupToGet[] = $group_id;
}
}
if (!empty($arGroupToGet))
{
$res = CSocNetFeatures::getList(
[],
[
'@ENTITY_ID' => $arGroupToGet,
'ENTITY_TYPE' => $type,
],
false,
false,
[ 'ENTITY_ID', 'FEATURE', 'ACTIVE', 'FEATURE_NAME' ]
);
while ($featureFields = $res->getNext(true, false))
{
$arFeatures[$featureFields['ENTITY_ID']][$featureFields['FEATURE']] = [
'ACTIVE' => $featureFields['ACTIVE'],
'FEATURE_NAME' => $featureFields['FEATURE_NAME'],
];
}
foreach ($arGroupToGet as $group_id)
{
if (
!isset($GLOBALS['SONET_FEATURES_CACHE'])
|| !is_array($GLOBALS['SONET_FEATURES_CACHE'])
)
{
$GLOBALS['SONET_FEATURES_CACHE'] = [];
}
if (
!isset($GLOBALS['SONET_FEATURES_CACHE'][$type])
|| !is_array($GLOBALS['SONET_FEATURES_CACHE'][$type])
)
{
$GLOBALS['SONET_FEATURES_CACHE'][$type] = [];
}
if (!isset($arFeatures[$group_id]))
{
$arFeatures[$group_id] = Array();
}
$GLOBALS["SONET_FEATURES_CACHE"][$type][$group_id] = $arFeatures[$group_id];
if (!array_key_exists($feature, $arFeatures[$group_id]))
{
$arReturn[$group_id] = true;
continue;
}
$arReturn[$group_id] = ($arFeatures[$group_id][$feature]["ACTIVE"] === "Y");
}
}
return $arReturn;
}
// not array
$id = (int)$id;
if ($id <= 0)
{
$APPLICATION->ThrowException(GetMessage("SONET_GF_EMPTY_ENTITY_ID"), "ERROR_EMPTY_ENTITY_ID");
return false;
}
if (
isset($GLOBALS['SONET_FEATURES_CACHE'][$type][$id])
&& is_array($GLOBALS['SONET_FEATURES_CACHE'][$type][$id])
)
{
$arFeatures = $GLOBALS["SONET_FEATURES_CACHE"][$type][$id];
}
else
{
$res = CSocNetFeatures::getList(
[],
[
'ENTITY_ID' => $id,
'ENTITY_TYPE' => $type,
],
false,
false,
[ 'FEATURE', 'ACTIVE', 'FEATURE_NAME' ]
);
while ($featureFields = $res->getNext())
{
$arFeatures[$featureFields['FEATURE']] = [
'ACTIVE' => $featureFields['ACTIVE'],
'FEATURE_NAME' => $featureFields['FEATURE_NAME'],
];
}
if (
!isset($GLOBALS['SONET_FEATURES_CACHE'])
|| !is_array($GLOBALS['SONET_FEATURES_CACHE'])
)
{
$GLOBALS['SONET_FEATURES_CACHE'] = [];
}
if (
!isset($GLOBALS['SONET_FEATURES_CACHE'][$type])
|| !is_array($GLOBALS['SONET_FEATURES_CACHE'][$type])
)
{
$GLOBALS["SONET_FEATURES_CACHE"][$type] = [];
}
$GLOBALS['SONET_FEATURES_CACHE'][$type][$id] = $arFeatures;
}
if (!array_key_exists($feature, $arFeatures))
{
return true;
}
return ($arFeatures[$feature]['ACTIVE'] === 'Y');
}