Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
notification.php
1<?php
2
4
11
12Loc::loadMessages(__FILE__);
13
19{
20 private const MODULE_ID = 'rest';
21 private const OPTION_ACCESS_NOTIFICATION = 'rest_access_notification';
22 private const OPTION_LAST_CHECK_ACCESS_NOTIFICATION = 'last_check_rest_access_notify';
23 private const OPTION_LAST_CHECK_NOTIFICATION = 'last_check_rest_notify';
24 private const OPTION_NOTIFICATION_URL = 'rest_notify_url';
25 private const CODE_CHECK_BY_AGENT = [
26 'REST_BUY',
27 'SUBSCRIPTION_MARKET_DEMO_END',
28 'SUBSCRIPTION_MARKET_TARIFF_MARKET',
29 'SUBSCRIPTION_MARKET_TRIAL_END',
30 ];
31 private static $timestampNotifyDays = 259200; // 3 * 86400
32 private static $codeToNotification = [
33 'rest_buy' => 'REST_BUY',
34 'limit_subscription_market_demomarket_end' => 'SUBSCRIPTION_MARKET_DEMO_END',
35 'limit_subscription_market_tarifwithmarket' => 'SUBSCRIPTION_MARKET_TARIFF_MARKET',
36 'plus_need_trial' => 'SUBSCRIPTION_MARKET_TRIAL_END',
37 ];
38
42 public static function get()
43 {
44 $result = false;
45 $option = Option::get(static::MODULE_ID, static::OPTION_ACCESS_NOTIFICATION, '');
46
47 if (static::$codeToNotification[$option])
48 {
49 $option = static::$codeToNotification[$option];
50 }
51
52 if ($option !== '')
53 {
54 $url = Option::get(static::MODULE_ID, static::OPTION_NOTIFICATION_URL, '');
55 if ($url === '')
56 {
57 $url = Loc::getMessage('REST_MARKETPLACE_NOTIFICATION_' . $option . '_URL');
58 if ($option === 'REST_BUY' && Loader::includeModule('bitrix24'))
59 {
60 $prefix = \CBitrix24::getLicensePrefix();
61 if ($prefix === 'by')
62 {
63 $url = 'https://goodbye-2020.bitrix24.site/';
64 }
65 elseif ($prefix === 'kz')
66 {
67 $url = 'https://goodbye2020.bitrix24.site/';
68 }
69 elseif ($prefix === 'ua')
70 {
71 $url = 'https://skilky-mozhna.bitrix24site.ua/';
72 }
73 elseif ($prefix === 'ru')
74 {
75 $url = 'https://goodbye2020.bitrix24.tech/';
76 }
77 elseif ($prefix === 'en')
78 {
79 $url = 'https://www.bitrix24.com/promo/sales/holiday-sale/';
80 }
81 elseif ($prefix === 'jp')
82 {
83 $url = 'https://www.bitrix24.jp/promo/sales/holiday-sale/';
84 }
85 elseif ($prefix === 'pl')
86 {
87 $url = 'https://www.bitrix24.pl/promo/sales/holiday-sale/';
88 }
89 elseif ($prefix === 'it')
90 {
91 $url = 'https://www.bitrix24.it/promo/sales/holiday-sale/';
92 }
93 elseif ($prefix === 'br')
94 {
95 $url = 'https://www.bitrix24.com.br/promo/sales/holiday-sale/';
96 }
97 elseif ($prefix === 'fr')
98 {
99 $url = 'https://www.bitrix24.fr/promo/sales/holiday-sale/';
100 }
101 elseif ($prefix === 'de')
102 {
103 $url = 'https://www.bitrix24.de/promo/sales/holiday-sale/';
104 }
105 elseif ($prefix === 'in')
106 {
107 $url = 'https://www.bitrix24.in/promo/sales/holiday-sale/';
108 }
109 elseif ($prefix === 'eu')
110 {
111 $url = 'https://www.bitrix24.eu/promo/sales/holiday-sale/';
112 }
113 elseif ($prefix === 'es' || $prefix === 'la')
114 {
115 $url = 'https://www.bitrix24.es/promo/sales/holiday-sale/';
116 }
117 }
118
119 if ($option === 'SUBSCRIPTION_MARKET_TRIAL_END')
120 {
121 $url = \Bitrix\Rest\Marketplace\Url::getSubscriptionBuyUrl();
122 }
123 }
124 $urlBtn = '';
125 if ($url !== '')
126 {
127 $urlBtn = '<a target="_blank" href="'
128 . $url
129 . '">'
130 . Loc::getMessage('REST_MARKETPLACE_NOTIFICATION_' . $option . '_BTN')
131 . '</a>';
132 }
133
134 $message = Loc::getMessage(
135 'REST_MARKETPLACE_NOTIFICATION_' . $option . '_MESS',
136 [
137 '#BTN#' => $urlBtn
138 ]
139 );
140 if ($message !== '')
141 {
142 $result = [
143 'PANEL_MESSAGE' => $message
144 ];
145 }
146 else
147 {
148 static::reset();
149 }
150 }
151
152 return $result;
153 }
154
155 public static function setLastCheckTimestamp($timestamp)
156 {
157 Option::set(static::MODULE_ID, static::OPTION_LAST_CHECK_NOTIFICATION, $timestamp);
158 return true;
159 }
160
161 public static function getLastCheckTimestamp()
162 {
163 $result = false;
164 $option = (int) Option::get(static::MODULE_ID, static::OPTION_LAST_CHECK_NOTIFICATION, 0);
165 if ($option > 0)
166 {
167 $result = $option + static::$timestampNotifyDays;
168 }
169
170 return $result;
171 }
172
181 public static function set(string $code, string $url = '') : bool
182 {
183 Option::set(static::MODULE_ID, static::OPTION_ACCESS_NOTIFICATION, $code);
184 Option::set(static::MODULE_ID, static::OPTION_LAST_CHECK_ACCESS_NOTIFICATION, time());
185 Option::set(static::MODULE_ID, static::OPTION_NOTIFICATION_URL, $url);
186
187 return true;
188 }
189
195 public static function reset()
196 {
197 Option::delete(static::MODULE_ID, ['name' => static::OPTION_ACCESS_NOTIFICATION]);
198 Option::delete(static::MODULE_ID, ['name' => static::OPTION_LAST_CHECK_ACCESS_NOTIFICATION]);
199 Option::delete(static::MODULE_ID, ['name' => static::OPTION_NOTIFICATION_URL]);
200
201 return true;
202 }
203
207 public static function checkAgent()
208 {
209 if (Loader::includeModule('bitrix24'))
210 {
211 $code = '';
213 {
214 $dateFinish = Client::getSubscriptionFinalDate();
215 $entity = Access::getActiveEntity();
216 $maxCount = Access::getAvailableCount();
217 $isSubscriptionFinish = $dateFinish
218 && $dateFinish < (new Date())
219 && (time() - static::$timestampNotifyDays) < $dateFinish->getTimestamp();
220 if (!Access::isAvailable())
221 {
222 if (
223 $maxCount >= 0
224 && (
225 $entity[Access::ENTITY_COUNT] > $maxCount
228 )
229 && static::getLastCheckTimestamp() > time()
230 )
231 {
232 $code = 'SUBSCRIPTION_MARKET_TARIFF_MARKET';
233 }
234 elseif ($isSubscriptionFinish)
235 {
236 $code = 'SUBSCRIPTION_MARKET_DEMO_END';
237 }
238 }
239 elseif (Access::isFeatureEnabled() && $isSubscriptionFinish)
240 {
241 $code = 'SUBSCRIPTION_MARKET_TRIAL_END';
242 }
243 }
244
245 if ($code !== '')
246 {
247 static::set($code);
248 }
249 else
250 {
251 $lastCode = Option::get(static::MODULE_ID, static::OPTION_ACCESS_NOTIFICATION, null);
252 if (!is_null($lastCode) && in_array($lastCode, static::CODE_CHECK_BY_AGENT))
253 {
254 static::reset();
255 }
256 }
257 }
258
259 return '\Bitrix\Rest\Marketplace\Notification::checkAgent();';
260 }
261}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
const STATUS_PAID
Definition app.php:76
const STATUS_SUBSCRIPTION
Definition app.php:79
static getActiveEntity($force=false)
Definition access.php:212
static isAvailable($app='')
Definition access.php:65