1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
UIPromotionService.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Im\V2\Promotion\Service;
6
7use Bitrix\Im\Common;
8use Bitrix\Im\V2\Application\Features;
9use Bitrix\Im\V2\Common\SingletonTrait;
10use Bitrix\Im\V2\Promotion\Entity\Promotion;
11use Bitrix\Im\V2\Promotion\Entity\PromotionList;
12use Bitrix\Im\V2\Promotion\Internals\DeviceType;
13use Bitrix\Im\V2\Promotion\Internals\PromotionType;
14use Bitrix\Im\V2\Promotion\Internals\UserType;
15use Bitrix\Im\V2\Service\Locator;
16use Bitrix\Main\Config\Configuration;
17use Bitrix\Main\Error;
18use Bitrix\Main\Loader;
19use Bitrix\Main\Result;
20use Bitrix\Main\Type\DateTime;
21use Bitrix\Main\UI\Tour;
22use Bitrix\Pull\Event;
23
25{
26 use SingletonTrait;
27
28 private const ONE_MONTH = 3600 * 24 * 30;
29 private const ENDLESS_LIFETIME = 0;
30
31 public function getActive(DeviceType $type = DeviceType::ALL): PromotionList
32 {
33 $promoList = new PromotionList();
34
35 if (!Loader::includeModule('ui'))
36 {
37 return $promoList;
38 }
39
40 foreach ($this->getConfig() as $config)
41 {
42 $tour = $this->getTour($config, $type);
43 if (!$tour || !$tour->isAvailable())
44 {
45 continue;
46 }
47
48 $promo = new Promotion($tour->getId());
49 $promoList->add($promo);
50 }
51
52 return $promoList;
53 }
54
55 private function getConfig(): array
56 {
57 $result = [];
58
59 if (!Loader::includeModule('ui'))
60 {
61 return $result;
62 }
63
64 $result[] = [
65 "ID" => 'im:group-chat-create:20062023:all',
66 "USER_TYPE" => UserType::ALL->value,
67 "DEVICE_TYPE" => DeviceType::WEB->value,
68 "LIFETIME" => self::ENDLESS_LIFETIME,
69 "END_DATE" => (new DateTime('01.11.2025', 'd.m.Y'))->getTimestamp()
70 ];
71
72 $result[] = [
73 "ID" => 'im:conference-create:24082023:all',
74 "USER_TYPE" => UserType::ALL->value,
75 "DEVICE_TYPE" => DeviceType::WEB->value,
76 "LIFETIME" => self::ENDLESS_LIFETIME,
77 "END_DATE" => (new DateTime('01.11.2025', 'd.m.Y'))->getTimestamp()
78 ];
79
80 $result[] = [
81 "ID" => 'im:channel-create:04032024:all',
82 "USER_TYPE" => UserType::ALL->value,
83 "DEVICE_TYPE" => DeviceType::WEB->value,
84 "LIFETIME" => self::ENDLESS_LIFETIME,
85 "END_DATE" => (new DateTime('01.11.2025', 'd.m.Y'))->getTimestamp()
86 ];
87
88 $result[] = [
89 "ID" => 'im:collab-create:12092024:all',
90 "USER_TYPE" => UserType::ALL->value,
91 "DEVICE_TYPE" => DeviceType::WEB->value,
92 "LIFETIME" => self::ONE_MONTH * 2,
93 ];
94
95 $result[] = [
96 "ID" => 'im:add-users-to-copilot-chat:09042024:all',
97 "USER_TYPE" => UserType::ALL->value,
98 "DEVICE_TYPE" => DeviceType::WEB->value,
99 "LIFETIME" => self::ENDLESS_LIFETIME,
100 "END_DATE" => (new DateTime('01.11.2025', 'd.m.Y'))->getTimestamp()
101 ];
102
103 $result[] = [
104 "ID" => 'im:change-role-copilot-chat:09042024:all',
105 "USER_TYPE" => UserType::ALL->value,
106 "DEVICE_TYPE" => DeviceType::WEB->value,
107 "LIFETIME" => self::ENDLESS_LIFETIME,
108 "END_DATE" => (new DateTime('01.11.2025', 'd.m.Y'))->getTimestamp()
109 ];
110
111 $result[] = [
112 "ID" => 'im:collab-helpdesk-sidebar:30102024:all',
113 "USER_TYPE" => UserType::ALL->value,
114 "DEVICE_TYPE" => DeviceType::WEB->value,
115 "LIFETIME" => self::ENDLESS_LIFETIME,
116 ];
117
118 $result[] = [
119 "ID" => 'call:copilot-call-button:29102024:all',
120 "USER_TYPE" => UserType::ALL->value,
121 "DEVICE_TYPE" => DeviceType::WEB->value,
122 ];
123
124 $result[] = [
125 "ID" => 'call:copilot-notify-warning:21112024:all',
126 "USER_TYPE" => UserType::ALL->value,
127 "DEVICE_TYPE" => DeviceType::WEB->value,
128 ];
129
130 $result[] = [
131 "ID" => 'call:copilot-notify-promo:21112024:all',
132 "USER_TYPE" => UserType::ALL->value,
133 "DEVICE_TYPE" => DeviceType::WEB->value,
134 ];
135
136 $result[] = [
137 "ID" => 'call:callcontrol-notify-promo:07052025:all',
138 "USER_TYPE" => UserType::ALL->value,
139 "DEVICE_TYPE" => DeviceType::ALL->value,
140 ];
141
142 $result[] = [
143 "ID" => 'im:download-several-files:22112024:all',
144 "USER_TYPE" => UserType::ALL->value,
145 "DEVICE_TYPE" => DeviceType::WEB->value,
146 "LIFETIME" => self::ENDLESS_LIFETIME,
147 ];
148
149 $result[] = [
150 "ID" => 'call:copilot-notify-result:24112024:all',
151 "USER_TYPE" => UserType::ALL->value,
152 "DEVICE_TYPE" => DeviceType::WEB->value,
153 ];
154
155 $result[] = [
156 "ID" => 'im:copilot-in-default-tab:11032025:all',
157 "USER_TYPE" => UserType::ALL->value,
158 "DEVICE_TYPE" => DeviceType::ALL->value,
159 "LIFETIME" => self::ENDLESS_LIFETIME,
160 "END_DATE" => (new DateTime('30.04.2026', 'd.m.Y'))->getTimestamp(),
161 ];
162
163 if (Locator::getMessenger()->getApplication()->isAirDesignEnabled())
164 {
165 $result[] = [
166 "ID" => 'im:air-chat-empty-state:29042025:all',
167 "USER_TYPE" => UserType::ALL->value,
168 "DEVICE_TYPE" => DeviceType::WEB->value,
169 "LIFETIME" => self::ENDLESS_LIFETIME,
170 ];
171 }
172
173 if (Features::get()->intranetInviteAvailable)
174 {
175 $result[] = [
176 "ID" => 'im:recent-create-chat-invite-users:22052025:all',
177 "USER_TYPE" => UserType::ALL->value,
178 "DEVICE_TYPE" => DeviceType::WEB->value,
179 "LIFETIME" => self::ENDLESS_LIFETIME,
180 ];
181 }
182
183 if (Features::isCopilotSelectModelAvailable())
184 {
185 $result[] = [
186 "ID" => 'im:chat-header-change-copilot-engine-and-role:20052025:all',
187 "USER_TYPE" => UserType::ALL->value,
188 "DEVICE_TYPE" => DeviceType::ALL->value,
189 "LIFETIME" => self::ENDLESS_LIFETIME,
190 "END_DATE" => (new DateTime('30.04.2027', 'd.m.Y'))->getTimestamp(),
191 ];
192
193 $result[] = [
194 "ID" => 'im:chat-sidebar-change-copilot-engine-and-role:20052025:all',
195 "USER_TYPE" => UserType::ALL->value,
196 "DEVICE_TYPE" => DeviceType::ALL->value,
197 "LIFETIME" => self::ENDLESS_LIFETIME,
198 "END_DATE" => (new DateTime('30.04.2027', 'd.m.Y'))->getTimestamp(),
199 ];
200 }
201 else
202 {
203 $result[] = [
204 "ID" => 'im:add-users-to-copilot-chat:09042024:all',
205 "USER_TYPE" => UserType::ALL->value,
206 "DEVICE_TYPE" => DeviceType::ALL->value,
207 "LIFETIME" => self::ENDLESS_LIFETIME,
208 "END_DATE" => (new DateTime('01.11.2025', 'd.m.Y'))->getTimestamp()
209 ];
210
211 $result[] = [
212 "ID" => 'im:change-role-copilot-chat:09042024:all',
213 "USER_TYPE" => UserType::ALL->value,
214 "DEVICE_TYPE" => DeviceType::ALL->value,
215 "LIFETIME" => self::ENDLESS_LIFETIME,
216 "END_DATE" => (new DateTime('01.11.2025', 'd.m.Y'))->getTimestamp()
217 ];
218 }
219
221 if (isset($settings['promotion']) && is_array($settings['promotion']))
222 {
223 $result = array_merge($result, $settings['promotion']);
224 }
225
226 return $result;
227 }
228
229 private function getTour(array $config, DeviceType $type = DeviceType::ALL): bool|Tour|null
230 {
231 if (!Loader::includeModule('ui'))
232 {
233 return null;
234 }
235
236 $deviceType = (string)$config['DEVICE_TYPE'];
237 if (!$type->isDeviceTypeAvailable($deviceType))
238 {
239 return false;
240 }
241
242 $tour = new Tour($config["ID"]);
243
244 $params = [
245 "USER_TYPE" => "setUserType",
246 "USER_TIMESPAN" => "setUserTimeSpan",
247 "LIFETIME" => "setLifetime",
248 "START_DATE" => "setStartDate",
249 "END_DATE" => "setEndDate",
250 ];
251
252 foreach ($params as $param => $setter)
253 {
254 if (isset($config[$param]))
255 {
256 $tour->$setter($config[$param]);
257 }
258 }
259
260 return $tour;
261 }
262
263 public function getTourById(string $id): ?Tour
264 {
265 foreach ($this->getConfig() as $config)
266 {
267 if ($config['ID'] === $id)
268 {
269 return $this->getTour($config);
270 }
271 }
272
273 return null;
274 }
275
277 {
278 return PromotionType::UI;
279 }
280
281 public function isCurrentTypePromotion(string $promotionId): bool
282 {
283 return in_array($promotionId, $this->getActive()->toIdList(), true);
284 }
285
286 public function markAsViewed(Promotion $promotion): Result
287 {
288 $result = new Result();
289 $promoId = $promotion->getId();
290
291 $tour = $this->getTourById($promoId);
292 if (!$tour || !$tour->isAvailable())
293 {
294 $result->addError(new Error('Promotion is not available'));
295
296 return $result;
297 }
298
300 $tour->setViewDate($userId);
301
302 if (Loader::includeModule('pull'))
303 {
304 Event::add($userId, [
305 'module_id' => 'im',
306 'command' => 'promotionRead',
307 'params' => ['id' => $promoId],
308 'extra' => Common::getPullExtra()
309 ]);
310 }
311
312 return $result;
313 }
314}
$type
Определения options.php:106
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getPullExtra()
Определения common.php:127
getActive(DeviceType $type=DeviceType::ALL)
Определения UIPromotionService.php:31
isCurrentTypePromotion(string $promotionId)
Определения UIPromotionService.php:281
Определения error.php:15
Определения tour.php:6
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$settings
Определения product_settings.php:43
$config
Определения quickway.php:69
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799