4use \Bitrix\Main\Web\Json;
11 'CalendarSelCont' =>
false,
12 'SPCalendarSelCont' =>
false,
13 'meetSection' =>
false,
14 'crmSection' =>
false,
15 'showDeclined' =>
false,
16 'denyBusyInvitation' =>
false,
17 'collapseOffHours' =>
'Y',
18 'showWeekNumbers' =>
'N',
21 'showCompletedTasks' =>
'N',
22 'lastUsedSection' =>
false,
23 'sendFromEmail' =>
false,
24 'defaultSections' => [],
25 'syncPeriodPast' => 3,
26 'syncPeriodFuture' => 12,
27 'defaultReminders' => [
29 'type' =>
'daybefore',
43 public static function set($settings = [], $userId =
false)
46 $userId = \CCalendar::getUserId();
50 if ($settings ===
false)
52 \CUserOptions::setOption(
"calendar",
"user_settings",
false,
false, $userId);
54 elseif(is_array($settings))
57 foreach($settings as $optionName => $value)
59 if (isset(self::$settings[$optionName]))
62 ($optionName ===
'defaultSections' || $optionName ===
'defaultReminders')
66 $curSet[$optionName] = Json::encode($value);
70 $curSet[$optionName] = $value;
74 \CUserOptions::setOption(
"calendar",
"user_settings", $curSet,
false, $userId);
78 public static function get($userId =
null)
82 $userId = \CCalendar::getUserId();
85 $resSettings = self::$settings;
89 $settings = \CUserOptions::getOption(
"calendar",
"user_settings",
false, $userId);
90 if (is_array($settings))
92 foreach($settings as $optionName => $value)
95 ($optionName ===
'defaultSections' || $optionName ===
'defaultReminders')
99 $resSettings[$optionName] = Json::decode($value);
103 $resSettings[$optionName] = $value;
108 $resSettings[
'timezoneName'] = \CCalendar::getUserTimezoneName($userId);
109 $resSettings[
'timezoneOffsetUTC'] = \CCalendar::getCurrentOffsetUTC($userId);
110 $resSettings[
'timezoneDefaultName'] =
'';
112 if (isset($settings[
'denyBusyInvitation']))
114 $resSettings[
'denyBusyInvitation'] = !!$settings[
'denyBusyInvitation'];
117 if (isset($settings[
'showDeclined']))
119 $resSettings[
'showDeclined'] = !!$settings[
'showDeclined'];
124 if (!$resSettings[
'timezoneName'])
126 $resSettings[
'timezoneDefaultName'] = \CCalendar::getGoodTimezoneForOffset($resSettings[
'timezoneOffsetUTC']);
129 $workTime = \CUserOptions::getOption(
"calendar",
"workTime",
false, $userId);
132 $resSettings[
'work_time_start'] = $workTime[
'start'].
'.00';
133 $resSettings[
'work_time_end'] = $workTime[
'end'].
'.00';
144 $userId = \CCalendar::getUserId();
149 'pinnedFields' => implode(
',', [
'location',
'rrule',
'section'])
152 if (!isset($defaultValues[$formType]))
154 $defaultValues[$formType] =
false;
157 $settings = \CUserOptions::getOption(
"calendar", $formType, $defaultValues[$formType], $userId);
158 if (!is_array($settings[
'pinnedFields']))
160 $settings[
'pinnedFields'] = explode(
',', $settings[
'pinnedFields']);
169 $userId = \CCalendar::getUserId();
173 $str = \CUserOptions::getOption(
"calendar",
"superpose_tracking_users",
false, $userId);
175 if ($str !==
false && CheckSerializedData($str))
177 $ids = unserialize($str, [
'allowed_classes' =>
false]);
178 if (is_array($ids) && count($ids) > 0)
189 if (is_array($res) && !in_array($userId, $res))
194 if (isset($params[
'userList']))
196 $params[
'userList'] = array_unique($params[
'userList']);
197 $diff = array_diff($params[
'userList'], $res);
198 if (count($diff) > 0)
200 $res = array_merge($res, $diff);
205 $res = \Bitrix\Main\UserTable::getList(
207 'filter' => [
'ID' => $res],
208 'select' => [
'ID',
'LOGIN',
'NAME',
'LAST_NAME',
'SECOND_NAME']
213 while ($user = $res->fetch())
215 $user[
'FORMATTED_NAME'] = \CCalendar::GetUserName($user);
216 $trackedUsers[] = $user;
219 return $trackedUsers;
226 $userId = \CCalendar::getUserId();
229 if (!is_array($value))
233 array_walk($value,
'intval');
234 $value = array_unique($value);
236 \CUserOptions::setOption(
"calendar",
"superpose_tracking_users", serialize($value),
false, $userId);
242 $str = \CUserOptions::getOption(
"calendar",
"superpose_tracking_groups",
false, $userId);
244 if ($str !==
false && CheckSerializedData($str))
246 $ids = unserialize($str, [
'allowed_classes' =>
false]);
253 $res[] = intval($id);
259 if ($params && isset($params[
'groupList']))
261 $params[
'groupList'] = array_unique($params[
'groupList']);
262 $diff = array_diff($params[
'groupList'], $res);
263 if (count($diff) > 0)
265 $res = array_merge($res, $diff);
276 $userId = \CCalendar::getUserId();
279 if (!is_array($value))
284 \CUserOptions::setOption(
"calendar",
"superpose_tracking_groups", serialize($value),
false, $userId);
290 if (class_exists(
'CUserOptions') && $userId > 0)
292 $optionName = ($options[
'isPersonalCalendarContext'] ??
null) ?
'hidden_sections' :
'hidden_sections_'.$options[
'type'];
293 $res = \CUserOptions::getOption(
'calendar', $optionName,
false, $userId);
295 if (is_array($res) && isset($res[$optionName]) && is_string($res[$optionName]))
297 $res = explode(
',', $res[$optionName]);
300 if ($res ===
false && isset($options[
'defaultHiddenSections']) && is_array($options[
'defaultHiddenSections']))
302 $res = $options[
'defaultHiddenSections'];
307 $res = array_values(array_filter(array_unique($res),
function($k) {
308 return $k ===
'tasks' || is_numeric($k);
313 return is_array($res) ? $res : [];
318 \CUserOptions::SetOption(
'calendar',
'hidden_sections', $sections,
false, $userId);
329 $str = \CUserOptions::getOption(
"calendar",
"section_customization",
false, $userId);
330 if ($str !==
false && CheckSerializedData($str))
332 $result = unserialize($str, [
'allowed_classes' =>
false]);
342 foreach($data as $sectionId => $config)
344 if (isset($sectionCustomization[$sectionId]) && $config ===
false)
346 unset($sectionCustomization[$sectionId]);
350 $sectionCustomization[$sectionId] = $config;
354 \CUserOptions::setOption(
"calendar",
"section_customization", serialize($sectionCustomization),
false, $userId);
356 \Bitrix\Calendar\Util::addPullEvent(
357 'change_section_customization',
368 $defaultFollowedSectionId = intval(\CUserOptions::GetOption(
"calendar",
"superpose_displayed_default", 0, $userId));
369 if ($defaultFollowedSectionId)
371 $sectionIdList[] = $defaultFollowedSectionId;
374 $str = \CUserOptions::GetOption(
"calendar",
"superpose_displayed",
false, $userId);
375 if (CheckSerializedData($str))
377 $idList = unserialize($str, [
'allowed_classes' =>
false]);
378 if (is_array($idList))
380 foreach($idList as $id)
384 $sectionIdList[] = intval($id);
390 if ($defaultFollowedSectionId)
392 \CUserOptions::SetOption(
"calendar",
"superpose_displayed", serialize($sectionIdList));
393 \CUserOptions::SetOption(
"calendar",
"superpose_displayed_default",
false);
396 return $sectionIdList;
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 setTrackingGroups($userId=false, $value=[])
static setSectionCustomization($userId=false, $data=[])
static getHiddenSections($userId=false, $options=[])
static getTrackingUsers($userId=false, $params=[])