1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
calendar_planner.php
См. документацию.
1<?php
2
8
10{
11 public static function Init($config = [], $initialParams = false)
12 {
13 self::InitJsCore($config, $initialParams);
14 }
15
16 public static function InitJsCore($config = [], $initialParams = [])
17 {
18 global $APPLICATION;
19 \Bitrix\Main\UI\Extension::load(['ajax', 'window', 'popup', 'access', 'date', 'viewer', 'socnetlogdest']);
20 \Bitrix\Main\UI\Extension::load(['calendar.planner', 'ui.fonts.opensans']);
21
22 // Config
23 if (!$config['id'])
24 {
25 $config['id'] = (isset($config['id']) && $config['id'] <> '')
26 ? $config['id']
27 : 'bx_calendar_planner'
28 . mb_substr(uniqid(mt_rand(), true), 0, 4)
29 ;
30 }
31
32 $APPLICATION->AddHeadScript('/bitrix/js/calendar/planner.js');
33 $APPLICATION->SetAdditionalCSS("/bitrix/js/calendar/planner.css");
34
36 ?>
37 <div id="<?= htmlspecialcharsbx($config['id'])?>" class="calendar-planner-wrapper"></div>
38 <script>
39 BX.namespace('BX.Calendar');
40 if(typeof BX.Calendar.PlannerManager === 'undefined')
41 {
42 BX.Calendar.PlannerManager = {
43 planners: {},
44 Get: function(id)
45 {
46 return BX.Calendar.PlannerManager.planners[id] || false;
47 },
48 Init: function(id, config, initialParams)
49 {
50 if (window.CalendarPlanner)
51 {
52 BX.Calendar.PlannerManager.planners[id] = new window.CalendarPlanner(config, initialParams);
53 }
54 }
55 }
56 }
57
58 BX.message(<?=CUtil::PhpToJSObject($mess_lang, false);?>);
59 BX.ready(function()
60 {
61 BX.Calendar.PlannerManager.Init(
62 '<?= CUtil::JSEscape($config['id'])?>',
63 <?=\Bitrix\Main\Web\Json::encode($config, false);?>,
64 <?=\Bitrix\Main\Web\Json::encode($initialParams);?>
65 );
66 });
67 </script>
68 <?php
69 }
70
71 public static function prepareData($params = []): array
72 {
73 $parentId = (int)($params['parent_id'] ?? null);
74 $entryId = (int)($params['entry_id'] ?? null);
75
76 $skipEntryId = $parentId !== 0 ? $parentId : $entryId;
77 $curUserId = (int)($params['user_id'] ?? null);
78 $hostUserId = (int)($params['host_id'] ?? null);
79 $skipFeatureCheck = $params['skipFeatureCheck'] ?? false;
80
81 $isPlannerFeatureEnabled = $skipFeatureCheck || Bitrix24Manager::isPlannerFeatureEnabled();
82
83 $skipEntryList = (isset($params['skipEntryList']) && is_array($params['skipEntryList']))
84 ? $params['skipEntryList']
85 : [];
86
87 $resourceIdList = [];
88 $userIds = [];
89 $users = [];
90 $result = [
91 'users' => [],
92 'entries' => [],
93 'accessibility' => []
94 ];
95
96 if (isset($params['codes']) && is_array($params['codes']))
97 {
98 $params['codes'] = array_unique($params['codes']);
99 $users = CCalendar::GetDestinationUsers($params['codes'], true);
100 }
101
102 $prevUsersId = (isset($params['prevUserList']) && is_array($params['prevUserList']))
103 ? array_unique(array_map('intval', $params['prevUserList']))
104 : [];
105
106 if (!empty($users))
107 {
108 foreach($users as $user)
109 {
110 if (!in_array((int)$user['USER_ID'], $prevUsersId, true))
111 {
112 $userIds[] = (int)$user['USER_ID'];
113 }
114
115 $status = (($hostUserId && $hostUserId === (int)$user['USER_ID'])
116 || (!$hostUserId && $curUserId === (int)$user['USER_ID']))
117 ? 'h'
118 : '';
119
120 $userSettings = \Bitrix\Calendar\UserSettings::get($user['USER_ID']);
121 $result['entries'][] = [
122 'type' => 'user',
123 'id' => $user['USER_ID'],
124 'name' => CCalendar::GetUserName($user),
125 'status' => $status,
126 'url' => CCalendar::GetUserUrl($user['USER_ID']),
127 'avatar' => CCalendar::GetUserAvatarSrc($user),
128 'strictStatus' => $userSettings['denyBusyInvitation'],
129 'emailUser' => isset($user['EXTERNAL_AUTH_ID']) && ($user['EXTERNAL_AUTH_ID'] === 'email'),
130 'sharingUser' => isset($user['EXTERNAL_AUTH_ID']) && ($user['EXTERNAL_AUTH_ID'] === SharingUser::EXTERNAL_AUTH_ID),
131 'timezoneName' => CCalendar::GetUserTimezoneName((int)$user['USER_ID']),
132 'isCollabUser' => Util::isCollabUser((int)$user['USER_ID']),
133 ];
134 }
135 }
136 elseif(isset($params['entries']) && is_array($params['entries']))
137 {
138 foreach($params['entries'] as $userId)
139 {
140 $userIds[] = (int)$userId;
141 }
142 }
143
144 if (isset($params['resources']) && is_array($params['resources']))
145 {
146 foreach($params['resources'] as $resource)
147 {
148 $resourceId = (int)$resource['id'];
149 $resourceIdList[] = $resourceId;
150 $resource['type'] = preg_replace("/[^a-zA-Z0-9_]/i", "", $resource['type']);
151 $result['entries'][] = array(
152 'type' => $resource['type'],
153 'id' => $resourceId,
154 'name' => $resource['name']
155 );
156 $result['accessibility'][$resourceId] = [];
157 }
158 }
159
160 $from = $params['date_from'] ?? null;
161 $to = $params['date_to'] ?? null;
162
163 if (empty($from) || empty($to))
164 {
165 return $result;
166 }
167
168 $maxPlannerUsers = \CCalendar::GetMaxPlannerUsers();
169 $dontLoadAccessibility = $maxPlannerUsers > 0 && count($userIds) > $maxPlannerUsers;
170 if ($isPlannerFeatureEnabled && !$dontLoadAccessibility)
171 {
172 $accessibility = (new Accessibility())
173 ->setSkipEventId($skipEntryId)
174 ->getAccessibility($userIds, CCalendar::TimestampUTC($from), CCalendar::TimestampUTC($to))
175 ;
176
177 $timezoneName = \CCalendar::GetUserTimezoneName(\CCalendar::GetUserId());
178 foreach ($accessibility as $userId => $entries)
179 {
180 $result['accessibility'][$userId] = [];
181 foreach ($entries as $entry)
182 {
183 if (isset($entry['id']) && in_array($entry['id'], $skipEntryList))
184 {
185 continue;
186 }
187
188 if ($entry['isFullDay'])
189 {
190 $dateFrom = $entry['from'];
191 $dateTo = $entry['to'];
192 }
193 else
194 {
195 $dateFrom = Util::formatDateTimeTimestamp(CCalendar::TimestampUTC($entry['from']), $timezoneName);
196 $dateTo = Util::formatDateTimeTimestamp(CCalendar::TimestampUTC($entry['to']), $timezoneName);
197 }
198
199 $result['accessibility'][$userId][] = [
200 'name' => $entry['name'],
201 'dateFrom' => $dateFrom,
202 'dateTo' => $dateTo,
203 'isFullDay' => $entry['isFullDay'],
204 'isVacation' => $entry['isVacation'] ?? false,
205 ];
206 }
207 }
208 }
209
210 if (isset($params['location']))
211 {
212 $location = \Bitrix\Calendar\Rooms\Util::parseLocation($params['location']);
213 $entryLocation = \Bitrix\Calendar\Rooms\Util::parseLocation($params['entryLocation'] ?? null);
214 $roomEventId = $entryLocation['room_event_id'] ?? null;
215
216 if ($roomEventId && !in_array($roomEventId, $skipEntryList))
217 {
218 $skipEntryList[] = $roomEventId;
219 }
220
221 if ($location['mrid'] ?? null)
222 {
223 $mrid = 'MR_' . $location['mrid'];
224 $entry = [
225 'type' => 'room',
226 'id' => $mrid,
227 'name' => 'meeting room'
228 ];
229
231 foreach ($roomList as $room)
232 {
233 if ((int)$room['ID'] === (int)$location['mrid'])
234 {
235 $entry['name'] = $room['NAME'];
236 $entry['url'] = $room['URL'];
237 break;
238 }
239 }
240
241 $result['entries'][] = $entry;
242 $result['accessibility'][$mrid] = [];
243
244 if ($isPlannerFeatureEnabled)
245 {
247 'allowReserveMeeting' => true,
248 'id' => $location['mrid'],
249 'from' => $from,
250 'to' => $to,
251 'curEventId' => $roomEventId
252 ]);
253
254 foreach ($meetingRoomRes as $entry)
255 {
256 if (!in_array($entry['ID'], $skipEntryList))
257 {
258 $result['accessibility'][$mrid][] = [
259 'id' => $entry['ID'],
260 'dateFrom' => $entry['DT_FROM'],
261 'dateTo' => $entry['DT_TO']
262 ];
263 }
264 }
265 }
266 }
267 elseif ($location['room_id'])
268 {
269 $roomId = 'room_' . $location['room_id'];
270 $entry = [
271 'type' => 'room',
272 'id' => $roomId,
273 'roomId' => $location['room_id'],
274 'name' => 'meeting room'
275 ];
276
277 $sectionList = Rooms\Manager::getRoomsList();
278 foreach($sectionList as $room)
279 {
280 if ((int)$room['ID'] === (int)$location['room_id'])
281 {
282 $entry['name'] = $room['NAME'];
283 break;
284 }
285 }
286
287 $result['entries'][] = $entry;
288 $result['accessibility'][$roomId] = [];
289
290 if ($isPlannerFeatureEnabled)
291 {
293 [$location['room_id']],
294 $from,
295 $to
296 );
297
298 foreach ($meetingRoomRes as $entry)
299 {
300 if ((int)$entry['PARENT_ID'] === $skipEntryId || in_array((int)$entry['ID'], $skipEntryList))
301 {
302 continue;
303 }
304
305 $dateFrom = $entry['DATE_FROM'];
306 if ($entry['DT_SKIP_TIME'] !== "Y")
307 {
308 $dateFrom = CCalendar::Date(
309 CCalendar::Timestamp($entry['DATE_FROM']) - $entry['~USER_OFFSET_FROM']
310 );
311 $dateTo = CCalendar::Date(
312 CCalendar::Timestamp($entry['DATE_TO']) - $entry['~USER_OFFSET_TO']
313 );
314 }
315 else
316 {
317 $dateTo = CCalendar::Date(
318 CCalendar::Timestamp($entry['DATE_TO']) + CCalendar::GetDayLen()
319 );
320 }
321
322 $result['accessibility'][$roomId][] = [
323 'id' => $entry['ID'],
324 'name' => $entry['NAME'],
325 'dateFrom' => $dateFrom,
326 'dateTo' => $dateTo
327 ];
328 }
329 }
330 }
331 }
332
333 if (!empty($resourceIdList) && $isPlannerFeatureEnabled)
334 {
335 $resEntries = CCalendarEvent::GetList(
336 array(
337 'arFilter' => array(
338 "FROM_LIMIT" => $from,
339 "TO_LIMIT" => $to,
340 "CAL_TYPE" => 'resource',
341 "ACTIVE_SECTION" => "Y",
342 "SECTION" => $resourceIdList
343 ),
344 'parseRecursion' => true,
345 'setDefaultLimit' => false
346 )
347 );
348
349 foreach($resEntries as $entry)
350 {
351 if (in_array($entry['ID'], $skipEntryList))
352 {
353 continue;
354 }
355
356 $dateFrom = $entry['DATE_FROM'];
357 $dateTo = $entry['DATE_TO'];
358
359 if ($entry['DT_SKIP_TIME'] !== "Y")
360 {
361 $dateFrom = CCalendar::Date(
362 CCalendar::Timestamp($entry['DATE_FROM'])
363 - $entry['~USER_OFFSET_FROM']
364 );
365 $dateTo = CCalendar::Date(
366 CCalendar::Timestamp($entry['DATE_TO'])
367 - $entry['~USER_OFFSET_TO']
368 );
369 }
370
371 $result['accessibility'][$entry['SECT_ID']][] = array(
372 'id' => $entry["ID"],
373 'name' => $entry["NAME"],
374 'dateFrom' => $dateFrom,
375 'dateTo' => $dateTo
376 );
377 }
378 }
379
380 if (($params['initPullWatches'] ?? null) === true)
381 {
383 $curUserId,
384 $userIds
385 );
386 }
387
388 return $result;
389 }
390}
$resourceId
Определения push.php:24
global $APPLICATION
Определения include.php:80
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getRoomAccessibility(array $roomIds, $from, $to)
Определения accessibilitymanager.php:281
static getMeetingRoomList(array $params=[])
Определения iblockmeetingroom.php:20
static getAccessibilityForMeetingRoom(array $params)
Определения iblockmeetingroom.php:255
static getRoomsList()
Определения manager.php:161
static get($userId=null)
Определения usersettings.php:86
Определения util.php:21
static isCollabUser(int $userId)
Определения util.php:337
static initPlannerPullWatches(int $currentUserId, array $userIdList=[])
Определения util.php:452
static formatDateTimeTimestamp(int $timestamp, string $timezoneName)
Определения util.php:742
static loadLanguageFile($file, $language=null, $normalize=true)
Определения loc.php:225
static load($extNames)
Определения extension.php:16
static encode($data, $options=null)
Определения json.php:22
static InitJsCore($config=[], $initialParams=[])
Определения calendar_planner.php:16
static Init($config=[], $initialParams=false)
Определения calendar_planner.php:11
static prepareData($params=[])
Определения calendar_planner.php:71
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
Get()
Определения idea_idea_comment.php:22
$status
Определения session.php:10
Определения cookie.php:3
$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
$location
Определения options.php:2729