Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
accessibilitymanager.php
1<?php
2
4
6
8{
9 private const TYPE = 'location';
10
12 private ?string $dateFrom = null;
14 private ?string $dateTo = null;
16 private ?array $datesRange = null;
18 private ?array $locationList = null;
19
20 protected function __construct()
21 {
22 }
23
24 public static function createInstance(): AccessibilityManager
25 {
26 return new self();
27 }
28
29 public function setLocationList(?array $locationList = []): AccessibilityManager
30 {
31 $this->locationList = $locationList;
32
33 return $this;
34 }
35
36 public function setDateFrom(?string $dateFrom = ''): AccessibilityManager
37 {
38 $this->dateFrom = $dateFrom;
39
40 return $this;
41 }
42
43 public function setDateTo(?string $dateTo = ''): AccessibilityManager
44 {
45 $this->dateTo = $dateTo;
46
47 return $this;
48 }
49
50 public function setDatesRange(?array $range = []): AccessibilityManager
51 {
52 $this->datesRange = $range;
53
54 return $this;
55 }
56
57 public function getLocationList(): ?array
58 {
59 return $this->locationList;
60 }
61
62 public function getDateFrom(): ?string
63 {
64 return $this->dateFrom;
65 }
66
67 public function getDateTo(): ?string
68 {
69 return $this->dateTo;
70 }
71
72 public function getDatesRange(): ?array
73 {
74 return $this->datesRange;
75 }
76
85 public static function checkAccessibility(string $locationId = '', array $params = []): bool
86 {
87 $location = Util::parseLocation($locationId);
88
89 $res = true;
90 if ($location['room_id'] || $location['mrid'])
91 {
92 $dateFrom = DateTime::createFromTimestamp(\CCalendar::TimestampUTC($params['fields']['DATE_FROM']))
93 ->setTimeZone(new \DateTimeZone('UTC'));
94 $dateTo = DateTime::createFromTimestamp(\CCalendar::TimestampUTC($params['fields']['DATE_TO']))
95 ->setTimeZone(new \DateTimeZone('UTC'));
96
97 $fromTs = \Bitrix\Calendar\Util::getDateTimestampUtc($dateFrom, $params['fields']['TZ_FROM']);
98 $toTs = \Bitrix\Calendar\Util::getDateTimestampUtc($dateTo, $params['fields']['TZ_FROM']);
99 if ($params['fields']['SKIP_TIME'])
100 {
101 $toTs += \CCalendar::GetDayLen();
102 }
103
104 $eventId = (int)$params['fields']['ID'];
105
106 $from = \Bitrix\Calendar\Util::formatDateTimestampUTC($fromTs);
107 $to = \Bitrix\Calendar\Util::formatDateTimestampUTC($toTs);
108
109 if ($location['mrid'])
110 {
112 'allowReserveMeeting' => true,
113 'id' => $location['mrid'],
114 'from' => \CCalendar::Date(
115 $fromTs - \CCalendar::DAY_LENGTH,
116 false
117 ),
118 'to' => \CCalendar::Date(
119 $toTs + \CCalendar::DAY_LENGTH,
120 false
121 ),
122 'curEventId' => $location['mrevid'],
123 ]);
124
125 foreach ($meetingRoomRes as $entry)
126 {
127 if ((int)$entry['ID'] !== (int)$location['mrevid'])
128 {
129 $entryFromTs = \CCalendar::Timestamp($entry['DT_FROM']);
130 $entryToTs = \CCalendar::Timestamp($entry['DT_TO']);
131
132 if ($entryFromTs < $toTs && $entryToTs > $fromTs)
133 {
134 $res = false;
135 break;
136 }
137 }
138 }
139 }
140 elseif ($location['room_id'])
141 {
142 $entries = self::getRoomAccessibility([$location['room_id']], $from, $to);
143 foreach ($entries as $entry)
144 {
145 if ((int)$entry['ID'] !== (int)$location['room_event_id']
146 && (int)$entry['PARENT_ID'] !== $eventId)
147 {
148 $entryFromTs = \Bitrix\Calendar\Util::getDateTimestampUtc(new DateTime($entry['DATE_FROM']), $entry['TZ_FROM']);
149 $entryToTs = \Bitrix\Calendar\Util::getDateTimestampUtc(new DateTime($entry['DATE_TO']), $entry['TZ_FROM']);
150 if ($entry['DT_SKIP_TIME'] === 'Y')
151 {
152 $entryToTs += \CCalendar::GetDayLen();
153 }
154
155 if ($entryFromTs < $toTs && $entryToTs > $fromTs)
156 {
157 $res = false;
158 break;
159 }
160 }
161 }
162 }
163 }
164
165 return $res;
166 }
167
175 public static function getRoomAccessibility(array $roomIds, $from, $to): array
176 {
177 return \CCalendarEvent::GetList([
178 'arFilter' => [
179 'FROM_LIMIT' => $from,
180 'TO_LIMIT' => $to,
181 'CAL_TYPE' => self::TYPE,
182 'ACTIVE_SECTION' => 'Y',
183 'SECTION' => $roomIds,
184 ],
185 'parseRecursion' => true,
186 'fetchSection' => true,
187 'setDefaultLimit' => false,
188 ]);
189 }
190
195 public function getLocationAccessibility(): array
196 {
197 if (!is_array($this->datesRange) || !is_array($this->locationList) || empty($this->datesRange))
198 {
199 return [];
200 }
201
202 $roomIds = array_map(static fn($room) => (int)$room['ID'], $this->locationList);
203 $from = $this->datesRange[0];
204 $to = $this->datesRange[count($this->datesRange) - 1];
205
206 $entries = self::getRoomAccessibility($roomIds, $from, $to);
207
208 $result = [];
209
210 foreach ($this->datesRange as $date)
211 {
212 $result[$date] = [];
213 }
214
215 foreach ($entries as $entry)
216 {
217 $roomId = (int)$entry['SECTION_ID'];
218
219 $dateStart = new DateTime($entry['DATE_FROM']);
220 $dateEnd = new DateTime($entry['DATE_TO']);
221 while ($dateStart->getTimestamp() <= $dateEnd->getTimestamp())
222 {
223 $date = $dateStart->format('d.m.Y');
224 $dateStart->add('1 day');
225 if (!isset($result[$date]))
226 {
227 continue;
228 }
229
230 $result[$date][$roomId] ??= [];
231 $result[$date][$roomId][] = $entry;
232 }
233 }
234
235 return $result;
236 }
237}
static checkAccessibility(string $locationId='', array $params=[])
static getRoomAccessibility(array $roomIds, $from, $to)
static createFromTimestamp($timestamp)
Definition datetime.php:246