Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
promotion.php
1<?php
2namespace Bitrix\Im;
3
5
7{
8 const DEVICE_TYPE_WEB = "web"; // browser + desktop
9 const DEVICE_TYPE_BROWSER = "browser";
10 const DEVICE_TYPE_DESKTOP = "desktop";
11 const DEVICE_TYPE_MOBILE = "mobile";
12 const DEVICE_TYPE_ALL = "all";
13
14 const USER_TYPE_OLD = "OLD";
15 const USER_TYPE_NEW = "NEW";
16 const USER_TYPE_ALL = "ALL";
17
18 private static function getConfig()
19 {
20 $result = [];
21
22 if (!\Bitrix\Main\Loader::includeModule('ui'))
23 {
24 return $result;
25 }
26
27 if (self::isDisable())
28 {
29 return $result;
30 }
31
32/*
33 $result[] = [
34 "ID" => 'im:video:01042020:web',
35 "USER_TYPE" => self::USER_TYPE_OLD,
36 "DEVICE_TYPE" => self::DEVICE_TYPE_WEB
37 ];
38
39 $result[] = [
40 "ID" => 'ol:crmform:17092021:web',
41 "USER_TYPE" => self::USER_TYPE_OLD,
42 "DEVICE_TYPE" => self::DEVICE_TYPE_WEB
43 ];
44
45 $result[] = [
46 "ID" => 'im:call-document:16102021:web',
47 "USER_TYPE" => self::USER_TYPE_ALL,
48 "DEVICE_TYPE" => self::DEVICE_TYPE_WEB
49 ];
50
51 $result[] = [
52 "ID" => 'imbot:support24:25112021:web',
53 "USER_TYPE" => self::USER_TYPE_OLD,
54 "DEVICE_TYPE" => self::DEVICE_TYPE_WEB
55 ];
56 $result[] = [
57 "ID" => 'im:mask:06122022:desktop',
58 "USER_TYPE" => self::USER_TYPE_OLD,
59 "DEVICE_TYPE" => self::DEVICE_TYPE_DESKTOP
60 ];
61*/
62 $result[] = [
63 "ID" => 'im:ai:15062023:all',
64 "USER_TYPE" => self::USER_TYPE_ALL,
65 "DEVICE_TYPE" => self::DEVICE_TYPE_ALL
66 ];
67
68 $result[] = [
69 "ID" => 'im:group-chat-create:20062023:all',
70 "USER_TYPE" => self::USER_TYPE_ALL,
71 "DEVICE_TYPE" => self::DEVICE_TYPE_ALL
72 ];
73
74 $result[] = [
75 "ID" => 'im:conference-create:24082023:all',
76 "USER_TYPE" => self::USER_TYPE_ALL,
77 "DEVICE_TYPE" => self::DEVICE_TYPE_ALL
78 ];
79
81 {
82 $result[] = [
83 "ID" => 'immobile:chat-v2:16112023:mobile',
84 "USER_TYPE" => self::USER_TYPE_ALL,
85 "DEVICE_TYPE" => self::DEVICE_TYPE_MOBILE,
86 ];
87 }
88
89 $settings = \Bitrix\Main\Config\Configuration::getValue('im');
90 if (isset($settings['promotion']) && is_array($settings['promotion']))
91 {
92 $result = array_merge($result, $settings['promotion']);
93 }
94
95 return $result;
96 }
97
98 public static function getActive($type = self::DEVICE_TYPE_ALL)
99 {
100 $result = [];
101
102 if (!\Bitrix\Main\Loader::includeModule('ui'))
103 {
104 return $result;
105 }
106
107 foreach (self::getConfig() as $config)
108 {
109 $tour = self::getTour($config, $type);
110 if (!$tour || !$tour->isAvailable())
111 {
112 continue;
113 }
114
115 $result[] = $tour->getId();
116 }
117
118 return $result;
119 }
120
121 public static function read($id)
122 {
123 $tour = self::getTourById($id);
124 if (!$tour || !$tour->isAvailable())
125 {
126 return false;
127 }
128
129 $userId = Common::getUserId();
130
131 $tour->setViewDate($userId);
132
133 if (\Bitrix\Main\Loader::includeModule('pull'))
134 {
135 \Bitrix\Pull\Event::add($userId, [
136 'module_id' => 'im',
137 'command' => 'promotionRead',
138 'params' => ['id' => $id],
139 'extra' => \Bitrix\Im\Common::getPullExtra()
140 ]);
141 }
142
143 return true;
144 }
145
156
157 private static function getTour($config, $type = self::DEVICE_TYPE_ALL)
158 {
159 if (!\Bitrix\Main\Loader::includeModule('ui'))
160 {
161 return null;
162 }
163
164 if ($type === self::DEVICE_TYPE_WEB)
165 {
166 if (!(
167 $config['DEVICE_TYPE'] === self::DEVICE_TYPE_ALL
168 || $config['DEVICE_TYPE'] === self::DEVICE_TYPE_BROWSER
169 || $config['DEVICE_TYPE'] === self::DEVICE_TYPE_DESKTOP
170 ))
171 {
172 return false;
173 }
174 }
175 else if ($type === self::DEVICE_TYPE_MOBILE)
176 {
177 if (
178 $config['DEVICE_TYPE'] !== self::DEVICE_TYPE_MOBILE
179 && $config['DEVICE_TYPE'] !== self::DEVICE_TYPE_ALL
180 )
181 {
182 return false;
183 }
184 }
185 else if ($type !== self::DEVICE_TYPE_ALL)
186 {
187 if (
188 $config['DEVICE_TYPE'] !== self::DEVICE_TYPE_ALL
189 && $config['DEVICE_TYPE'] !== self::DEVICE_TYPE_WEB
190 && $config['DEVICE_TYPE'] !== $type
191 )
192 {
193 return false;
194 }
195 }
196
197 $tour = new \Bitrix\Main\UI\Tour($config["ID"]);
198
199 $params = array(
200 "USER_TYPE" => "setUserType",
201 "USER_TIMESPAN" => "setUserTimeSpan",
202 "LIFETIME" => "setLifetime",
203 "START_DATE" => "setStartDate",
204 "END_DATE" => "setEndDate",
205 );
206
207 foreach ($params as $param => $setter)
208 {
209 if (isset($config[$param]))
210 {
211 $tour->$setter($config[$param]);
212 }
213 }
214
215 return $tour;
216 }
217
218 private static function getTourById($id)
219 {
220 foreach (self::getConfig() as $config)
221 {
222 if ($config['ID'] === $id)
223 {
224 return self::getTour($config);
225 }
226 }
227
228 return null;
229 }
230
231 private static function isDisable(): bool
232 {
233 return Option::get('im', 'promo_disabled', 'N') === 'Y';
234 }
235}
static getPullExtra()
Definition common.php:128
static getUserId($userId=null)
Definition common.php:74
const DEVICE_TYPE_BROWSER
Definition promotion.php:9
static getDeviceTypes()
static getActive($type=self::DEVICE_TYPE_ALL)
Definition promotion.php:98
static isLegacyChatActivated($userId=false)
Definition settings.php:85