Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
feature.php
1<?php
3
6 Bitrix\Bitrix24;
7
8Loc::loadMessages(__FILE__);
9
10final class Feature
11{
12 private const DISCOUNT_CONSTRUCTOR = 'sale_discount_constructor';
13 private const CUMULATIVE_DISCOUNTS = 'sale_cumulative_discounts';
14
15 private static $bitrix24Included = null;
16
17 private static $featureList = [];
18
19 private static $tranferList = [
20 self::CUMULATIVE_DISCOUNTS => 'CatDiscountSave'
21 ];
22
23 private static $retailExist = [
24 self::CUMULATIVE_DISCOUNTS => true
25 ];
26
27 private static $bitrix24exist = [
28 self::CUMULATIVE_DISCOUNTS => true,
29 self::DISCOUNT_CONSTRUCTOR => true
30 ];
31
33 private static $bitrix24helpCodes = [
34 self::DISCOUNT_CONSTRUCTOR => 'limit_shop_discount_builder',
35 self::CUMULATIVE_DISCOUNTS => 'limit_shop_cumulative_discounts'
36 ];
37
38 private static $helpCodesCounter = 0;
39 private static $initUi = false;
40
41 public static function isCumulativeDiscountsEnabled()
42 {
43 return self::isFeatureEnabled(self::CUMULATIVE_DISCOUNTS);
44 }
45
46 public static function isDiscountConstructorEnabled()
47 {
48 return self::isFeatureEnabled(self::DISCOUNT_CONSTRUCTOR);
49 }
50
56 public static function getCumulativeDiscountsHelpLink(): ?array
57 {
58 return self::getHelpLink(self::CUMULATIVE_DISCOUNTS);
59 }
60
66 public static function getDiscountConstructorHelpLink(): ?array
67 {
68 return self::getHelpLink(self::DISCOUNT_CONSTRUCTOR);
69 }
70
76 public static function initUiHelpScope(): void
77 {
78 global $APPLICATION;
79 if (!self::isBitrix24())
80 {
81 return;
82 }
83 if (self::$helpCodesCounter <= 0 || self::$initUi)
84 {
85 return;
86 }
87 self::$initUi = true;
88 $APPLICATION->IncludeComponent(
89 'bitrix:ui.info.helper',
90 '',
91 []
92 );
93 }
94
95 private static function isFeatureEnabled($featureId)
96 {
97 $featureId = (string)$featureId;
98 if ($featureId === '')
99 return false;
100 if (!isset(self::$featureList[$featureId]))
101 {
102 if (self::isBitrix24())
103 {
104 if (isset(self::$bitrix24exist[$featureId]))
105 self::$featureList[$featureId] = Bitrix24\Feature::isFeatureEnabled($featureId);
106 else
107 self::$featureList[$featureId] = true;
108 }
109 else
110 {
111 if (isset(self::$retailExist[$featureId]))
112 self::$featureList[$featureId] = \CBXFeatures::IsFeatureEnabled(self::$tranferList[$featureId]);
113 else
114 self::$featureList[$featureId] = true;
115 }
116 }
117 return self::$featureList[$featureId];
118 }
119
126 private static function getHelpLink(string $featureId): ?array
127 {
128 if (!self::isBitrix24())
129 {
130 return null;
131 }
132 if (!isset(self::$bitrix24helpCodes[$featureId]))
133 {
134 return null;
135 }
136 self::$helpCodesCounter++;
137 return [
138 'TYPE' => 'ONCLICK',
139 'LINK' => 'BX.UI.InfoHelper.show(\''.self::$bitrix24helpCodes[$featureId].'\');'
140 ];
141 }
142
143 private static function isBitrix24()
144 {
145 if (self::$bitrix24Included === null)
146 self::$bitrix24Included = Loader::includeModule('bitrix24');
147 return self::$bitrix24Included;
148 }
149}
static loadMessages($file)
Definition loc.php:64
static isCumulativeDiscountsEnabled()
Definition feature.php:41
static getCumulativeDiscountsHelpLink()
Definition feature.php:56
static getDiscountConstructorHelpLink()
Definition feature.php:66
static isDiscountConstructorEnabled()
Definition feature.php:46