67 if (!static::isActiveRules())
72 if (!array_key_exists($app, static::$availableApp))
74 static::$availableApp[$app] =
false;
75 if (Client::isSubscriptionAvailable())
77 static::$availableApp[$app] =
true;
79 elseif (static::isFeatureEnabled())
81 static::$availableApp[$app] =
true;
85 if (in_array($app, Immune::getList(),
true))
87 static::$availableApp[$app] =
true;
91 $appInfo = AppTable::getByClientId($app);
92 if ($appInfo[
'CODE'] && in_array($appInfo[
'CODE'], Immune::getList(),
true))
94 static::$availableApp[$app] =
true;
100 return static::$availableApp[$app];
112 if (!static::isActiveRules())
117 $key = $entityType . $entity;
118 if (!array_key_exists($key, static::$availableAppCount))
120 static::$availableAppCount[$key] =
true;
121 if ($entityType === static::ENTITY_TYPE_APP)
123 $maxCount = static::getAvailableCount();
126 $appInfo = AppTable::getByClientId($entity);
127 if (!isset($appInfo[
'STATUS']) || $appInfo[
'STATUS'] !== AppTable::STATUS_LOCAL)
129 if (isset($appInfo[
'CODE']) && $appInfo[
'CODE'])
131 $entity = $appInfo[
'CODE'];
134 $entityList = static::getActiveEntity(
true);
135 if ($entityList[static::ENTITY_COUNT] > $maxCount)
137 static::$availableAppCount[$key] =
false;
140 $entityList[static::ENTITY_COUNT] === $maxCount
141 && !in_array($entity, $entityList[$entityType],
true)
144 static::$availableAppCount[$key] =
false;
148 static::$availableAppCount[$key] ===
false
150 in_array($entity, Immune::getList(),
true)
152 !static::needCheckCount()
153 && in_array($entity, $entityList[$entityType],
true)
158 static::$availableAppCount[$key] =
true;
165 return static::$availableAppCount[$key];
175 $subscriptionActive = Client::isSubscriptionAvailable();
176 if (!$subscriptionActive)
178 $restUnlimitedFinish =
false;
179 $count = static::DEFAULT_AVAILABLE_COUNT;
182 if (Client::isSubscriptionAccess())
184 $restUnlimitedFinish = Option::get(static::MODULE_ID, static::OPTION_REST_UNLIMITED_FINISH,
null);
185 $count = (int) \
Bitrix\Bitrix24\Feature::getVariable(
'rest_no_subscribe_access_limit');
186 if (\CBitrix24::getLicensePrefix() ===
'ua')
194 $count = (int) Option::get(
196 static::OPTION_AVAILABLE_COUNT,
197 static::DEFAULT_AVAILABLE_COUNT
201 (!$restUnlimitedFinish || $restUnlimitedFinish < time())
292 public static function getHelperCode($action =
'', $entityType =
'', $entityData = []) : string
294 if ($action === static::ACTION_BUY)
296 return 'limit_subscription_market_trial_access';
299 if ($entityType === static::ENTITY_TYPE_APP && !is_array($entityData))
301 $entityData = AppTable::getByClientId($entityData);
305 $dateFinish = Client::getSubscriptionFinalDate();
306 $entity = static::getActiveEntity();
307 $maxCount = static::getAvailableCount();
309 $isSubscriptionFinished = $dateFinish && $dateFinish < (
new Date());
310 $isSubscriptionAccess = Client::isSubscriptionAccess();
311 $isSubscriptionDemoAvailable = Client::isSubscriptionDemoAvailable() && !$dateFinish;
312 $isSubscriptionAvailable = Client::isSubscriptionAvailable();
313 $canBuySubscription = Client::canBuySubscription();
314 $isDemoSubscription = Client::isSubscriptionDemo();
315 $isCanInstallInDemo =
true;
317 !empty($entityData[
'HOLD_INSTALL_BY_TRIAL'])
318 && $entityData[
'HOLD_INSTALL_BY_TRIAL'] ===
'Y'
321 $isCanInstallInDemo =
false;
324 $license = $isB24 ? \CBitrix24::getLicenseFamily() :
'';
325 $isDemo = $license ===
'demo';
326 $isMinLicense = $isB24 && mb_strpos($license,
'project') === 0;
327 $isMaxLicense = $isB24 && ($license ===
'ent' || $license ===
'pro' || mb_strpos($license,
'company') === 0);
329 $isMaxApplication =
false;
330 if ($maxCount >= 0 && $entity[static::ENTITY_COUNT] >= $maxCount)
332 $isMaxApplication =
true;
335 $isMaxApplicationDemo =
false;
336 if ($entity[static::ENTITY_COUNT] >= static::DEFAULT_AVAILABLE_COUNT_DEMO)
338 $isMaxApplicationDemo =
true;
341 $hasPaidApplication =
false;
343 $entity[static::ENTITY_TYPE_APP_STATUS][AppTable::STATUS_PAID] > 0
344 || $entity[static::ENTITY_TYPE_APP_STATUS][AppTable::STATUS_SUBSCRIPTION] > 0
347 $hasPaidApplication =
true;
350 $isFreeEntity =
false;
351 if ($entityType === static::ENTITY_TYPE_INTEGRATION || $entityType === static::ENTITY_TYPE_AP_CONNECT)
353 $isFreeEntity =
true;
355 elseif (!empty($entityData))
358 $entityData[
'ID'] > 0
359 && (isset($entityData[
'ACTIVE']) && $entityData[
'ACTIVE'])
361 $entityData[
'STATUS'] === AppTable::STATUS_FREE
362 || $entityData[
'STATUS'] === AppTable::STATUS_LOCAL
366 $isFreeEntity =
true;
370 !isset($entityData[
'ACTIVE'])
371 || !$entityData[
'ACTIVE']
374 $entityData[
'BY_SUBSCRIPTION'] ===
'Y'
375 || ($entityData[
'FREE'] ===
'N' && !empty($entityData[
'PRICE']))
379 $isFreeEntity =
true;
383 $isUsedDemoLicense =
false;
384 if ($isB24 && (
int) Option::get(
'bitrix24',
'DEMO_START', 0) > 0)
386 $isUsedDemoLicense =
true;
389 if (!static::isActiveRules())
394 $entityData[
'BY_SUBSCRIPTION'] ===
'Y'
395 || ($entityData[
'ID'] > 0 && $entityData[
'STATUS'] === AppTable::STATUS_SUBSCRIPTION)
399 if ($isSubscriptionDemoAvailable)
402 $code =
'limit_subscription_market_access';
404 elseif ($isB24 && $isDemo)
407 $code =
'limit_subscription_market_tarifwithmarket';
412 $code =
'limit_subscription_market_marketpaid';
416 elseif (!$isSubscriptionAccess)
420 if ($isUsedDemoLicense)
422 $code =
'limit_free_rest_hold_no_demo';
424 elseif ($entityType === static::ENTITY_TYPE_AP_CONNECT)
426 $code =
'limit_market_bus';
430 $code =
'limit_free_rest_hold';
434 elseif (!static::isAvailable())
436 if ($hasPaidApplication || !$isFreeEntity)
438 if ($isSubscriptionDemoAvailable)
441 $code =
'limit_subscription_market_access';
446 $code =
'plus_need_trial';
451 $code =
'limit_subscription_market_tarifwithmarket';
452 if ($action === static::ACTION_OPEN)
454 $code =
'installed_plus_buy_license_with_plus';
458 elseif ($isB24 && !$isUsedDemoLicense)
461 if ($entityType === static::ENTITY_TYPE_AP_CONNECT)
463 $code =
'limit_market_bus';
467 $code =
'limit_free_rest_hold';
470 elseif ($isB24 && !$isMaxApplicationDemo)
473 $code =
'limit_free_rest_hold_no_demo';
475 elseif ($isSubscriptionDemoAvailable)
478 $code =
'limit_subscription_market_marketpaid';
480 elseif ($isB24 && $isSubscriptionAccess)
483 $code =
'limit_subscription_market_tarifwithmarket';
484 if ($action === static::ACTION_OPEN)
486 $code =
'limit_free_apps_buy_license_with_plus';
489 elseif (!$isB24 && $isSubscriptionAccess)
492 $code =
'plus_need_trial';
495 elseif ($isB24 && !$isDemo && $isMaxApplication && $isFreeEntity && !$isMaxLicense)
497 if (!$isUsedDemoLicense)
500 if ($entityType === static::ENTITY_TYPE_AP_CONNECT)
502 $code =
'limit_market_bus';
506 $code =
'limit_free_apps_need_demo';
512 $code =
'limit_free_apps_buy_license';
516 $isSubscriptionDemoAvailable
517 && $isCanInstallInDemo
518 && ($hasPaidApplication || $isMaxApplication || !$isFreeEntity)
524 $code =
'limit_subscription_market_access_buy_marketplus';
526 elseif ($isB24 && $isDemo)
529 $code =
'limit_subscription_market_marketpaid';
534 $code =
'limit_subscription_market_access';
537 elseif ($isDemoSubscription && !$isCanInstallInDemo)
540 $code =
'subscription_market_paid_access';
542 elseif ($canBuySubscription)
544 if ($isSubscriptionFinished)
547 $code =
'limit_subscription_market_access_buy_marketplus';
552 $code =
'plus_need_trial';
555 elseif ($isB24 && $isDemo)
557 if (!$isSubscriptionDemoAvailable)
560 $code =
'limit_subscription_market_tarifwithmarket';
565 $code =
'limit_subscription_market_access';
568 elseif (!$isSubscriptionAvailable)
570 $code =
'limit_free_rest_hold_no_demo';