1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
im_settings.php
См. документацию.
1<?php
2
9
11{
12 public const SETTINGS = 'settings';
13 public const NOTIFY = 'notify';
14
15 public const CLIENT_SITE = 'site';
16 public const CLIENT_XMPP = 'xmpp';
17 public const CLIENT_MAIL = 'email';
18 public const CLIENT_PUSH = 'push';
19
20 public const START_MESSAGE_FIRST = 'first';
21 public const START_MESSAGE_LAST = 'last';
22
23 public const PRIVACY_MESSAGE = 'privacyMessage';
24 public const PRIVACY_CHAT = 'privacyChat';
25 public const PRIVACY_CALL = 'privacyCall';
26 public const PRIVACY_SEARCH = 'privacySearch';
27 public const PRIVACY_PROFILE = 'privacyProfile';
28 public const PRIVACY_RESULT_ALL = 'all';
29 public const PRIVACY_RESULT_CONTACT = 'contact';
30 public const PRIVACY_RESULT_NOBODY = 'nobody';
31
32 public const STATUS = 'status';
33
34 public static function Get($userId = false)
35 {
36 $userId = $userId === false ? null : $userId;
37 $userId = Common::getUserId($userId);
38 if (!$userId)
39 {
40 return null;
41 }
42
43 if (Manager::isSettingsMigrated() || Manager::isUserMigrated($userId))
44 {
45 $result = Manager::getUserSettings($userId);
46 if (!$result->isSuccess())
47 {
48 return null;
49 }
50 $settings = $result->getData();
51
52 if(empty($settings['notify']) || empty($settings['general']))
53 {
54 return null;
55 }
56
57 return [
58 self::NOTIFY => self::convertNotifySettingsToOldFormat($settings['notify']['settings']),
59 self::SETTINGS => $settings['general']['settings'],
60 ];
61 }
62
63 $arSettings[self::SETTINGS] = CUserOptions::GetOption('im', self::SETTINGS, [], $userId);
64 $arSettings[self::NOTIFY] = CUserOptions::GetOption('im', self::NOTIFY, [], $userId);
65
66 // Check fields and add default values
67 $arSettings[self::SETTINGS] = self::checkValues(self::SETTINGS, $arSettings[self::SETTINGS]);
68 $arSettings[self::NOTIFY] = self::checkValues(self::NOTIFY, $arSettings[self::NOTIFY]);
69
70 return $arSettings;
71 }
72
73 public static function Set($type, $value, $userId = false)
74 {
75 if (!in_array($type, [self::SETTINGS, self::NOTIFY], true))
76 {
77 return false;
78 }
79
81
82 $userId = $userId === false ? null : $userId;
83 $userId = Common::getUserId($userId);
84 if (!$userId)
85 {
86 return null;
87 }
88
89 if (Manager::isSettingsMigrated() || Manager::isUserMigrated($userId))
90 {
91 $newFormatSettings['notify'] =
92 $type === self::NOTIFY
93 ? self::convertNotifySettingsToNewFormat($value)
94 : []
95 ;
96
97 $newFormatSettings['general'] =
98 $type === self::SETTINGS
99 ? array_replace_recursive(General::getDefaultSettings(), $value)
100 : []
101 ;
102 return Manager::setUserSettings($userId, $newFormatSettings)->isSuccess();
103 }
104
105 if (isset($value[self::STATUS]))
106 {
107 CIMStatus::Set($userId, ['STATUS' => $value[self::STATUS]]);
108 }
109 if (isset($value['openDesktopFromPanel']) && CModule::IncludeModule('pull'))
110 {
111 Event::add($userId, [
112 'module_id' => 'im',
113 'command' => 'settingsUpdate',
114 'expiry' => 5,
115 'params' => [
116 'openDesktopFromPanel' => $value['openDesktopFromPanel'],
117 ],
118 'extra' => Common::getPullExtra()
119 ]);
120 }
121
122 $arDefault = self::GetDefaultSettings($type);
123 foreach ($value as $key => $val)
124 {
125 if (isset($arDefault[$key]) && $arDefault[$key] == $val)
126 {
127 if ($key === self::PRIVACY_SEARCH)
128 {
129 $USER_FIELD_MANAGER->Update("USER", $userId, ['UF_IM_SEARCH' => '']);
130 }
131 unset($value[$key]);
132 }
133 }
134 CUserOptions::SetOption('im', $type, $value, false, $userId);
135
136 if (isset($value[self::PRIVACY_SEARCH]))
137 {
138 $USER_FIELD_MANAGER->Update("USER", $userId, ['UF_IM_SEARCH' => $value[self::PRIVACY_SEARCH]]);
139 }
140
141 return true;
142 }
143
144 public static function SetSetting($type, $value, $userId = false)
145 {
146 if (!in_array($type, [self::SETTINGS, self::NOTIFY], true))
147 {
148 return false;
149 }
150
151 global $USER_FIELD_MANAGER;
152
153 $userId = $userId === false ? null : $userId;
154 $userId = Common::getUserId($userId);
155 if (!$userId)
156 {
157 return null;
158 }
159
160 if (Manager::isSettingsMigrated() || Manager::isUserMigrated($userId))
161 {
162 $newFormatSettings = [];
163 if ($type === self::NOTIFY)
164 {
165 $newFormatSettings = self::convertNotifySettingsToNewFormat($value, false);
166 }
167 if ($type === self::SETTINGS)
168 {
169 $type = 'general';
170 $newFormatSettings = $value;
171 }
172
173 return Manager::setUserSetting($userId, $type, $newFormatSettings)->isSuccess();
174 }
175
176 $arSettings = CUserOptions::GetOption('im', $type, [], $userId);
177 foreach ($value as $key => $val)
178 {
179 $arSettings[$key] = $val;
180 }
181
182 if (isset($value[self::STATUS]))
183 {
184 CIMStatus::Set($userId, ['STATUS' => $value[self::STATUS]]);
185 }
186 if (isset($value['openDesktopFromPanel']) && CModule::IncludeModule('pull'))
187 {
188 Event::add(
189 $userId,
190 [
191 'module_id' => 'im',
192 'command' => 'settingsUpdate',
193 'expiry' => 5,
194 'params' => [
195 'openDesktopFromPanel' => $value['openDesktopFromPanel'],
196 ],
197 'extra' => Common::getPullExtra()
198 ]
199 );
200 }
201
202 $arDefault = self::GetDefaultSettings($type);
203 foreach ($arSettings as $key => $val)
204 {
205 if (isset($arDefault[$key]) && $arDefault[$key] == $val)
206 {
207 if ($key === self::PRIVACY_SEARCH)
208 {
209 $USER_FIELD_MANAGER->Update("USER", $userId, ['UF_IM_SEARCH' => '']);
210 }
211 unset($value[$key]);
212 }
213 }
214 CUserOptions::SetOption('im', $type, $arSettings, false, $userId);
215 if (isset($value[self::PRIVACY_SEARCH]))
216 {
217 $USER_FIELD_MANAGER->Update("USER", $userId, ['UF_IM_SEARCH' => $value[self::PRIVACY_SEARCH]]);
218 }
219
220 return true;
221 }
222
223 public static function GetSetting($type, $value, $userId = false)
224 {
225 if (!in_array($type, [self::SETTINGS, self::NOTIFY], true))
226 {
227 return null;
228 }
229
230 $userId = $userId === false ? null : $userId;
231 $userId = Common::getUserId($userId);
232 if (!$userId)
233 {
234 return null;
235 }
236
237 if (Manager::isSettingsMigrated() || Manager::isUserMigrated($userId))
238 {
239 if ($type === self::NOTIFY)
240 {
241 [$option, $module, $event] = explode('|', $value, 3);
242 return (new Notification($module, $event))->getValue($userId, $option);
243 }
244 if ($type === self::SETTINGS)
245 {
246 return General::createWithUserId($userId)->getValue($value);
247 }
248 }
249
250 $arSettings = self::Get($userId);
251
252 return isset($arSettings[$type][$value]) ? $arSettings[$type][$value] : null;
253 }
254
255 public static function GetNotifyAccess($userId, $moduleId, $eventId, $clientId)
256 {
257 $userId = intval($userId);
258 if ($userId <= 0 || $moduleId == '' || $eventId == '' || $clientId == '')
259 {
260 return false;
261 }
262
263 if (Manager::isSettingsMigrated() || Manager::isUserMigrated($userId))
264 {
265 $clientId = $clientId === self::CLIENT_MAIL ? Notification::MAIL : $clientId;
266
267 return Manager::getNotifyAccess($userId, $moduleId, $eventId, $clientId);
268 }
269
270 $notifySettingName = $clientId.'|'.$moduleId.'|'.$eventId;
271 $userSettings = self::Get($userId);
272
273 if ($userSettings['settings']['notifyScheme'] === 'simple')
274 {
275 if ($clientId === self::CLIENT_SITE && !$userSettings['settings']['notifySchemeSendSite'])
276 {
277 return false;
278 }
279
280 if ($clientId === self::CLIENT_XMPP && !$userSettings['settings']['notifySchemeSendXmpp'])
281 {
282 return false;
283 }
284
285 if ($clientId === self::CLIENT_MAIL && !$userSettings['settings']['notifySchemeSendEmail'])
286 {
287 return false;
288 }
289
290 if ($clientId === self::CLIENT_PUSH && !$userSettings['settings']['notifySchemeSendPush'])
291 {
292 return false;
293 }
294
295 return
296 isset($userSettings['notify'])
297 && array_key_exists($notifySettingName, $userSettings['notify'])
298 && $userSettings['notify'][$notifySettingName] === false
299 ? false
300 : true;
301 }
302 else
303 {
304 if (isset($userSettings['notify']) && array_key_exists($notifySettingName, $userSettings['notify']))
305 {
306 return $userSettings['notify'][$notifySettingName];
307 }
308
309 if (isset($userSettings['notify']) && array_key_exists($clientId.'|im|default', $userSettings['notify']))
310 {
311 return $userSettings['notify'][$clientId.'|im|default'];
312 }
313 }
314
315 return false;
316 }
317
318 public static function GetDefaultSettings($type)
319 {
320 $defaultSettings = [];
321 if ($type === self::SETTINGS)
322 {
323 $defaultSettings = General::getDefaultSettings();
324 }
325 elseif ($type === self::NOTIFY)
326 {
327 $notificationSettings = Notification::getDefaultSettings();
328 $defaultSettings = self::convertNotifySettingsToOldFormat($notificationSettings);
329 }
330
331 return $defaultSettings;
332 }
333
334 public static function CheckValues($type, $value)
335 {
336 $checkedValues = [];
337
338 $defaultSettings = self::GetDefaultSettings($type);
339 if ($type === self::SETTINGS)
340 {
341 foreach($defaultSettings as $key => $default)
342 {
343 if ($key === 'status')
344 {
345 $checkedValues[$key] = in_array($value[$key], ['online', 'dnd', 'away'])? $value[$key]: $default;
346 }
347 else if ($key === 'panelPositionHorizontal')
348 {
349 $checkedValues[$key] = in_array($value[$key], ['left', 'center', 'right'])? $value[$key]: $default;
350 }
351 else if ($key === 'panelPositionVertical')
352 {
353 $checkedValues[$key] = in_array($value[$key], ['top', 'bottom'])? $value[$key]: $default;
354 }
355 else if ($key === 'notifyScheme')
356 {
357 $checkedValues[$key] = in_array($value[$key], ['simple', 'expert'])? $value[$key]: $default;
358 }
359 else if ($key === 'enableDarkTheme')
360 {
361 $checkedValues[$key] = in_array($value[$key], ['auto', 'light', 'dark']) ? $value[$key] : $default;
362 }
363 else if (in_array($key, ['privacyMessage', 'privacyChat', 'privacyCall', 'privacySearch']))
364 {
365 $checkedValues[$key] =
366 in_array($value[$key], [self::PRIVACY_RESULT_ALL, self::PRIVACY_RESULT_CONTACT])
367 ? $value[$key]
368 : $default
369 ;
370 }
371 else if ($key === 'privacyProfile')
372 {
373 $checkedValues[$key] =
374 in_array($value[$key], [
375 self::PRIVACY_RESULT_ALL,
376 self::PRIVACY_RESULT_CONTACT,
377 self::PRIVACY_RESULT_NOBODY
378 ],
379 true)
380 ? $value[$key]
381 : $default
382 ;
383 }
384 else if ($key === 'sendByEnter' && $value[$key] === 'Y') // for legacy
385 {
386 $checkedValues[$key] = true;
387 }
388 else if ($key === 'enableSound' && $value[$key] === 'N') // for legacy
389 {
390 $checkedValues[$key] = false;
391 }
392 else if ($key === 'backgroundImage')
393 {
394 $checkedValues[$key] = $value[$key];
395 }
396 else if ($key === 'notifySchemeLevel')
397 {
398 $checkedValues[$key] = in_array($value[$key], ['normal', 'important'])? $value[$key]: $default;
399 }
400 else if ($key === 'trackStatus')
401 {
402 $value[$key] = explode(',', $value[$key]);
403 foreach ($value[$key] as $k => $v)
404 {
405 if ($v !== 'all')
406 {
407 $value[$key][$k] = intval($v);
408 if ($value[$key][$k] == 0)
409 {
410 unset($value[$key][$k]);
411 }
412 }
413 }
414 $checkedValues[$key] = implode(',', $value[$key]);
415
416 }
417 else if ($key === 'callAcceptIncomingVideo')
418 {
419 $checkedValues[$key] = in_array($value[$key], VideoStrategyType::getList())? $value[$key]: $default;
420 }
421 else if (array_key_exists($key, $value))
422 {
423 $checkedValues[$key] = is_bool($value[$key])? $value[$key]: $default;
424 }
425 else
426 {
427 $checkedValues[$key] = $default;
428 }
429 }
430 }
431 else if ($type === self::NOTIFY)
432 {
433 foreach($defaultSettings as $key => $default)
434 {
435 if (array_key_exists($key, $value))
436 {
437 $checkedValues[$key] = is_bool($value[$key]) ? $value[$key] : $default;
438 }
439 else
440 {
441 $checkedValues[$key] = $default;
442 }
443 }
444 }
445
446 return $checkedValues;
447 }
448
449 public static function GetNotifyNames()
450 {
451 return Notification::getEventNames();
452 }
453
454 public static function GetSimpleNotifyBlocked($byModule = false)
455 {
456 $arNotifyBlocked = [];
457
458 $arSettings = self::Get();
459
460 if ($arSettings[self::SETTINGS]['notifyScheme'] === 'expert')
461 {
462 foreach ($arSettings[self::NOTIFY] as $key => $value)
463 {
464 if ($value === false)
465 {
466 [$clientId, $moduleId, $notifyId] = explode('|', $key, 3);
467 if ($clientId === self::CLIENT_SITE)
468 {
470 {
471 continue;
472 }
473 if ($byModule)
474 {
475 $arNotifyBlocked[$moduleId][$notifyId] = false;
476 }
477 else
478 {
479 $arNotifyBlocked[$moduleId . '|' . $notifyId] = false;
480 }
481 }
482 }
483 }
484 }
485 else
486 {
487 foreach ($arSettings[self::NOTIFY] as $key => $value)
488 {
489 if ($value === false)
490 {
491 [$clientId, $moduleId, $notifyId] = explode('|', $key, 3);
492 if (in_array($clientId, ['push', 'important', 'disabled']))
493 {
494 continue;
495 }
496
497 if ($clientId === self::CLIENT_SITE)
498 {
500 {
501 continue;
502 }
503 if ($byModule)
504 {
505 $arNotifyBlocked[$moduleId][$notifyId] = false;
506 }
507 else
508 {
509 $arNotifyBlocked[$moduleId . '|' . $notifyId] = false;
510 }
511 }
512 }
513 }
514 }
515
516 return $arNotifyBlocked;
517 }
518
519 public static function GetPrivacy($type, $userId = false)
520 {
521 $userId = $userId === false ? null : $userId;
522 $userId = Common::getUserId($userId);
523
524 if (!$userId)
525 {
526 return null;
527 }
528
529 if (Manager::isSettingsMigrated() || Manager::isUserMigrated($userId))
530 {
531 return General::createWithUserId($userId)->getValue($type);
532 }
533
535
536 return array_key_exists($type, $ar[CIMSettings::SETTINGS])? $ar[CIMSettings::SETTINGS][$type]: false;
537 }
538
539 public static function GetStartChatMessage()
540 {
541 return COption::GetOptionString("im", 'start_chat_message');
542 }
543
544 public static function ClearCache($userId = false)
545 {
546 return true;
547 }
548
549 private static function convertNotifySettingsToNewFormat(array $settings, $needReplace = true): array
550 {
551 $defaultSettings = Notification::getDefaultSettings();
552
553 $newFormatSettings = [];
554 foreach ($settings as $name => $value)
555 {
556 [$type, $module, $event] = explode('|', $name, 3);
557
558 switch ($type)
559 {
560 case 'site':
561 $type = 1;
562
563 break;
564 case 'email':
565 $type = 2;
566
567 break;
568 case 'xmpp':
569 $type = 3;
570
571 break;
572 case 'push':
573 $type = 4;
574
575 break;
576 }
577 $newName = implode('|', ['no', $module, $event, $type]);
578
579 $newFormatSettings[] = [
580 'NAME' => $newName,
581 'VALUE' => $value ? 'Y' : 'N'
582 ];
583 }
584 $newSettings = Notification::decodeSettings($newFormatSettings);
585
586 return $needReplace
587 ? array_replace_recursive($defaultSettings, $newSettings)
588 : $newSettings
589 ;
590 }
591
593 {
594 $formattedSettings = [];
595 foreach ($settings as $moduleId => $notifyTypes)
596 {
597 foreach ($notifyTypes['NOTIFY'] as $eventName => $eventValue)
598 {
599 $siteName = self::CLIENT_SITE.'|'.$moduleId.'|'.$eventName;
600 $mailName = self::CLIENT_MAIL.'|'.$moduleId.'|'.$eventName;
601 $xmppName = self::CLIENT_XMPP.'|'.$moduleId.'|'.$eventName;
602 $pushName = self::CLIENT_PUSH.'|'.$moduleId.'|'.$eventName;
603
604 $formattedSettings[$siteName] = $eventValue['SITE'];
605 $formattedSettings[$mailName] = $eventValue['MAIL'];
606 $formattedSettings[$xmppName] = $eventValue['XMPP'];
607 $formattedSettings[$pushName] = $eventValue['PUSH'];
608
609 if (isset($eventValue['DISABLED']))
610 {
611 $formattedSettings['disabled|'.$siteName] = $eventValue['DISABLED']['SITE'];
612 $formattedSettings['disabled|'.$mailName] = $eventValue['DISABLED']['MAIL'];
613 $formattedSettings['disabled|'.$xmppName] = $eventValue['DISABLED']['XMPP'];
614 $formattedSettings['disabled|'.$pushName] = $eventValue['DISABLED']['PUSH'];
615 }
616
617 $formattedSettings['important|'.$moduleId.'|'.$eventName] =
618 isset($eventValue['IMPORTANT']) && is_bool($eventValue['IMPORTANT'])
619 ? $eventValue['IMPORTANT']
620 : true;
621 }
622 }
623 return $formattedSettings;
624 }
625
626}
$type
Определения options.php:106
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения common.php:7
Определения event.php:5
static CheckDisableFeature($moduleId, $notifyEvent, $feature)
Определения im_notify_schema.php:25
Определения im_settings.php:11
static GetNotifyAccess($userId, $moduleId, $eventId, $clientId)
Определения im_settings.php:255
const CLIENT_SITE
Определения im_settings.php:15
static GetSimpleNotifyBlocked($byModule=false)
Определения im_settings.php:454
const PRIVACY_RESULT_ALL
Определения im_settings.php:28
const PRIVACY_RESULT_CONTACT
Определения im_settings.php:29
static GetSetting($type, $value, $userId=false)
Определения im_settings.php:223
static ClearCache($userId=false)
Определения im_settings.php:544
const PRIVACY_MESSAGE
Определения im_settings.php:23
const NOTIFY
Определения im_settings.php:13
const CLIENT_PUSH
Определения im_settings.php:18
static GetPrivacy($type, $userId=false)
Определения im_settings.php:519
const PRIVACY_PROFILE
Определения im_settings.php:27
const START_MESSAGE_LAST
Определения im_settings.php:21
const CLIENT_MAIL
Определения im_settings.php:17
static SetSetting($type, $value, $userId=false)
Определения im_settings.php:144
const CLIENT_XMPP
Определения im_settings.php:16
const PRIVACY_RESULT_NOBODY
Определения im_settings.php:30
static Set($type, $value, $userId=false)
Определения im_settings.php:73
static GetStartChatMessage()
Определения im_settings.php:539
static GetDefaultSettings($type)
Определения im_settings.php:318
static convertNotifySettingsToOldFormat(array $settings)
Определения im_settings.php:592
const PRIVACY_SEARCH
Определения im_settings.php:26
const PRIVACY_CALL
Определения im_settings.php:25
const SETTINGS
Определения im_settings.php:12
static CheckValues($type, $value)
Определения im_settings.php:334
const PRIVACY_CHAT
Определения im_settings.php:24
static GetNotifyNames()
Определения im_settings.php:449
const START_MESSAGE_FIRST
Определения im_settings.php:20
const STATUS
Определения im_settings.php:32
static Get($userId=false)
Определения im_settings.php:34
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
global $USER_FIELD_MANAGER
Определения attempt.php:6
$result
Определения get_property_values.php:14
$moduleId
Get()
Определения idea_idea_comment.php:22
$name
Определения menu_edit.php:35
$value
Определения Param.php:39
$settings
Определения product_settings.php:43
$event
Определения prolog_after.php:141
return false
Определения prolog_main_admin.php:185
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
if(empty($signedUserToken)) $key
Определения quickway.php:257
$option
Определения options.php:1711
$val
Определения options.php:1793
$clientId
Определения seo_client.php:18
$k
Определения template_pdf.php:567