Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
locationajax.php
1<?php
2
4
15use CCalendar;
16
17Loc::loadMessages(__FILE__);
18
20{
21 public const TYPE = 'location';
22
30 public function createRoomAction(): array
31 {
32 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
33 {
34 return [];
35 }
36
37 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
38 $accessController = new TypeAccessController(CCalendar::GetUserId());
39 if (
40 !$accessController->check(ActionDictionary::ACTION_TYPE_EDIT, $typeModel, [])
42 )
43 {
44 $this->addError(new \Bitrix\Main\Error(Loc::getMessage('EC_ACCESS_DENIED')));
45 return [];
46 }
47
48 $builder = new \Bitrix\Calendar\Core\Builders\Rooms\RoomBuilderFromRequest($this->getRequest());
49 $manager =
50 Rooms\Manager::createInstanceWithRoom($builder->build())
51 ->createRoom()
52 ->saveAccess()
53 ->clearCache()
54 ->eventHandler('OnAfterCalendarRoomCreate')
55 ->addPullEvent('create_room')
56 ;
57
58 if ($manager->getError())
59 {
60 $this->addError(
61 $manager->getError()
62 );
63 }
64
65 return $manager->prepareResponseData();
66 }
67
75 public function updateRoomAction(): array
76 {
77 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
78 {
79 return [];
80 }
81
82 $sectionId = (int)$this->getRequest()->getPost('id');
83 $section = \CCalendarSect::GetById($sectionId);
84 $sectionModel = SectionModel::createFromArray($section);
85 $accessController = new SectionAccessController(CCalendar::GetUserId());
86 if (
87 !$accessController->check(ActionDictionary::ACTION_SECTION_EDIT, $sectionModel, [])
89 )
90 {
91 $this->addError(new \Bitrix\Main\Error(Loc::getMessage('EC_ACCESS_DENIED')));
92 return [];
93 }
94
95 $builder = new \Bitrix\Calendar\Core\Builders\Rooms\RoomBuilderFromRequest($this->getRequest());
96 $manager =
97 Rooms\Manager::createInstanceWithRoom($builder->build())
98 ->updateRoom()
99 ->saveAccess()
100 ->clearCache()
101 ->eventHandler('OnAfterCalendarRoomUpdate')
102 ->addPullEvent('update_room')
103 ;
104
105 if ($manager->getError())
106 {
107 $this->addError(
108 $manager->getError()
109 );
110 }
111
112 return $manager->prepareResponseData();
113 }
114
122 public function deleteRoomAction(): array
123 {
124 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
125 {
126 return [];
127 }
128
129 $sectionId = (int)$this->getRequest()->getPost('id');
130 $section = \CCalendarSect::GetById($sectionId);
131 $sectionModel = SectionModel::createFromArray($section);
132 $accessController = new SectionAccessController(CCalendar::GetUserId());
133 if (
134 !$accessController->check(ActionDictionary::ACTION_SECTION_EDIT, $sectionModel, [])
136 )
137 {
138 $this->addError(new \Bitrix\Main\Error(Loc::getMessage('EC_ACCESS_DENIED')));
139 return [];
140 }
141
142 $builder = new \Bitrix\Calendar\Core\Builders\Rooms\RoomBuilderFromRequest($this->getRequest());
143 $manager =
144 Rooms\Manager::createInstanceWithRoom($builder->build())
145 ->deleteRoom()
146 ->pullDeleteEvents()
147 ->deleteEmptyEvents()
148 ->deleteLocationFromEvents()
149 ->cleanAccessTable()
150 ->clearCache()
151 ->eventHandler('OnAfterCalendarRoomDelete')
152 ->addPullEvent('delete_room')
153 ;
154
155 if ($manager->getError())
156 {
157 $this->addError(
158 $manager->getError()
159 );
160 }
161
162 return $manager->prepareResponseData();
163 }
164
172 public function getRoomsManagerDataAction(): ?array
173 {
174 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
175 {
176 return [];
177 }
178
179 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
180 $accessController = new TypeAccessController(CCalendar::GetUserId());
181 if (!$accessController->check(ActionDictionary::ACTION_TYPE_VIEW, $typeModel, []))
182 {
183 $this->addError(new \Bitrix\Main\Error(Loc::getMessage('EC_ACCESS_DENIED')));
184 return [];
185 }
186
187 return Rooms\Manager::prepareRoomManagerData();
188 }
189
197 public function getRoomsListAction(): array
198 {
199 $result = [];
200 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
201 {
202 return $result;
203 }
204
205 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
206 $accessController = new TypeAccessController(CCalendar::GetUserId());
207 if (!$accessController->check(ActionDictionary::ACTION_TYPE_VIEW, $typeModel, []))
208 {
209 $this->addError(new \Bitrix\Main\Error(Loc::getMessage('EC_ACCESS_DENIED')));
210 return $result;
211 }
212
213 $result['rooms'] = Rooms\Manager::getRoomsList();
214
215 return $result;
216 }
217
222 public function getLocationAccessibilityAction(): array
223 {
224 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
225 {
226 return [];
227 }
228
229 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
230 $accessController = new TypeAccessController(CCalendar::GetUserId());
231 if (!$accessController->check(ActionDictionary::ACTION_TYPE_VIEW, $typeModel, []))
232 {
233 return [];
234 }
235
236 $request = $this->getRequest();
237
238 return
239 Rooms\AccessibilityManager::createInstance()
240 ->setLocationList($request->getPost('locationList'))
241 ->setDatesRange($request->getPost('datesRange'))
242 ->getLocationAccessibility()
243 ;
244 }
245
249 public function hideSettingsHintLocationAction(): void
250 {
251 $request = $this->getRequest();
252 $value = ($request->getPost('value') === 'true');
253
254 \CUserOptions::SetOption(
255 'calendar',
256 'hideSettingsHintLocation',
257 $value
258 );
259 }
260
261 public function cancelBookingAction(): ?array
262 {
263 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
264 {
265 return [];
266 }
267
268 $request = $this->getRequest();
269
270 $params['recursion_mode'] = $request->getPost('recursion_mode');
271 $params['parent_event_id'] = (int)$request->getPost('parent_event_id');
272 $params['section_id'] = (int)$request->getPost('section_id');
273 $params['current_event_date_from'] = $request->getPost('current_event_date_from');
274 $params['current_event_date_to'] = $request->getPost('current_event_date_to');
275 $params['owner_id'] = (int)$request->getPost('owner_id');
276
278 $sectionModel =
279 SectionModel::createFromId($params['section_id'])
280 ->setType(Dictionary::CALENDAR_TYPE['location'])
281 ;
282 $accessController = new SectionAccessController(CCalendar::GetUserId());
283 if (!$accessController->check(ActionDictionary::ACTION_SECTION_ACCESS, $sectionModel, []))
284 {
285 $this->addError(new \Bitrix\Main\Error(Loc::getMessage('EC_ACCESS_DENIED')));
286 return [];
287 }
288
289 $manager =
290 Rooms\Manager::createInstance()
291 ->cancelBooking($params)
292 ;
293
294 if ($manager->getError())
295 {
296 $this->addError(
297 $manager->getError()
298 );
299 }
300
301 return [];
302 }
303
304 public function createCategoryAction(): array
305 {
306 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
307 {
308 return [];
309 }
310
311 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
312 $accessController = new TypeAccessController(CCalendar::GetUserId());
313 if (
314 !$accessController->check(ActionDictionary::ACTION_TYPE_EDIT, $typeModel, [])
316 )
317 {
318 $this->addError(new \Bitrix\Main\Error(Loc::getMessage('EC_ACCESS_DENIED')));
319 return [];
320 }
321
322 $builder = new \Bitrix\Calendar\Core\Builders\Rooms\Categories\CategoryBuilderFromRequest($this->getRequest());
323 $manager =
324 Rooms\Categories\Manager::createInstance($builder->build())
325 ->createCategory()
326 ->clearCache()
327 ->addPullEvent('create_category')
328 ;
329
330 if ($manager->getError())
331 {
332 $this->addError(
333 $manager->getError()
334 );
335 }
336
337 return Rooms\Categories\Manager::getCategoryList();
338 }
339
340 public function updateCategoryAction(): array
341 {
342 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
343 {
344 return [];
345 }
346
347 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
348 $accessController = new TypeAccessController(CCalendar::GetUserId());
349 if (
350 !$accessController->check(ActionDictionary::ACTION_TYPE_EDIT, $typeModel, [])
352 )
353 {
354 $this->addError(new \Bitrix\Main\Error(Loc::getMessage('EC_ACCESS_DENIED')));
355 return [];
356 }
357
358 $builder = new \Bitrix\Calendar\Core\Builders\Rooms\Categories\CategoryBuilderFromRequest($this->getRequest());
359 $manager =
360 Rooms\Categories\Manager::createInstance($builder->build())
361 ->updateCategory()
362 ->clearCache()
363 ->addPullEvent('update_category')
364 ;
365
366 if ($manager->getError())
367 {
368 $this->addError(
369 $manager->getError()
370 );
371 }
372
373 return Rooms\Categories\Manager::getCategoryList();
374 }
375
376 public function deleteCategoryAction(): array
377 {
378 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
379 {
380 return [];
381 }
382
383 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
384 $accessController = new TypeAccessController(CCalendar::GetUserId());
385 if (
386 !$accessController->check(ActionDictionary::ACTION_TYPE_EDIT, $typeModel, [])
388 )
389 {
390 $this->addError(new \Bitrix\Main\Error(Loc::getMessage('EC_ACCESS_DENIED')));
391 return [];
392 }
393
394 $builder = new \Bitrix\Calendar\Core\Builders\Rooms\Categories\CategoryBuilderFromRequest($this->getRequest());
395 $manager =
396 Rooms\Categories\Manager::createInstance($builder->build())
397 ->deleteCategory()
398 ->clearCache()
399 ->addPullEvent('delete_category')
400 ;
401
402 if ($manager->getError())
403 {
404 $this->addError(
405 $manager->getError()
406 );
407 }
408
409 return Rooms\Categories\Manager::getCategoryList();
410 }
411
412 public function getCategoryListAction(): array
413 {
414 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
415 {
416 return [];
417 }
418
419 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
420 $accessController = new TypeAccessController(CCalendar::GetUserId());
421 if (!$accessController->check(ActionDictionary::ACTION_TYPE_VIEW, $typeModel, []))
422 {
423 $this->addError(new \Bitrix\Main\Error(Loc::getMessage('EC_ACCESS_DENIED')));
424 return [];
425 }
426
427 $response = [];
428 $response['categories'] = Rooms\Categories\Manager::getCategoryList();
429
430 return $response;
431 }
432
433 public function getCategoryManagerDataAction(): array
434 {
435 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
436 {
437 return [];
438 }
439
440 $categoryManagerData = [];
441 $categoryManagerData['permissions'] = Rooms\PermissionManager::getAvailableOperations() ?? [];
442 $categoryManagerData['categories'] = Rooms\Categories\Manager::getCategoryList() ?? [];
443
444 return $categoryManagerData;
445 }
446}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29