1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
accessibilitymanager.php
См. документацию.
1<?php
2
4
9
11{
13 private const TYPE = 'location';
15 public const ADDITIONAL_LOCATION_CONNECTION_OPTION = 'additional_location_connection';
16
18 private ?string $dateFrom = null;
20 private ?string $dateTo = null;
22 private ?array $datesRange = null;
24 private ?array $locationList = null;
25
26 protected function __construct()
27 {
28 }
29
30 public static function createInstance(): AccessibilityManager
31 {
32 return new self();
33 }
34
35 public function setLocationList(?array $locationList = []): AccessibilityManager
36 {
37 $this->locationList = $locationList;
38
39 return $this;
40 }
41
42 public function setDateFrom(?string $dateFrom = ''): AccessibilityManager
43 {
44 $this->dateFrom = $dateFrom;
45
46 return $this;
47 }
48
49 public function setDateTo(?string $dateTo = ''): AccessibilityManager
50 {
51 $this->dateTo = $dateTo;
52
53 return $this;
54 }
55
56 public function setDatesRange(?array $range = []): AccessibilityManager
57 {
58 $this->datesRange = $range;
59
60 return $this;
61 }
62
63 public function getLocationList(): ?array
64 {
65 return $this->locationList;
66 }
67
68 public function getDateFrom(): ?string
69 {
70 return $this->dateFrom;
71 }
72
73 public function getDateTo(): ?string
74 {
75 return $this->dateTo;
76 }
77
78 public function getDatesRange(): ?array
79 {
80 return $this->datesRange;
81 }
82
93 public static function checkAccessibility(string $locationId = '', array $params = []): bool
94 {
95 $location = Util::parseLocation($locationId);
96
97 $res = true;
98 if ($location['room_id'] || $location['mrid'])
99 {
100 $dateFrom = DateTime::createFromTimestamp(\CCalendar::TimestampUTC($params['fields']['DATE_FROM']))
101 ->setTimeZone(new \DateTimeZone('UTC'));
102 $dateTo = DateTime::createFromTimestamp(\CCalendar::TimestampUTC($params['fields']['DATE_TO']))
103 ->setTimeZone(new \DateTimeZone('UTC'));
104
105 $fromTs = \Bitrix\Calendar\Util::getDateTimestampUtc($dateFrom, $params['fields']['TZ_FROM']);
106 $toTs = \Bitrix\Calendar\Util::getDateTimestampUtc($dateTo, $params['fields']['TZ_FROM']);
107 if ($params['fields']['SKIP_TIME'])
108 {
109 $toTs += \CCalendar::GetDayLen();
110 }
111
112 $eventId = (int)$params['fields']['ID'];
113
116
117 if ($location['room_id'])
118 {
119 $sections = [$location['room_id']];
120 $additionalLocationConnection = self::getAdditionalLocationAccessibilityConnection((int)$location['room_id']);
121 if (!empty($additionalLocationConnection))
122 {
123 $sections = [
124 ...$sections,
125 ...$additionalLocationConnection,
126 ];
127 }
128
129 $entries = self::getRoomAccessibility($sections, $from, $to);
130 $res = self::checkLocationAccessibility($entries, $fromTs, $toTs, $location['room_event_id'], $eventId);
131 }
132
134 else if ($location['mrid'])
135 {
137 }
138 }
139
140 return $res;
141 }
142
143
153 public static function checkLocationAccessibility(array $entries, int $fromTs, int $toTs, mixed $roomEventId, mixed $eventId): bool
154 {
155 $result = true;
156
157 foreach ($entries as $entry)
158 {
159 if (
160 (int)$entry['ID'] !== (int)$roomEventId
161 && (int)$entry['PARENT_ID'] !== $eventId
162 )
163 {
165 new DateTime($entry['DATE_FROM']), $entry['TZ_FROM']
166 );
168 new DateTime($entry['DATE_TO']), $entry['TZ_FROM']
169 );
170 if ($entry['DT_SKIP_TIME'] === 'Y')
171 {
172 $entryToTs += \CCalendar::GetDayLen();
173 }
174
175 if ($entryFromTs < $toTs && $entryToTs > $fromTs)
176 {
177 $result = false;
178
179 break;
180 }
181 }
182 }
183
184 return $result;
185 }
186
187
192 public static function getAdditionalLocationAccessibilityConnection(int $roomId): array
193 {
194 $currentOption = Option::get('calendar', self::ADDITIONAL_LOCATION_CONNECTION_OPTION);
195 $decodedOption = unserialize($currentOption, ['allowed_classes' => false]);
196
197 return $decodedOption[$roomId] ?? [];
198 }
199
200
207 public static function setFullAdditionalLocationAccessibilityConnection(array $additionalRoomConnectionInfo): void
208 {
209 $result = serialize($additionalRoomConnectionInfo);
210
211 Option::set('calendar', self::ADDITIONAL_LOCATION_CONNECTION_OPTION, $result);
212 }
213
221 public static function setAdditionalLocationAccessibilityConnection(int $roomId, array $additionalRoomId): void
222 {
223 $currentOption = Option::get('calendar', self::ADDITIONAL_LOCATION_CONNECTION_OPTION);
224 $decodedOption = unserialize($currentOption, ['allowed_classes' => false]);
225
226 if (!is_array($decodedOption))
227 {
228 $decodedOption = [];
229 }
230
231 $decodedOption[$roomId] = $additionalRoomId;
232 $result = serialize($decodedOption);
233
234 Option::set('calendar', self::ADDITIONAL_LOCATION_CONNECTION_OPTION, $result);
235 }
236
244 public static function checkIBlockAccessibility(array $location, int $fromTs, int $toTs): bool
245 {
246 $result = true;
247
249 'allowReserveMeeting' => true,
250 'id' => $location['mrid'],
251 'from' => \CCalendar::Date($fromTs - \CCalendar::DAY_LENGTH, false),
252 'to' => \CCalendar::Date($toTs + \CCalendar::DAY_LENGTH, false),
253 'curEventId' => $location['mrevid'],
254 ]);
255
256 foreach ($meetingRoomRes as $entry)
257 {
258 if ((int)$entry['ID'] !== (int)$location['mrevid'])
259 {
260 $entryFromTs = \CCalendar::Timestamp($entry['DT_FROM']);
261 $entryToTs = \CCalendar::Timestamp($entry['DT_TO']);
262
263 if ($entryFromTs < $toTs && $entryToTs > $fromTs)
264 {
265 $result = false;
266
267 break;
268 }
269 }
270 }
271 return $result;
272 }
273
281 public static function getRoomAccessibility(array $roomIds, $from, $to): array
282 {
283 return \CCalendarEvent::GetList([
284 'arFilter' => [
285 'FROM_LIMIT' => $from,
286 'TO_LIMIT' => $to,
287 'CAL_TYPE' => self::TYPE,
288 'ACTIVE_SECTION' => 'Y',
289 'SECTION' => $roomIds,
290 ],
291 'arSelect' => \CCalendarEvent::$defaultSelectEvent,
292 'parseRecursion' => true,
293 'fetchSection' => true,
294 'setDefaultLimit' => false,
295 'fetchAttendees' => false,
296 ]);
297 }
298
304 {
305 if (!is_array($this->datesRange) || !is_array($this->locationList) || empty($this->datesRange))
306 {
307 return [];
308 }
309
310 $roomIds = array_map(static fn($room) => (int)$room['ID'], $this->locationList);
311 $from = $this->datesRange[0];
312 $to = $this->datesRange[count($this->datesRange) - 1];
313
314 $entries = self::getRoomAccessibility($roomIds, $from, $to);
315
316 $result = [];
317
318 foreach ($this->datesRange as $date)
319 {
320 $result[$date] = [];
321 }
322
323 foreach ($entries as $entry)
324 {
325 $roomId = (int)$entry['SECTION_ID'];
326
327 $dateStart = new DateTime($entry['DATE_FROM']);
328 $dateEnd = new DateTime($entry['DATE_TO']);
329 while ($dateStart->getTimestamp() <= $dateEnd->getTimestamp())
330 {
331 $date = $dateStart->format('d.m.Y');
332 $dateStart->add('1 day');
333 if (!isset($result[$date]))
334 {
335 continue;
336 }
337
338 $result[$date][$roomId] ??= [];
339 $result[$date][$roomId][] = $entry;
340 }
341 }
342
343 return $result;
344 }
345}
setDateFrom(?string $dateFrom='')
Определения accessibilitymanager.php:42
static checkIBlockAccessibility(array $location, int $fromTs, int $toTs)
Определения accessibilitymanager.php:244
static setFullAdditionalLocationAccessibilityConnection(array $additionalRoomConnectionInfo)
Определения accessibilitymanager.php:207
static checkAccessibility(string $locationId='', array $params=[])
Определения accessibilitymanager.php:93
setLocationList(?array $locationList=[])
Определения accessibilitymanager.php:35
static getAdditionalLocationAccessibilityConnection(int $roomId)
Определения accessibilitymanager.php:192
static getRoomAccessibility(array $roomIds, $from, $to)
Определения accessibilitymanager.php:281
static setAdditionalLocationAccessibilityConnection(int $roomId, array $additionalRoomId)
Определения accessibilitymanager.php:221
static checkLocationAccessibility(array $entries, int $fromTs, int $toTs, mixed $roomEventId, mixed $eventId)
Определения accessibilitymanager.php:153
static getAccessibilityForMeetingRoom(array $params)
Определения iblockmeetingroom.php:255
static formatDateTimestampUTC(int $timestamp)
Определения util.php:760
static getDateTimestampUtc(DateTime $date, ?string $eventTimezone=null)
Определения util.php:774
</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
</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