• Модуль: landing
  • Путь к файлу: ~/bitrix/modules/landing/lib/restriction/site.php
  • Класс: BitrixLandingRestrictionSite
  • Вызов: Site::isCreatingAllowed
static function isCreatingAllowed(string $code, array $params): bool
{
	if (!Loader::includeModule('bitrix24'))
	{
		return true;
	}

	if (
		$params['action_type'] === 'publication'
		&& Manager::licenseIsFreeSite($params['type'])
		&& !Manager::isFreePublicAllowed()
	)
	{
		if (!isset($params['filter']['!ID']))
		{
			return false;
		}

		$siteId = $params['filter']['!ID'];
		$site = SiteCore::getList([
			'select' => ['ID' , 'DATE_CREATE'],
			'filter' => ['ID' => $siteId],
		])->fetch();
		$dateWhenClosedFree = DateTime::createFromTimestamp('1646238000');  //02.03.2022 16:20:00
		if ($site['DATE_CREATE']->getTimestamp() >= $dateWhenClosedFree->getTimestamp())
		{
			return false;
		}
	}

	$optPrefix = 'landing_site_';
	$optSuffix = ($params['action_type'] == 'publication') ? '_publication' : '';
	$variableCode = $optPrefix . strtolower($params['type']) . $optSuffix;
	$limit = (int) Feature::getVariable($variableCode);

	if ($limit)
	{
		$filter = [
			'CHECK_PERMISSIONS' => 'N',
			'=TYPE' => $params['type'],
			'=SPECIAL' => 'N'
		];

		if ($params['action_type'] == 'publication')
		{
			$filter['=ACTIVE'] = 'Y';
		}

		if (
			isset($params['filter']) &&
			is_array($params['filter'])
		)
		{
			$filter = array_merge(
				$filter,
				$params['filter']
			);
		}

		if ($params['action_type'] === 'publication' && $params['type'] === 'STORE')
		{
			return self::checkLimitByTemplates($filter, $limit);
		}

		$check = SiteCore::getList([
			'select' => [
				'CNT' => new EntityExpressionField('CNT', 'COUNT(*)')
			],
			'filter' => $filter,
			'group' => []
		])->fetch();
		if ($check && $check['CNT'] >= $limit)
		{
			return false;
		}
	}

	return true;
}