1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
usersettings.php
См. документацию.
1<?php
2namespace Bitrix\Calendar;
3
4use Bitrix\Calendar\Core\Event\Tools\Dictionary;
5use Bitrix\Calendar\Integration\Pull\PushCommand;
6use Bitrix\Main\Loader;
7use Bitrix\Main\Web\Json;
8
10{
11 private static array $settings = [
12 'view' => 'month',
13 'CalendarSelCont' => false,
14 'SPCalendarSelCont' => false,
15 'meetSection' => false,
16 'crmSection' => false,
17 'showDeclined' => false,
18 'denyBusyInvitation' => false,
19 'collapseOffHours' => 'Y',
20 'showWeekNumbers' => 'N',
21 'showTasks' => 'Y',
22 'syncTasks' => 'N',
23 'showCompletedTasks' => 'N',
24 'lastUsedSection' => false,
25 'sendFromEmail' => false,
26 'defaultSections' => [],
27 'syncPeriodPast' => 3,
28 'syncPeriodFuture' => 12,
29 'defaultReminders' => [
30 'fullDay' => [
31 'type' => 'daybefore',
32 'before' => 0,
33 'time' => 480,
34 ],
35 'withTime' => [
36 'type' => 'min',
37 'count' => 15
38 ]
39 ],
40 // 'enableLunchTime' => 'N',
41 // 'lunchStart' => '13:00',
42 // 'lunchEnd' => '14:00',
43 ];
44
45 private static array $serializedSettings = [
46 'defaultSections',
47 'defaultReminders',
48 ];
49
50 public static function set($settings = [], $userId = false): void
51 {
52 if (!$userId)
53 {
54 $userId = \CCalendar::getUserId();
55 }
56 if (!$userId)
57 {
58 return;
59 }
60
61 if ($settings === false)
62 {
63 \CUserOptions::setOption("calendar", "user_settings", false, false, $userId);
64 }
65 elseif (is_array($settings))
66 {
67 $curSet = self::get($userId);
68 foreach($settings as $optionName => $value)
69 {
70 if (isset(self::$settings[$optionName]))
71 {
72 if (is_array($value) && in_array($optionName, self::$serializedSettings, true))
73 {
74 $curSet[$optionName] = Json::encode($value);
75 }
76 else
77 {
78 $curSet[$optionName] = $value;
79 }
80 }
81 }
82 \CUserOptions::setOption("calendar", "user_settings", $curSet, false, $userId);
83 }
84 }
85
86 public static function get($userId = null): array
87 {
88 if (!$userId)
89 {
90 $userId = \CCalendar::getUserId();
91 }
92
93 $resSettings = self::$settings;
94
95 if ($userId)
96 {
97 $settings = \CUserOptions::getOption("calendar", "user_settings", false, $userId);
98 if (is_array($settings))
99 {
100 foreach($settings as $optionName => $value)
101 {
102 if (!is_array($value) && in_array($optionName, self::$serializedSettings, true))
103 {
104 $resSettings[$optionName] = Json::decode($value);
105 }
106 else
107 {
108 $resSettings[$optionName] = $value;
109 }
110 }
111 }
112
113 $resSettings['timezoneName'] = \CCalendar::getUserTimezoneName($userId);
114 $resSettings['timezoneOffsetUTC'] = \CCalendar::getCurrentOffsetUTC($userId);
115 $resSettings['timezoneDefaultName'] = '';
116
117 if (isset($settings['denyBusyInvitation']))
118 {
119 $resSettings['denyBusyInvitation'] = (bool)$settings['denyBusyInvitation'];
120 }
121
122 if (isset($settings['showDeclined']))
123 {
124 $resSettings['showDeclined'] = (bool)$settings['showDeclined'];
125 }
126
127 // We don't have default timezone for this offset for this user
128 // We will ask him but we should suggest some suitable for his offset
129 if (!$resSettings['timezoneName'])
130 {
131 $resSettings['timezoneDefaultName'] = \CCalendar::getGoodTimezoneForOffset($resSettings['timezoneOffsetUTC']);
132 }
133
134 $workTime = \CUserOptions::getOption("calendar", "workTime", false, $userId);
135 if ($workTime)
136 {
137 $resSettings['work_time_start'] = $workTime['start'].'.00';
138 $resSettings['work_time_end'] = $workTime['end'].'.00';
139 }
140 }
141
142 return $resSettings;
143 }
144
145 public static function getFormSettings($formType, $userId = false, ?string $entryType = null)
146 {
147 if (!$userId)
148 {
149 $userId = \CCalendar::getUserId();
150 }
151
152 $defaultPinnedFields = ['location', 'rrule', 'section'];
153 if ($entryType === Dictionary::CALENDAR_TYPE['open_event'])
154 {
155 $pinnedFields = [...$defaultPinnedFields, 'description'];
156 }
157 else
158 {
159 $pinnedFields = $defaultPinnedFields;
160 }
162 'slider_main' => [
163 'pinnedFields' => implode(',', $pinnedFields),
164 ]
165 ];
166 if (!isset($defaultValues[$formType]))
167 {
168 $defaultValues[$formType] = false;
169 }
170 //\CUserOptions::DeleteOption("calendar", $formType);
171 $userOptionName = $entryType ? sprintf('%s-%s', $formType, $entryType) : $formType;
172 $settings = \CUserOptions::getOption("calendar", $userOptionName, $defaultValues[$formType], $userId);
173 if (!is_array($settings['pinnedFields']))
174 {
175 $settings['pinnedFields'] = explode(',', $settings['pinnedFields']);
176 }
177 return $settings;
178 }
179
180 public static function getTrackingUsers($userId = false, $params = [])
181 {
182 if (!$userId)
183 {
184 $userId = \CCalendar::getUserId();
185 }
186
187 $res = [];
188 $str = \CUserOptions::getOption("calendar", "superpose_tracking_users", false, $userId);
189
190 if ($str !== false && CheckSerializedData($str))
191 {
192 $ids = unserialize($str, ['allowed_classes' => false]);
193 if (is_array($ids) && count($ids) > 0)
194 {
195 foreach($ids as $id)
196 {
197 if ((int)$id > 0)
198 {
199 $res[] = (int)$id;
200 }
201 }
202 }
203 }
204 if (is_array($res) && !in_array($userId, $res))
205 {
206 $res[] = $userId;
207 }
208
209 if (isset($params['userList']))
210 {
211 $params['userList'] = array_unique($params['userList']);
212 $diff = array_diff($params['userList'], $res);
213 if (count($diff) > 0)
214 {
215 $res = array_merge($res, $diff);
217 }
218 }
219
221 [
222 'filter' => ['ID' => $res],
223 'select' => ['ID', 'LOGIN', 'NAME', 'LAST_NAME', 'SECOND_NAME']
224 ]
225 );
226
227 $trackedUsers = [];
228 while ($user = $res->fetch())
229 {
230 $user['FORMATTED_NAME'] = \CCalendar::GetUserName($user);
231 $trackedUsers[] = $user;
232 }
233
234 return $trackedUsers;
235 }
236
237 public static function setTrackingUsers($userId = false, $value = [])
238 {
239 if (!$userId)
240 {
241 $userId = \CCalendar::getUserId();
242 }
243
244 if (!is_array($value))
245 {
246 $value = [];
247 }
248 array_walk($value, 'intval');
249 $value = array_unique($value);
250
251 \CUserOptions::setOption("calendar", "superpose_tracking_users", serialize($value), false, $userId);
252 }
253
254 public static function getHiddenSections($userId = false, $options = []): array
255 {
256 $res = [];
257 if (class_exists('CUserOptions') && $userId > 0)
258 {
259 $optionName = ($options['isPersonalCalendarContext'] ?? null) ? 'hidden_sections' : 'hidden_sections_'.$options['type'];
260 $res = \CUserOptions::getOption('calendar', $optionName, false, $userId);
261
262 if (is_array($res) && isset($res[$optionName]) && is_string($res[$optionName]))
263 {
264 $res = explode(',', $res[$optionName]);
265 }
266
267 if ($res === false && isset($options['defaultHiddenSections']) && is_array($options['defaultHiddenSections']))
268 {
269 $res = $options['defaultHiddenSections'];
270 }
271
272 if (is_array($res))
273 {
274 $res = array_values(array_unique(array_filter($res, function($k) {
275 return $k === 'tasks' || is_numeric($k);
276 })));
277 }
278 }
279
280 return is_array($res) ? $res : [];
281 }
282
283 public static function saveHiddenSections(int $userId, array $sections, string $optionName = 'hidden_sections')
284 {
285 \CUserOptions::SetOption('calendar', $optionName, $sections, false, $userId);
286 }
287
288 public static function getSectionCustomization($userId = false)
289 {
290 /*
291 * \CUserOptions::setOption("calendar", "section_customization", serialize(['tasks' => ['name' => 'Custom task name', 'color' =>
292 '#FF22FF']]), false, $userId);
293 */
294
295 $result = [];
296 $str = \CUserOptions::getOption("calendar", "section_customization", false, $userId);
297 if ($str !== false && CheckSerializedData($str))
298 {
299 $result = unserialize($str, ['allowed_classes' => false]);
300 }
301
302 return $result;
303 }
304
305 public static function setSectionCustomization($userId = false, $data = [])
306 {
307 $sectionCustomization = self::getSectionCustomization($userId);
308
309 foreach($data as $sectionId => $config)
310 {
311 if (isset($sectionCustomization[$sectionId]) && $config === false)
312 {
313 unset($sectionCustomization[$sectionId]);
314 }
315 else
316 {
317 $sectionCustomization[$sectionId] = $config;
318 }
319 }
320
321 \CUserOptions::setOption("calendar", "section_customization", serialize($sectionCustomization), false, $userId);
322
324 PushCommand::ChangeSectionCustomization,
325 $userId,
326 );
327 }
328
329
330 public static function getFollowedSectionIdList($userId = false): array
331 {
332 $sectionIdList = [];
333 if ($userId)
334 {
335 $defaultFollowedSectionId = (int)\CUserOptions::GetOption(
336 "calendar", "superpose_displayed_default", 0, $userId
337 );
338 if ($defaultFollowedSectionId)
339 {
340 $sectionIdList[] = $defaultFollowedSectionId;
341 }
342
343 $str = \CUserOptions::GetOption("calendar", "superpose_displayed", false, $userId);
345 {
346 $idList = unserialize($str, ['allowed_classes' => false]);
347 if (is_array($idList))
348 {
349 foreach($idList as $id)
350 {
351 if ((int)$id > 0)
352 {
353 $sectionIdList[] = (int)$id;
354 }
355 }
356 }
357 }
358
359 if ($defaultFollowedSectionId)
360 {
361 \CUserOptions::SetOption("calendar", "superpose_displayed", serialize($sectionIdList));
362 \CUserOptions::SetOption("calendar", "superpose_displayed_default", false);
363 }
364 }
365 return $sectionIdList;
366 }
367}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getFormSettings($formType, $userId=false, ?string $entryType=null)
Определения usersettings.php:145
static getFollowedSectionIdList($userId=false)
Определения usersettings.php:330
static getSectionCustomization($userId=false)
Определения usersettings.php:288
static setTrackingUsers($userId=false, $value=[])
Определения usersettings.php:237
static saveHiddenSections(int $userId, array $sections, string $optionName='hidden_sections')
Определения usersettings.php:283
static get($userId=null)
Определения usersettings.php:86
static setSectionCustomization($userId=false, $data=[])
Определения usersettings.php:305
static getHiddenSections($userId=false, $options=[])
Определения usersettings.php:254
static getTrackingUsers($userId=false, $params=[])
Определения usersettings.php:180
static addPullEvent(PushCommand $command, int $userId, array $params=[])
Определения util.php:385
static getList(array $parameters=array())
Определения datamanager.php:431
$options
Определения commerceml2.php:49
$str
Определения commerceml2.php:63
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$defaultValues
Определения iblock_catalog_edit.php:124
CheckSerializedData($str, $max_depth=200)
Определения tools.php:4949
$user
Определения mysql_to_pgsql.php:33
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$config
Определения quickway.php:69
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$optionName
Определения options.php:1735
$k
Определения template_pdf.php:567