- Модуль: landing
- Путь к файлу: ~/bitrix/modules/landing/lib/restriction/site.php
- Класс: BitrixLandingRestrictionSite
- Вызов: Site::checkLimitByTemplates
static function checkLimitByTemplates(array $filter, int $limit): bool
{
$sites = [];
$currentSiteId = null;
$currentSiteTemplate = null;
if (isset($filter['!ID']))
{
$currentSiteId = $filter['!ID'];
}
// get all sites (active) and group by templates
$res = BitrixLandingSite::getList([
'select' => [
'ID', 'XML_ID', 'TPL_CODE'
],
'filter' => $filter
]);
while ($row = $res->fetch())
{
$sites[] = $row;
}
// current site
if ($currentSiteId)
{
$res = BitrixLandingSite::getList([
'select' => [
'ID', 'XML_ID', 'TPL_CODE'
],
'filter' => [
'CHECK_PERMISSIONS' => 'N',
'ID' => $currentSiteId
]
]);
if ($row = $res->fetch())
{
$sites[] = $row;
}
}
// calc templates
$templates = [];
$templatesCount = 0;
$templatesLimits = self::LIMIT_BY_TEMPLATES_MINIMAL;
// $templatesLimits['%'] = max($limit, 1);
$limit = max($limit, 1);
foreach ($sites as $row)
{
if (!$row['TPL_CODE'])
{
if (mb_strpos($row['XML_ID'], '|') !== false)
{
[, $row['TPL_CODE']] = explode('|', $row['XML_ID']);
}
}
// store-chat-dark === store-chat-light === store-chat
foreach ($templatesLimits as $code => $cnt)
{
if (strpos($row['TPL_CODE'], $code) === 0)
{
$row['TPL_CODE'] = $code;
break;
}
}
if ($currentSiteId && $currentSiteId === $row['ID'])
{
$currentSiteTemplate = $row['TPL_CODE'];
}
if (!($templates[$row['TPL_CODE']] ?? null))
{
$templates[$row['TPL_CODE']] = 0;
}
$templates[$row['TPL_CODE']]++;
if (!in_array($row['TPL_CODE'], self::OVER_LIMIT_TEMPLATES, true))
{
$templatesCount++;
}
}
// special limit for store v3
if (
$currentSiteTemplate
&& $currentSiteTemplate === self::NEW_STORE_CODE
&& self::isNew2021Tariff()
)
{
CBitrixComponent::includeComponentClass('bitrix:landing.site_master');
$optionName = LandingSiteMasterComponent::getShopInstallCountOptionName($currentSiteTemplate);
if ((int)Manager::getOption($optionName, 0) <= 1)
{
$limit++;
}
}
// calc limits
if (
$currentSiteTemplate
&& in_array($row['TPL_CODE'], self::OVER_LIMIT_TEMPLATES, true)
)
{
return true;
}
if ($templates)
{
foreach ($templatesLimits as $code => $templateLimit)
{
if (
$templates[$code]
&& $templates[$code] > $templateLimit
)
{
return false;
}
}
}
if ($limit < $templatesCount)
{
return false;
}
return true;
}