Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
iblockmeetingroom.php
1<?php
2
4
7use CPHPCache;
8
10{
11 private static $meetingRoomList;
12 private static $allowReserveMeeting = true;
13
20 public static function getMeetingRoomList(array $params = []): array
21 {
22 if (\COption::GetOptionString('calendar', 'eventWithLocationConverted', 'N') === 'Y')
23 {
24 $meetingRoomList = [];
25 self::$meetingRoomList = $meetingRoomList;
26
27 return $meetingRoomList;
28 }
29 if (isset(self::$meetingRoomList))
30 {
31 $meetingRoomList = self::$meetingRoomList;
32 }
33 else
34 {
35 $meetingRoomList = [];
36 if (!\CCalendar::IsBitrix24() && Loader::includeModule('iblock'))
37 {
38 if (!isset($params['RMiblockId']) && !isset($params['VMiblockId']))
39 {
40 $settings = \CCalendar::GetSettings();
41 $pathsForSite = \CCalendar::GetSettings([
42 'forseGetSitePathes' => true,
43 'site' => \CCalendar::GetSiteId()
44 ]);;
45 $RMiblockId = $settings['rm_iblock_id'];
46 $pathToMR = $pathsForSite['path_to_rm'];
47 }
48 else
49 {
50 $RMiblockId = $params['RMiblockId'];
51 $pathToMR = $params['pathToMR'];
52 }
53
54 if (self::$allowReserveMeeting && !\CCalendar::IsAdmin() && (\CIBlock::GetPermission($RMiblockId) < 'R'))
55 {
56 self::$allowReserveMeeting = false;
57 }
58
59 if ((int)$RMiblockId > 0 && \CIBlock::GetPermission($RMiblockId) >= 'R' && self::$allowReserveMeeting)
60 {
61 $orderBy = [
62 'NAME' => 'ASC',
63 'ID' => 'DESC'
64 ];
65 $filter = [
66 'IBLOCK_ID' => $RMiblockId,
67 'ACTIVE' => 'Y'
68 ];
69 $selectFields = [
70 'IBLOCK_ID',
71 'ID',
72 'NAME',
73 'DESCRIPTION',
74 'UF_FLOOR',
75 'UF_PLACE',
76 'UF_PHONE'
77 ];
78 $res = \CIBlockSection::GetList($orderBy, $filter, false, $selectFields );
79 while ($arMeeting = $res->GetNext())
80 {
81 $meetingRoomList[] = [
82 'ID' => $arMeeting['ID'],
83 'NAME' => $arMeeting['~NAME'],
84 'DESCRIPTION' => $arMeeting['~DESCRIPTION'],
85 'UF_PLACE' => $arMeeting['UF_PLACE'],
86 'UF_PHONE' => $arMeeting['UF_PHONE'],
87 'URL' => str_replace(
88 ['#id#', '#ID#'],
89 $arMeeting['ID'],
90 $pathToMR
91 )
92 ];
93 }
94 }
95 }
96 self::$meetingRoomList = $meetingRoomList;
97 }
98
99 return $meetingRoomList;
100 }
101
108 public static function getMeetingRoomById($params)
109 {
110 if (!Loader::includeModule('iblock'))
111 {
112 return false;
113 }
114
115 if ((int)$params['RMiblockId'] > 0 && \CIBlock::GetPermission($params['RMiblockId']) >= 'R')
116 {
117 $filter = [
118 'IBLOCK_ID' => $params['RMiblockId'],
119 'ACTIVE' => 'Y',
120 'ID' => $params['id']
121 ];
122 $selectFields = ['NAME'];
123 $res = \CIBlockSection::GetList([], $filter, false, $selectFields);
124 if ($meeting = $res->GetNext())
125 {
126 return $meeting;
127 }
128 }
129
130 if ((int)$params['VMiblockId'] > 0 && \CIBlock::GetPermission($params['VMiblockId']) >= 'R')
131 {
132 $filter = [
133 'IBLOCK_ID' => $params['VMiblockId'],
134 'ACTIVE' => 'Y'
135 ];
136 $selectFields = [
137 'ID',
138 'NAME',
139 'DESCRIPTION',
140 'IBLOCK_ID'
141 ];
142 $res = \CIBlockSection::GetList([], $filter, false, $selectFields);
143 if ($meeting = $res->GetNext())
144 {
145 return [
146 'ID' => $params['VMiblockId'],
147 'NAME' => $meeting['NAME'],
148 'DESCRIPTION' => $meeting['DESCRIPTION'],
149 ];
150 }
151 }
152
153 return false;
154 }
155
162 public static function reserveMeetingRoom(array $params)
163 {
164 if (!Loader::includeModule('iblock'))
165 {
166 return false;
167 }
168
169 $tst = MakeTimeStamp($params['dateTo']);
170 if (date('H:i', $tst) === '00:00')
171 {
172 $params['dateTo'] = \CIBlockFormatProperties::DateFormat(
173 \CCalendar::DFormat(true),
174 $tst + (23 * 60 + 59) * 60
175 );
176 }
177
178 $settings = \CCalendar::GetSettings(['request' => false]);
179 $params['RMiblockId'] = $settings['rm_iblock_id'];
180
181 $check = self::checkMeetingRoom($params);
182 if ($check !== true)
183 {
184 return $check;
185 }
186
187 $fields = [
188 'IBLOCK_ID' => $params['RMiblockId'],
189 'IBLOCK_SECTION_ID' => $params['mrid'],
190 'NAME' => $params['name'],
191 'DATE_ACTIVE_FROM' => $params['dateFrom'],
192 'DATE_ACTIVE_TO' => $params['dateTo'],
193 'CREATED_BY' => \CCalendar::GetCurUserId(),
194 'DETAIL_TEXT' => $params['description'],
195 'PROPERTY_VALUES' => [
196 'UF_PERSONS' => $params['persons'],
197 'PERIOD_TYPE' => 'NONE'
198 ],
199 'ACTIVE' => 'Y'
200 ];
201
202 $iBlockElem= new \CIBlockElement;
203 $id = $iBlockElem->Add($fields);
204
205 // Hack: reserve meeting calendar based on old calendar's cache
206 $cache = new CPHPCache;
207 $cache->CleanDir('event_calendar/');
208 $cache->CleanDir('event_calendar/events/');
209 $cache->CleanDir('event_calendar/events/'.$params['RMiblockId']);
210
211 return (int)$id;
212 }
213
218 public static function releaseMeetingRoom(array $params): void
219 {
220 if (!Loader::includeModule('iblock'))
221 {
222 return;
223 }
224
225 $settings = \CCalendar::GetSettings(['request' => false]);
226 $params['RMiblockId'] = $settings['rm_iblock_id'];
227
228 $filter = [
229 'ID' => $params['mrevid'],
230 'IBLOCK_ID' => $params['RMiblockId'],
231 'IBLOCK_SECTION_ID' => $params['mrid'],
232 'SECTION_ID' => [$params['mrid']]
233 ];
234
235 $res = \CIBlockElement::GetList([], $filter, false, false, ['ID']);
236 if ($res->Fetch())
237 {
238 $iBlockElem = new \CIBlockElement;
239 $iBlockElem::Delete($params['mrevid']);
240 }
241
242 // Hack: reserve meeting calendar based on old calendar's cache
243 $cache = new CPHPCache;
244 $cache->CleanDir('event_calendar/');
245 $cache->CleanDir('event_calendar/events/');
246 $cache->CleanDir('event_calendar/events/'.$params['RMiblockId']);
247 }
248
255 public static function getAccessibilityForMeetingRoom(array $params): array
256 {
257 if (!Loader::includeModule('iblock'))
258 {
259 return [];
260 }
261
262 $allowReserveMeeting =
263 $params['allowReserveMeeting'] ?? self::$allowReserveMeeting
264 ;
265 $settings = \CCalendar::GetSettings(['request' => false]);
266 $RMiblockId = $settings['rm_iblock_id'];
267 $curEventId = $params['curEventId'] ?? false;
268 $result = [];
269 $offset = \CCalendar::GetOffset();
270
271 if ($allowReserveMeeting)
272 {
273 $select = [
274 'ID',
275 'NAME',
276 'IBLOCK_SECTION_ID',
277 'IBLOCK_ID',
278 'ACTIVE_FROM',
279 'ACTIVE_TO'
280 ];
281 $filter = [
282 'IBLOCK_ID' => $RMiblockId,
283 'SECTION_ID' => $params['id'],
284 'INCLUDE_SUBSECTIONS' => 'Y',
285 'ACTIVE' => 'Y',
286 'CHECK_PERMISSIONS' => 'N',
287 '>=DATE_ACTIVE_TO' => $params['from'],
288 '<=DATE_ACTIVE_FROM' => $params['to']
289 ];
290 if ((int)$curEventId > 0)
291 {
292 $filter['!ID'] = (int)$curEventId;
293 }
294
295 $rsElement = \CIBlockElement::GetList(['ACTIVE_FROM' => 'ASC'], $filter, false, false, $select);
296 while($iBlockElem = $rsElement->GetNextElement())
297 {
298 $item = $iBlockElem->GetFields();
299 $item['DISPLAY_ACTIVE_FROM'] = \CIBlockFormatProperties::DateFormat(
300 \CCalendar::DFormat(true), MakeTimeStamp($item['ACTIVE_FROM'])
301 );
302 $item['DISPLAY_ACTIVE_TO'] = \CIBlockFormatProperties::DateFormat(
303 \CCalendar::DFormat(true), MakeTimeStamp($item['ACTIVE_TO'])
304 );
305
306 $result[] = [
307 'ID' => (int)$item['ID'],
308 'NAME' => $item['~NAME'],
309 'DT_FROM' => \CCalendar::CutZeroTime($item['DISPLAY_ACTIVE_FROM']),
310 'DT_TO' => \CCalendar::CutZeroTime($item['DISPLAY_ACTIVE_TO']),
311 'DT_FROM_TS' => (\CCalendar::Timestamp($item['DISPLAY_ACTIVE_FROM']) - $offset) * 1000,
312 'DT_TO_TS' => (\CCalendar::Timestamp($item['DISPLAY_ACTIVE_TO']) - $offset) * 1000
313 ];
314 }
315 }
316
317 return $result;
318 }
319
326 public static function checkMeetingRoom($params)
327 {
328 if (!Loader::includeModule('iblock'))
329 {
330 return false;
331 }
332
333 $fromDateTime = MakeTimeStamp($params['dateFrom']);
334 $toDateTime = MakeTimeStamp($params['dateTo']);
335 $filter = [
336 'ACTIVE' => 'Y',
337 'IBLOCK_ID' => $params['RMiblockId'],
338 'SECTION_ID' => $params['mrid'],
339 '<DATE_ACTIVE_FROM' => $params['dateTo'],
340 '>DATE_ACTIVE_TO' => $params['dateFrom'],
341 'PROPERTY_PERIOD_TYPE' => 'NONE',
342 ];
343
344 if ($params['mrevid_old'] > 0)
345 {
346 $filter['!=ID'] = $params['mrevid_old'];
347 }
348
349 $dbElements = \CIBlockElement::GetList(
350 ['DATE_ACTIVE_FROM' => 'ASC'],
351 $filter,
352 false,
353 false,
354 ['ID']
355 );
356 if ($elements = $dbElements->GetNext())
357 {
358 return 'reserved';
359 }
360
361 include_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/components/bitrix/intranet.reserve_meeting/init.php');
362 $periodicElements = __IRM_SearchPeriodic($fromDateTime, $toDateTime, $params['RMiblockId'], $params['mrid']);
363
364 foreach ($periodicElements as $element)
365 {
366 if (!$params['mrevid_old'] || (int)$element['ID'] !== (int)$params['mrevid_old'])
367 {
368 return 'reserved';
369 }
370 }
371
372 return true;
373 }
374}