Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
usersettings.php
1<?php
2namespace Bitrix\Calendar;
4use \Bitrix\Main\Web\Json;
5
7{
8 private static
9 $settings = [
10 'view' => 'month',
11 'CalendarSelCont' => false,
12 'SPCalendarSelCont' => false,
13 'meetSection' => false,
14 'crmSection' => false,
15 'showDeclined' => false,
16 'denyBusyInvitation' => false,
17 'collapseOffHours' => 'Y',
18 'showWeekNumbers' => 'N',
19 'showTasks' => 'Y',
20 'syncTasks' => 'N',
21 'showCompletedTasks' => 'N',
22 'lastUsedSection' => false,
23 'sendFromEmail' => false,
24 'defaultSections' => [],
25 'syncPeriodPast' => 3,
26 'syncPeriodFuture' => 12,
27 'defaultReminders' => [
28 'fullDay' => [
29 'type' => 'daybefore',
30 'before' => 0,
31 'time' => 480,
32 ],
33 'withTime' => [
34 'type' => 'min',
35 'count' => 15
36 ]
37 ],
38 // 'enableLunchTime' => 'N',
39 // 'lunchStart' => '13:00',
40 // 'lunchEnd' => '14:00',
41 ];
42
43 public static function set($settings = [], $userId = false)
44 {
45 if (!$userId)
46 $userId = \CCalendar::getUserId();
47 if (!$userId)
48 return;
49
50 if ($settings === false)
51 {
52 \CUserOptions::setOption("calendar", "user_settings", false, false, $userId);
53 }
54 elseif(is_array($settings))
55 {
56 $curSet = self::get($userId);
57 foreach($settings as $optionName => $value)
58 {
59 if (isset(self::$settings[$optionName]))
60 {
61 if (
62 ($optionName === 'defaultSections' || $optionName === 'defaultReminders')
63 && is_array($value)
64 )
65 {
66 $curSet[$optionName] = Json::encode($value);
67 }
68 else
69 {
70 $curSet[$optionName] = $value;
71 }
72 }
73 }
74 \CUserOptions::setOption("calendar", "user_settings", $curSet, false, $userId);
75 }
76 }
77
78 public static function get($userId = null)
79 {
80 if (!$userId)
81 {
82 $userId = \CCalendar::getUserId();
83 }
84
85 $resSettings = self::$settings;
86
87 if ($userId)
88 {
89 $settings = \CUserOptions::getOption("calendar", "user_settings", false, $userId);
90 if (is_array($settings))
91 {
92 foreach($settings as $optionName => $value)
93 {
94 if (
95 ($optionName === 'defaultSections' || $optionName === 'defaultReminders')
96 && !is_array($value)
97 )
98 {
99 $resSettings[$optionName] = Json::decode($value);
100 }
101 else
102 {
103 $resSettings[$optionName] = $value;
104 }
105 }
106 }
107
108 $resSettings['timezoneName'] = \CCalendar::getUserTimezoneName($userId);
109 $resSettings['timezoneOffsetUTC'] = \CCalendar::getCurrentOffsetUTC($userId);
110 $resSettings['timezoneDefaultName'] = '';
111
112 if (isset($settings['denyBusyInvitation']))
113 {
114 $resSettings['denyBusyInvitation'] = !!$settings['denyBusyInvitation'];
115 }
116
117 if (isset($settings['showDeclined']))
118 {
119 $resSettings['showDeclined'] = !!$settings['showDeclined'];
120 }
121
122 // We don't have default timezone for this offset for this user
123 // We will ask him but we should suggest some suitable for his offset
124 if (!$resSettings['timezoneName'])
125 {
126 $resSettings['timezoneDefaultName'] = \CCalendar::getGoodTimezoneForOffset($resSettings['timezoneOffsetUTC']);
127 }
128
129 $workTime = \CUserOptions::getOption("calendar", "workTime", false, $userId);
130 if ($workTime)
131 {
132 $resSettings['work_time_start'] = $workTime['start'].'.00';
133 $resSettings['work_time_end'] = $workTime['end'].'.00';
134 }
135 }
136
137 return $resSettings;
138 }
139
140 public static function getFormSettings($formType, $userId = false)
141 {
142 if (!$userId)
143 {
144 $userId = \CCalendar::getUserId();
145 }
146
147 $defaultValues = [
148 'slider_main' => [
149 'pinnedFields' => implode(',', ['location', 'rrule', 'section'])
150 ]
151 ];
152 if (!isset($defaultValues[$formType]))
153 {
154 $defaultValues[$formType] = false;
155 }
156 //\CUserOptions::DeleteOption("calendar", $formType);
157 $settings = \CUserOptions::getOption("calendar", $formType, $defaultValues[$formType], $userId);
158 if (!is_array($settings['pinnedFields']))
159 {
160 $settings['pinnedFields'] = explode(',', $settings['pinnedFields']);
161 }
162 return $settings;
163 }
164
165 public static function getTrackingUsers($userId = false, $params = [])
166 {
167 if (!$userId)
168 {
169 $userId = \CCalendar::getUserId();
170 }
171
172 $res = [];
173 $str = \CUserOptions::getOption("calendar", "superpose_tracking_users", false, $userId);
174
175 if ($str !== false && CheckSerializedData($str))
176 {
177 $ids = unserialize($str, ['allowed_classes' => false]);
178 if (is_array($ids) && count($ids) > 0)
179 {
180 foreach($ids as $id)
181 {
182 if ((int)$id > 0)
183 {
184 $res[] = (int)$id;
185 }
186 }
187 }
188 }
189 if (is_array($res) && !in_array($userId, $res))
190 {
191 $res[] = $userId;
192 }
193
194 if (isset($params['userList']))
195 {
196 $params['userList'] = array_unique($params['userList']);
197 $diff = array_diff($params['userList'], $res);
198 if (count($diff) > 0)
199 {
200 $res = array_merge($res, $diff);
201 self::setTrackingUsers($userId, $res);
202 }
203 }
204
205 $res = \Bitrix\Main\UserTable::getList(
206 [
207 'filter' => ['ID' => $res],
208 'select' => ['ID', 'LOGIN', 'NAME', 'LAST_NAME', 'SECOND_NAME']
209 ]
210 );
211
212 $trackedUsers = [];
213 while ($user = $res->fetch())
214 {
215 $user['FORMATTED_NAME'] = \CCalendar::GetUserName($user);
216 $trackedUsers[] = $user;
217 }
218
219 return $trackedUsers;
220 }
221
222 public static function setTrackingUsers($userId = false, $value = [])
223 {
224 if (!$userId)
225 {
226 $userId = \CCalendar::getUserId();
227 }
228
229 if (!is_array($value))
230 {
231 $value = [];
232 }
233 array_walk($value, 'intval');
234 $value = array_unique($value);
235
236 \CUserOptions::setOption("calendar", "superpose_tracking_users", serialize($value), false, $userId);
237 }
238
239 public static function getTrackingGroups($userId = false, $params = [])
240 {
241 $res = [];
242 $str = \CUserOptions::getOption("calendar", "superpose_tracking_groups", false, $userId);
243
244 if ($str !== false && CheckSerializedData($str))
245 {
246 $ids = unserialize($str, ['allowed_classes' => false]);
247 if (is_array($ids))
248 {
249 foreach($ids as $id)
250 {
251 if (intval($id) > 0)
252 {
253 $res[] = intval($id);
254 }
255 }
256 }
257 }
258
259 if ($params && isset($params['groupList']))
260 {
261 $params['groupList'] = array_unique($params['groupList']);
262 $diff = array_diff($params['groupList'], $res);
263 if (count($diff) > 0)
264 {
265 $res = array_merge($res, $diff);
266 self::setTrackingGroups($userId, $res);
267 }
268 }
269
270 return $res;
271 }
272 public static function setTrackingGroups($userId = false, $value = [])
273 {
274 if (!$userId)
275 {
276 $userId = \CCalendar::getUserId();
277 }
278
279 if (!is_array($value))
280 {
281 $value = [];
282 }
283
284 \CUserOptions::setOption("calendar", "superpose_tracking_groups", serialize($value), false, $userId);
285 }
286
287 public static function getHiddenSections($userId = false, $options = []): array
288 {
289 $res = [];
290 if (class_exists('CUserOptions') && $userId > 0)
291 {
292 $optionName = ($options['isPersonalCalendarContext'] ?? null) ? 'hidden_sections' : 'hidden_sections_'.$options['type'];
293 $res = \CUserOptions::getOption('calendar', $optionName, false, $userId);
294
295 if (is_array($res) && isset($res[$optionName]) && is_string($res[$optionName]))
296 {
297 $res = explode(',', $res[$optionName]);
298 }
299
300 if ($res === false && isset($options['defaultHiddenSections']) && is_array($options['defaultHiddenSections']))
301 {
302 $res = $options['defaultHiddenSections'];
303 }
304
305 if (is_array($res))
306 {
307 $res = array_values(array_filter(array_unique($res), function($k) {
308 return $k === 'tasks' || is_numeric($k);
309 }));
310 }
311 }
312
313 return is_array($res) ? $res : [];
314 }
315
316 public static function saveHiddenSections(int $userId, array $sections)
317 {
318 \CUserOptions::SetOption('calendar', 'hidden_sections', $sections, false, $userId);
319 }
320
321 public static function getSectionCustomization($userId = false)
322 {
323 /*
324 * \CUserOptions::setOption("calendar", "section_customization", serialize(['tasks' => ['name' => 'Custom task name', 'color' =>
325 '#FF22FF']]), false, $userId);
326 */
327
328 $result = [];
329 $str = \CUserOptions::getOption("calendar", "section_customization", false, $userId);
330 if ($str !== false && CheckSerializedData($str))
331 {
332 $result = unserialize($str, ['allowed_classes' => false]);
333 }
334
335 return $result;
336 }
337
338 public static function setSectionCustomization($userId = false, $data = [])
339 {
340 $sectionCustomization = self::getSectionCustomization($userId);
341
342 foreach($data as $sectionId => $config)
343 {
344 if (isset($sectionCustomization[$sectionId]) && $config === false)
345 {
346 unset($sectionCustomization[$sectionId]);
347 }
348 else
349 {
350 $sectionCustomization[$sectionId] = $config;
351 }
352 }
353
354 \CUserOptions::setOption("calendar", "section_customization", serialize($sectionCustomization), false, $userId);
355
356 \Bitrix\Calendar\Util::addPullEvent(
357 'change_section_customization',
358 $userId, []
359 );
360 }
361
362
363 public static function getFollowedSectionIdList($userId = false)
364 {
365 $sectionIdList = [];
366 if ($userId)
367 {
368 $defaultFollowedSectionId = intval(\CUserOptions::GetOption("calendar", "superpose_displayed_default", 0, $userId));
369 if ($defaultFollowedSectionId)
370 {
371 $sectionIdList[] = $defaultFollowedSectionId;
372 }
373
374 $str = \CUserOptions::GetOption("calendar", "superpose_displayed", false, $userId);
375 if (CheckSerializedData($str))
376 {
377 $idList = unserialize($str, ['allowed_classes' => false]);
378 if (is_array($idList))
379 {
380 foreach($idList as $id)
381 {
382 if (intval($id) > 0)
383 {
384 $sectionIdList[] = intval($id);
385 }
386 }
387 }
388 }
389
390 if ($defaultFollowedSectionId)
391 {
392 \CUserOptions::SetOption("calendar", "superpose_displayed", serialize($sectionIdList));
393 \CUserOptions::SetOption("calendar", "superpose_displayed_default", false);
394 }
395 }
396 return $sectionIdList;
397 }
398}
static getTrackingGroups($userId=false, $params=[])
static saveHiddenSections(int $userId, array $sections)
static getFollowedSectionIdList($userId=false)
static getFormSettings($formType, $userId=false)
static getSectionCustomization($userId=false)
static setTrackingUsers($userId=false, $value=[])
static get($userId=null)
static setTrackingGroups($userId=false, $value=[])
static setSectionCustomization($userId=false, $data=[])
static getHiddenSections($userId=false, $options=[])
static getTrackingUsers($userId=false, $params=[])