Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
syncadapter.php
1<?
7
9
10IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/calendar/classes/general/calendar.php");
11
13{
14 private static
15 $sectionIndex = [];
16
25 public static function getSectionList($entityType, $entityId, $params = [])
26 {
27 $sectionId = $params['sectionId'];
28 $sectionList = [];
29
30 if ($sectionId && self::$sectionIndex[$sectionId])
31 {
32 $sectionList[] = self::$sectionIndex[$sectionId];
33 }
34 else
35 {
36 if ($sectionId !== \CCalendar::TASK_SECTION_ID)
37 {
38 $filter = [
39 'CAL_TYPE' => $entityType,
40 'OWNER_ID' => $entityId
41 ];
42
43 if (!is_array($params))
44 {
45 $params = [];
46 }
47
48 if ($sectionId > 0)
49 {
50 $filter['ID'] = $sectionId;
51 }
52
53 \CCalendar::SetSilentErrorMode(true);
54 if (isset($params['active']))
55 {
56 $filter['ACTIVE'] = $params['active'] ? 'Y' : 'N';
57 }
58
59 $res = \CCalendarSect::GetList(['arFilter' => $filter]);
60 \CCalendar::SetSilentErrorMode(false);
61
62 foreach($res as $calendar)
63 {
64 if ($params['skipExchange'] == true && $calendar['DAV_EXCH_CAL'] <> '')
65 {
66 continue;
67 }
68
69 $section = [
70 'ID' => $calendar['ID'],
71 '~NAME' => $calendar['NAME'],
72 'NAME' => htmlspecialcharsbx($calendar['NAME']),
73 'COLOR' => htmlspecialcharsbx($calendar['COLOR'])
74 ];
75 $sectionList[] = $section;
76 self::$sectionIndex[$section['ID']] = $section;
77 }
78
79 // Temporary hide it, while waiting for new interface.
80 if (!$sectionId && false)
81 {
82 $followedSectionIdList = UserSettings::getFollowedSectionIdList($entityId);
83 if (count($followedSectionIdList) > 0)
84 {
85 $followedSectionList = \CCalendarSect::GetList(['arFilter' => [
86 'CAL_TYPE' => $entityType,
87 'OWNER_ID' => $entityId,
88 'ACTIVE' => 'Y',
89 'ADDITIONAL_IDS' => $followedSectionIdList
90 ]]);
91
92 foreach($followedSectionList as $calendar)
93 {
94 $section = [
95 'ID' => $calendar['ID'],
96 '~NAME' => $calendar['NAME'],
97 'NAME' => htmlspecialcharsbx($calendar['NAME']),
98 'COLOR' => htmlspecialcharsbx($calendar['COLOR'])
99 ];
100 $sectionList[] = $section;
101 self::$sectionIndex[$section['ID']] = $section;
102 }
103 }
104 }
105 }
106
107 if (\CCalendarSync::isTaskListSyncEnabled() && $entityType == 'user' && ($sectionId === \CCalendar::TASK_SECTION_ID || !$sectionId))
108 {
109 $sectionsUserData = UserSettings::getSectionCustomization($entityId);
110 $taskSectionTitle = (isset($sectionsUserData['tasks']) && !empty($sectionsUserData['tasks']['name']))
111 ? $sectionsUserData['tasks']['name']
112 : \Bitrix\Main\Localization\Loc::getMessage('EC_MY_TASKS');
113
114 $section = [
115 'ID' => \CCalendar::TASK_SECTION_ID,
116 '~NAME' => $taskSectionTitle,
117 'NAME' => htmlspecialcharsbx($taskSectionTitle),
118 'COLOR' => (isset($sectionsUserData['tasks']) && !empty($sectionsUserData['tasks']['color'])) ?
119 htmlspecialcharsbx($sectionsUserData['tasks']['color']) : \CCalendar::DEFAULT_TASK_COLOR
120 ];
121 $sectionList[] = $section;
122 self::$sectionIndex[$section['ID']] = $section;
123 }
124 }
125
126 return $sectionList;
127 }
128
129
137 public static function getEventList($sectionId = false, $params = [])
138 {
139 $entryList = [];
140
141 if ($params['entityType'] === 'user')
142 {
143 $userId = $params['entityId'];
144 if ($sectionId === \CCalendar::TASK_SECTION_ID)
145 {
146 $entryList = self::getTaskList($userId);
147 }
148 else
149 {
150 \CCalendar::SetOffset(false, 0);
151 $filter = [
152 'DELETED' => 'N'
153 ];
154
155 if (isset($params['filter']['DAV_XML_ID']))
156 {
157 $filter['DAV_XML_ID'] = $params['filter']['DAV_XML_ID'];
158 }
159 else
160 {
161 if (isset($params['filter']['DATE_START']))
162 {
163 $filter['FROM_LIMIT'] = $params['filter']['DATE_START'];
164 }
165 if (isset($params['filter']['DATE_END']))
166 {
167 $filter['TO_LIMIT'] = $params['filter']['DATE_END'];
168 }
169 }
170
171 if ($sectionId > 0)
172 {
173 $filter['SECTION'] = $sectionId;
174 }
175
176 $events = \CCalendarEvent::GetList(
177 array(
178 'arFilter' => $filter,
179 'getUserfields' => false,
180 'parseRecursion' => false,
181 'fetchAttendees' => false,
182 'fetchMeetings' => !$sectionId || \CCalendar::getMeetingSection($userId, true) == $sectionId,
183 'userId' => $userId
184 )
185 );
186
187 foreach ($events as $event)
188 {
189 // Skip events from where owner is host of the meeting and it's meeting from other section
190 // or declined events
191 if($event['IS_MEETING'] && ($event["MEETING_STATUS"] == 'N' || ($event['MEETING_HOST'] == $userId && $event['SECTION_ID'] != $sectionId)))
192 {
193 continue;
194 }
195
196 $event['XML_ID'] = $event['DAV_XML_ID'];
197 $event['LOCATION'] = \CCalendar::GetTextLocation($event['LOCATION']);
198 $event['RRULE'] = \CCalendarEvent::ParseRRULE($event['RRULE']);
199 $entryList[] = $event;
200 }
201 }
202 }
203
204 return $entryList;
205 }
206
214 public static function getTaskList($userId, $params = [])
215 {
216 $tasksEntries = [];
217 if (\Bitrix\Main\Loader::includeModule('tasks'))
218 {
219 $tasksEntries = \CCalendar::getTaskList([
220 'type' => 'user',
221 'ownerId' => $userId
222 ]);
223
224 for ($i = 0, $l = count($tasksEntries); $i < $l; $i++)
225 {
226 $tasksEntries[$i]['TIMESTAMP_X'] = \CCalendar::Date(round(time() / 180) * 180);
227 $tasksEntries[$i]['DAV_XML_ID'] = 'task-'.$tasksEntries[$i]["ID"];
228 }
229 }
230
231 return $tasksEntries;
232 }
233
241 public static function deleteEvent($eventId, $params = [])
242 {
243 return \CCalendar::DeleteEvent($eventId);
244 }
245}
static getSectionList($entityType, $entityId, $params=[])
static getEventList($sectionId=false, $params=[])
static deleteEvent($eventId, $params=[])
static getTaskList($userId, $params=[])
static getFollowedSectionIdList($userId=false)
static getSectionCustomization($userId=false)