1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
util.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Rooms;
4
5use Bitrix\Calendar\Access\ActionDictionary;
6use Bitrix\Calendar\Access\Model\TypeModel;
7use Bitrix\Calendar\Access\TypeAccessController;
8use Bitrix\Calendar\Core\Event\Tools\Dictionary;
9use Bitrix\Calendar\Integration\Bitrix24\FeatureDictionary;
10use Bitrix\Main\Access\Exception\UnknownActionException;
11use Bitrix\Main\LoaderException;
12use Bitrix\Main\Localization\Loc;
13use Bitrix\Main\Loader;
14use Bitrix\Main\Text\Emoji;
15use CCalendar;
16use Bitrix\Calendar\Integration\Bitrix24Manager;
17use CExtranet;
18use CTimeZone;
19
20class Util
21{
29 public static function parseLocation($location): array
30 {
31 $res = [
32 'mrid' => false,
33 'mrevid' => false,
34 'room_id' => false,
35 'room_event_id' => false,
36 'str' => $location
37 ];
38
39 if (!$location || is_array($location))
40 {
41 $res['str'] = '';
42
43 return $res;
44 }
45
46 if (is_string($location))
47 {
48 $res['str'] = Emoji::decode($location);
49 }
50
51 if (mb_strlen($location) > 5 && str_starts_with($location, 'ECMR_'))
52 {
53 $parsedLocation = explode('_', $location);
54 if (count($parsedLocation) >= 2)
55 {
56 if ((int)$parsedLocation[1] > 0)
57 {
58 $res['mrid'] = (int)$parsedLocation[1];
59 }
60 if ((int)$parsedLocation[2] > 0)
61 {
62 $res['mrevid'] = (int)$parsedLocation[2];
63 }
64 }
65 }
66 else if (mb_strlen($location) > 9 && str_starts_with($location, 'calendar_'))
67 {
68 $parsedLocation = explode('_', $location);
69 if (count($parsedLocation) >= 2)
70 {
71 if ((int)$parsedLocation[1] > 0)
72 {
73 $res['room_id'] = (int)$parsedLocation[1];
74 }
75 if (isset($parsedLocation[2]) && (int)$parsedLocation[2] > 0)
76 {
77 $res['room_event_id'] = (int)$parsedLocation[2];
78 }
79 }
80 }
81
82 return $res;
83 }
84
92 public static function unParseTextLocation($loc = ''): array
93 {
94 $result = ['NEW' => $loc];
95 if ($loc != '')
96 {
97 $location = self::parseLocation($loc);
98 if ($location['mrid'] === false && $location['room_id'] === false)
99 {
101 $loc_ = mb_strtolower(trim($loc));
102 foreach($MRList as $MR)
103 {
104 if (mb_strtolower(trim($MR['NAME'])) === $loc_)
105 {
106 $result['NEW'] = 'ECMR_'.$MR['ID'];
107 break;
108 }
109 }
110
111 if (Bitrix24Manager::isFeatureEnabled(FeatureDictionary::CALENDAR_LOCATION))
112 {
113 $locationList = Manager::getRoomsList();
114 foreach($locationList as $room)
115 {
116 if (mb_strtolower(trim($room['NAME'])) === $loc_)
117 {
118 $result['NEW'] = 'calendar_'.$room['ID'];
119 }
120 }
121 }
122
123 }
124 }
125
126 return $result;
127 }
128
137 public static function getTextLocation($loc = '')
138 {
139 $result = $loc;
140 if ($loc)
141 {
142 $location = self::parseLocation($loc);
143
144 if ($location['mrid'] === false && $location['room_id'] === false)
145 {
146 return $location['str'];
147 }
148
149 if ($location['room_id'] > 0)
150 {
151 $room = Manager::getRoomById($location['room_id']);
152 return $room ? ($room[0]['NAME'] ?? null) : '';
153 }
154
156 foreach ($MRList as $MR)
157 {
158 if ((int)$MR['ID'] === (int)$location['mrid'])
159 {
160 return $MR['NAME'];
161 }
162 }
163 }
164
165 return Emoji::decode($result);
166 }
167
178 public static function setLocation($old = '', $new = '', array $params = [])
179 {
180 $params = [
181 'bRecreateReserveMeetings' => $params['bRecreateReserveMeetings'] ?? null,
182 'dateFrom' => $params['dateFrom'] ?? null,
183 'dateTo' => $params['dateTo'] ?? null,
184 'name' => $params['name'] ?? null,
185 'persons' => $params['persons'] ?? null,
186 'attendees' => $params['attendees'] ?? null,
187 'parentParams' => $params['parentParams'] ?? null,
188 'checkPermission' => $params['checkPermission'] ?? null,
189 ];
190
191 $tzEnabled = CTimeZone::Enabled();
192 if ($tzEnabled)
193 {
194 CTimeZone::Disable();
195 }
196
197 // *** ADD MEETING ROOM ***
198 $locOld = self::parseLocation($old);
199 $locNew = self::parseLocation($new);
200 $res = $locNew['mrid'] ? $locNew['str'] : $new;
201 $settings = CCalendar::GetSettings(['request' => false]);
202 $RMiblockId = $settings['rm_iblock_id'] ?? null;
203 // If not allowed
204 if ($RMiblockId && $locOld['mrid'] !== false && $locOld['mrevid'] !== false) // Release MR
205 {
206 Util::releaseLocation($locOld);
207 }
208
209 if ($locNew['mrid'] !== false) // Reserve MR
210 {
211 $mrevid = false;
212 if ($params['bRecreateReserveMeetings'])
213 {
215 'RMiblockId' => $RMiblockId,
216 'mrid' => $locNew['mrid'],
217 'dateFrom' => $params['dateFrom'],
218 'dateTo' => $params['dateTo'],
219 'name' => $params['name'],
220 'description' => Loc::getMessage('EC_RESERVE_FOR_EVENT').': '.$params['name'],
221 'persons' => $params['persons'],
222 'members' => $params['attendees']
223 ]);
224 }
225
226 else if($locNew['mrevid'] !== false)
227 {
228 $mrevid = $locNew['mrevid'];
229 }
230
231 $locNew =
232 ($mrevid && $mrevid !== 'reserved' && $mrevid !== 'expire' && $mrevid > 0)
233 ? 'ECMR_' . $locNew['mrid'] . '_' . $mrevid
234 : ''
235 ;
236 }
237 // Release room
238 else if (
239 $locOld['room_id'] !== false
240 && $locOld['room_event_id'] !== false
241 && $locNew['room_id'] === false
242 )
243 {
244 self::releaseLocation($locOld);
245
246 $locNew = $locNew['str'];
247 }
248 //Reserve room if it hasn't reserved before
249 else if($locNew['room_id'] && $locOld['room_id'] === false)
250 {
251 $roomEventId = Manager::reserveRoom([
252 'room_id' => $locNew['room_id'],
253 'room_event_id' => false,
254 'parentParams' => $params['parentParams']
255 ]);
256
257 $locNew = $roomEventId ? 'calendar_'.$locNew['room_id'].'_'.$roomEventId : '';
258 }
259 //Update room event if it has been reserved before
260 else if (
261 $locNew['room_id']
262 && $locOld['room_id']
263 && $locOld['room_event_id']
264 )
265 {
266 $roomEventId = Manager::reserveRoom([
267 'room_id' => $locNew['room_id'],
268 'room_event_id' => $locOld['room_event_id'],
269 'parentParams' => $params['parentParams'],
270 'checkPermission' => $params['checkPermission'],
271 ]);
272
273 $locNew = $roomEventId ? 'calendar_' . $locNew['room_id'] . '_' . $roomEventId : '';
274 }
275 //String value for location field
276 else
277 {
278 $locNew = $locNew['str'];
279 }
280
281 if ($locNew)
282 {
283 $res = $locNew;
284 }
285
286 if ($tzEnabled)
287 {
288 CTimeZone::Enable();
289 }
290
291 return $res;
292 }
293
299 public static function releaseLocation($loc)
300 {
301 $loc = [
302 'room_id' => $loc['room_id'] ?? false,
303 'room_event_id' => $loc['room_event_id'] ?? false,
304 'mrevid' => $loc['mrevid'] ?? false,
305 'mrid' => $loc['mrid'] ?? false,
306 ];
307
308 if ($loc['room_id'] && $loc['room_event_id'] !== false)
309 {
311 'room_id' => $loc['room_id'],
312 'room_event_id' => $loc['room_event_id']
313 ]);
314 }
315
316 // Old reserve meeting based on iblock module
317 if($loc['mrevid'] && $loc['mrid'])
318 {
319 $set = CCalendar::GetSettings(['request' => false]);
320 if ($set['rm_iblock_id'] ?? null)
321 {
323 'mrevid' => $loc['mrevid'],
324 'mrid' => $loc['mrid'],
325 'RMiblockId' => $set['rm_iblock_id']
326 ]);
327 }
328 }
329 }
330
338 public static function getLocationAccess($userId): bool
339 {
340 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
341
342 $access = (new TypeAccessController($userId))->check(ActionDictionary::ACTION_TYPE_EDIT, $typeModel, []);
343
344 if (Loader::includeModule('extranet'))
345 {
346 $access = $access && CExtranet::IsIntranetUser(SITE_ID, $userId);
347 }
348
349 return $access;
350 }
351}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getMeetingRoomList(array $params=[])
Определения iblockmeetingroom.php:20
static reserveMeetingRoom(array $params)
Определения iblockmeetingroom.php:162
static releaseMeetingRoom(array $params)
Определения iblockmeetingroom.php:218
static getRoomsList()
Определения manager.php:161
static getRoomById(int $id, array $params=[])
Определения manager.php:220
static releaseRoom(array $params=[])
Определения manager.php:412
static reserveRoom(array $params=[])
Определения manager.php:274
static setLocation($old='', $new='', array $params=[])
Определения util.php:178
static releaseLocation($loc)
Определения util.php:299
static parseLocation($location)
Определения util.php:29
static unParseTextLocation($loc='')
Определения util.php:92
static getTextLocation($loc='')
Определения util.php:137
static getLocationAccess($userId)
Определения util.php:338
$new
Определения file_edit.php:48
</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
if(!is_array($deviceNotifyCodes)) $access
Определения options.php:174
$settings
Определения product_settings.php:43
</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
const SITE_ID
Определения sonet_set_content_view.php:12