1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Manager.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\Configuration;
4
5use Bitrix\Im\Common;
6use Bitrix\Im\V2\Settings\CacheManager;
7use Bitrix\Main\ArgumentException;
8use Bitrix\Main\Error;
9use Bitrix\Main\ObjectPropertyException;
10use Bitrix\Main\Result;
11use Bitrix\Main\SystemException;
12use Bitrix\Pull\Event;
13use CModule;
14use COption;
15
17{
18 private const GENERAL = 'general';
19 private const NOTIFY = 'notify';
20
21 private const PRIVACY_SEARCH = 'privacySearch';
22 private const STATUS = 'status';
23
24 public static function getUserSettings(int $userId): Result
25 {
26 $result = new Result();
27 try
28 {
30 }
32 {
33 $result->addError(new Error($exception->getMessage(), $exception->getCode()));
34 return $result;
35 }
36
37 $result->setData($preset);
38 return $result;
39 }
40
49 public static function setUserSettings(int $userId, array $settings): Result
50 {
51 $result = new Result();
52 if (
53 !array_key_exists(self::NOTIFY, $settings)
54 || !array_key_exists(self::GENERAL, $settings)
55 )
56 {
57 $result->addError(new Error('Incorrect data when receiving chat settings', 400));
58 return $result;
59 }
60
61 self::updateUserStatus($userId, $settings['general']);
62
63 self::sendSettingsChangeEvent($userId, $settings['general']);
64
65 self::disableUserSearch($userId, $settings['general']);
66
67 if (isset($settings['general']['notifyScheme']) && $settings['general']['notifyScheme'] === 'simple')
68 {
70 }
71
72 $userPresetId =
74 ->addSelect('ID')
75 ->where('USER_ID', $userId)
76 ->fetch()
77 ;
78
79 if (!$userPresetId)
80 {
82
83 CacheManager::getUserCache($userId)->clearCache();
84 self::enableUserSearch($userId, $settings['general']);
85
86 return $result;
87 }
88
89 $userPresetId = $userPresetId['ID'];
92
93 CacheManager::getPresetCache($userPresetId)->clearCache();
94
95 self::enableUserSearch($userId, $settings['general']);
96
97 return $result;
98 }
99
100 public static function setUserSetting(int $userId, string $type, array $settings): Result
101 {
102 $result = new Result();
103 if (!in_array($type, [self::NOTIFY, self::GENERAL], true))
104 {
105 $result->addError(new Error('Incorrect data when receiving chat settings', 400));
106 return $result;
107 }
108
109 $userPresetId =
111 ->addSelect('ID')
112 ->where('USER_ID', $userId)
113 ->fetch()
114 ;
115 $userPresetId = $userPresetId['ID'] ?? null;
116
117 if ($type === self::NOTIFY)
118 {
119 if (!$userPresetId)
120 {
121 $preset['notify'] = $settings;
122 $preset['general'] = [];
124
125 return $result;
126 }
128 }
129
130 if ($type === self::GENERAL)
131 {
132 self::updateUserStatus($userId, $settings);
133
134 self::sendSettingsChangeEvent($userId, $settings);
135
136 self::disableUserSearch($userId, $settings);
137
138 if (!$userPresetId)
139 {
140 $preset['general'] = array_replace_recursive(General::getDefaultSettings(), $settings);
141 $preset['notify'] = [];
143
144 return $result;
145 }
147
148 self::enableUserSearch($userId, $settings);
149 }
150
151 CacheManager::getPresetCache($userPresetId)->clearCache();
152 CacheManager::getUserCache($userId)->clearCache();
153
154 return $result;
155 }
156
157 public static function isSettingsMigrated(): bool
158 {
159 return
160 COption::GetOptionString('im', 'migration_to_new_settings') === 'Y'
161 || COption::GetOptionString('im', \Bitrix\Im\Configuration\Configuration::DEFAULT_PRESET_SETTING_NAME, null) !== null
162 ;
163 }
164
165 public static function isUserMigrated(int $userId): bool
166 {
167 $lastConvertedId = COption::GetOptionInt('im', 'last_converted_user');
168 return $userId < $lastConvertedId;
169 }
170
171 public static function getNotifyAccess($userId, $moduleId, $eventId, $type)
172 {
173 $generalSettings = General::createWithUserId($userId);
174 $notifyScheme = $generalSettings->getValue('notifyScheme');
175
176 if ($notifyScheme !== 'expert')
177 {
179 {
180 return $generalSettings->getValue('notifySchemeSendSite');
181 }
183 {
184 return $generalSettings->getValue('notifySchemeSendEmail');
185 }
187 {
188 return $generalSettings->getValue('notifySchemeSendPush');
189 }
191 {
192 return $generalSettings->getValue('notifySchemeSendXmpp');
193 }
194 }
195
196 return (new Notification($moduleId, $eventId))->isAllowed($userId, $type);
197 }
198
199 private static function sendSettingsChangeEvent(int $userId, array $generalSettings): void
200 {
201 // TODO: refactoring required for the new interface
202 if (isset($generalSettings['openDesktopFromPanel']) && CModule::IncludeModule('pull'))
203 {
204 Event::add($userId, [
205 'module_id' => 'im',
206 'command' => 'settingsUpdate',
207 'expiry' => 5,
208 'params' => [
209 'openDesktopFromPanel' => $generalSettings['openDesktopFromPanel'],
210 ],
211 'extra' => Common::getPullExtra()
212 ]);
213 }
214 }
215
216 private static function disableUserSearch(int $userId, array $generalSettings): void
217 {
218 $defaultSettings = General::getDefaultSettings();
219 if (
220 array_key_exists(self::PRIVACY_SEARCH, $generalSettings)
221 && $defaultSettings[self::PRIVACY_SEARCH] === $generalSettings[self::PRIVACY_SEARCH]
222 )
223 {
224 global $USER_FIELD_MANAGER;
225 $USER_FIELD_MANAGER->Update("USER", $userId, ['UF_IM_SEARCH' => '']);
226 }
227 }
228
229 private static function enableUserSearch(int $userId, array $generalSettings): void
230 {
231 if (isset($generalSettings[self::PRIVACY_SEARCH]))
232 {
233 global $USER_FIELD_MANAGER;
234 $USER_FIELD_MANAGER->Update(
235 "USER",
236 $userId,
237 [
238 'UF_IM_SEARCH' => $generalSettings[self::PRIVACY_SEARCH],
239 ]
240 );
241 }
242 }
243
244 private static function updateUserStatus(int $userId, array $generalSettings): void
245 {
246 if (isset($generalSettings[self::STATUS]))
247 {
248 \CIMStatus::Set($userId, ['STATUS' => $generalSettings[self::STATUS]]);
249 }
250 }
251
252}
$type
Определения options.php:106
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getPullExtra()
Определения common.php:127
static chooseExistingPreset(int $presetId, int $userId)
Определения Configuration.php:659
static createUserPreset(int $userId, array $settings=[])
Определения Configuration.php:363
static updatePresetSettings(int $presetId, int $modifyId, array $settings)
Определения Configuration.php:550
static getUserPreset(int $userId)
Определения Configuration.php:108
static createWithUserId(int $userId)
Определения General.php:44
static updateGroupSettings(int $groupId, array $settings)
Определения General.php:478
static getDefaultSettings()
Определения General.php:95
static getUserSettings(int $userId)
Определения Manager.php:24
static isUserMigrated(int $userId)
Определения Manager.php:165
static getNotifyAccess($userId, $moduleId, $eventId, $type)
Определения Manager.php:171
static setUserSetting(int $userId, string $type, array $settings)
Определения Manager.php:100
static setUserSettings(int $userId, array $settings)
Определения Manager.php:49
static isSettingsMigrated()
Определения Manager.php:157
static updateGroupSettings(int $groupId, array $settings)
Определения Notification.php:543
static getSimpleNotifySettings(array $generalSettings)
Определения Notification.php:404
Определения result.php:20
Определения error.php:15
</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
$settings
Определения product_settings.php:43