1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
locationajax.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Controller;
4
5use Bitrix\Calendar\Access\ActionDictionary;
6use Bitrix\Calendar\Access\Model\SectionModel;
7use Bitrix\Calendar\Access\Model\TypeModel;
8use Bitrix\Calendar\Access\SectionAccessController;
9use Bitrix\Calendar\Access\TypeAccessController;
10use Bitrix\Calendar\Core\Event\Tools\Dictionary;
11use Bitrix\Calendar\Integration\Pull\PushCommand;
12use Bitrix\Calendar\Rooms;
13use Bitrix\Main\Error;
14use Bitrix\Main\Loader;
15use Bitrix\Main\Localization\Loc;
16use Bitrix\Main\Engine\Controller;
17use CCalendar;
18
19Loc::loadMessages(__FILE__);
20
22{
23 public const TYPE = 'location';
24
32 public function createRoomAction(): array
33 {
34 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
35 {
36 return [];
37 }
38
39 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
40 $accessController = new TypeAccessController(CCalendar::GetUserId());
41 if (
42 !$accessController->check(ActionDictionary::ACTION_TYPE_EDIT, $typeModel, [])
44 )
45 {
46 $this->addError(new Error(Loc::getMessage('EC_ACCESS_DENIED')));
47 return [];
48 }
49
50 $builder = new \Bitrix\Calendar\Core\Builders\Rooms\RoomBuilderFromRequest($this->getRequest());
51 $manager =
53 ->createRoom()
54 ->saveAccess()
55 ->clearCache()
56 ->eventHandler('OnAfterCalendarRoomCreate')
57 ->addPullEvent(PushCommand::CreateRoom)
58 ;
59
60 if ($manager->getError())
61 {
62 $this->addError(
63 $manager->getError()
64 );
65 }
66
67 return $manager->prepareResponseData();
68 }
69
77 public function updateRoomAction(): array
78 {
79 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
80 {
81 return [];
82 }
83
84 $sectionId = (int)$this->getRequest()->getPost('id');
85 $section = \CCalendarSect::GetById($sectionId);
86
87 if (empty($section))
88 {
89 $this->addError(new Error(Loc::getMessage('EC_ROOM_DELETE_ERROR')));
90
91 return [];
92 }
93
94 $sectionModel = SectionModel::createFromArray($section);
95 $accessController = new SectionAccessController(CCalendar::GetUserId());
96 if (
97 !$accessController->check(ActionDictionary::ACTION_SECTION_EDIT, $sectionModel, [])
99 )
100 {
101 $this->addError(new Error(Loc::getMessage('EC_ACCESS_DENIED')));
102 return [];
103 }
104
105 $builder = new \Bitrix\Calendar\Core\Builders\Rooms\RoomBuilderFromRequest($this->getRequest());
106 $manager =
108 ->updateRoom()
109 ->saveAccess()
110 ->clearCache()
111 ->eventHandler('OnAfterCalendarRoomUpdate')
112 ->addPullEvent(PushCommand::UpdateRoom)
113 ;
114
115 if ($manager->getError())
116 {
117 $this->addError(
118 $manager->getError()
119 );
120 }
121
122 return $manager->prepareResponseData();
123 }
124
132 public function deleteRoomAction(): array
133 {
134 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
135 {
136 return [];
137 }
138
139 $sectionId = (int)$this->getRequest()->getPost('id');
140 $section = \CCalendarSect::GetById($sectionId);
141
142 if (empty($section))
143 {
144 $this->addError(new Error(Loc::getMessage('EC_ROOM_DELETE_ERROR')));
145
146 return [];
147 }
148
149 $sectionModel = SectionModel::createFromArray($section);
150 $accessController = new SectionAccessController(CCalendar::GetUserId());
151 if (
152 !$accessController->check(ActionDictionary::ACTION_SECTION_EDIT, $sectionModel, [])
154 )
155 {
156 $this->addError(new Error(Loc::getMessage('EC_ACCESS_DENIED')));
157
158 return [];
159 }
160
161 $builder = new \Bitrix\Calendar\Core\Builders\Rooms\RoomBuilderFromRequest($this->getRequest());
162 $manager =
164 ->deleteRoom()
165 ->pullDeleteEvents()
166 ->deleteEmptyEvents()
167 ->deleteLocationFromEvents()
168 ->cleanAccessTable()
169 ->clearCache()
170 ->eventHandler('OnAfterCalendarRoomDelete')
171 ->addPullEvent(PushCommand::DeleteRoom)
172 ;
173
174 if ($manager->getError())
175 {
176 $this->addError(
177 $manager->getError()
178 );
179 }
180
181 return $manager->prepareResponseData();
182 }
183
192 {
193 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
194 {
195 return [];
196 }
197
198 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
199 $accessController = new TypeAccessController(CCalendar::GetUserId());
200 if (!$accessController->check(ActionDictionary::ACTION_TYPE_VIEW, $typeModel, []))
201 {
202 $this->addError(new Error(Loc::getMessage('EC_ACCESS_DENIED')));
203 return [];
204 }
205
207 }
208
216 public function getRoomsListAction(): array
217 {
218 $result = [];
219 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
220 {
221 return $result;
222 }
223
224 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
225 $accessController = new TypeAccessController(CCalendar::GetUserId());
226 if (!$accessController->check(ActionDictionary::ACTION_TYPE_VIEW, $typeModel, []))
227 {
228 $this->addError(new Error(Loc::getMessage('EC_ACCESS_DENIED')));
229 return $result;
230 }
231
233
234 return $result;
235 }
236
242 {
243 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
244 {
245 return [];
246 }
247
248 if (Loader::includeModule('pull'))
249 {
250 $userId = \CCalendar::GetUserId();
251
252 \CPullWatch::Add($userId, 'calendar-location', true);
253 }
254
255 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
256 $accessController = new TypeAccessController(CCalendar::GetUserId());
257 if (!$accessController->check(ActionDictionary::ACTION_TYPE_VIEW, $typeModel, []))
258 {
259 return [];
260 }
261
262 $request = $this->getRequest();
263
264 return
266 ->setLocationList($request->getPost('locationList'))
267 ->setDatesRange($request->getPost('datesRange'))
268 ->getLocationAccessibility()
269 ;
270 }
271
275 public function hideSettingsHintLocationAction(): void
276 {
277 $request = $this->getRequest();
278 $value = ($request->getPost('value') === 'true');
279
280 \CUserOptions::SetOption(
281 'calendar',
282 'hideSettingsHintLocation',
283 $value
284 );
285 }
286
287 public function cancelBookingAction(): ?array
288 {
289 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
290 {
291 return [];
292 }
293
294 $request = $this->getRequest();
295
296 $params['recursion_mode'] = $request->getPost('recursion_mode');
297 $params['parent_event_id'] = (int)$request->getPost('parent_event_id');
298 $params['section_id'] = (int)$request->getPost('section_id');
299 $params['current_event_date_from'] = $request->getPost('current_event_date_from');
300 $params['current_event_date_to'] = $request->getPost('current_event_date_to');
301 $params['owner_id'] = (int)$request->getPost('owner_id');
302
304 $sectionModel =
305 SectionModel::createFromId($params['section_id'])
306 ->setType(Dictionary::CALENDAR_TYPE['location'])
307 ;
308 $accessController = new SectionAccessController(CCalendar::GetUserId());
309 if (!$accessController->check(ActionDictionary::ACTION_SECTION_ACCESS, $sectionModel, []))
310 {
311 $this->addError(new Error(Loc::getMessage('EC_ACCESS_DENIED')));
312 return [];
313 }
314
315 $manager =
316 Rooms\Manager::createInstance()
317 ->cancelBooking($params)
318 ;
319
320 if ($manager->getError())
321 {
322 $this->addError(
323 $manager->getError()
324 );
325 }
326
327 return [];
328 }
329
330 public function createCategoryAction(): array
331 {
332 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
333 {
334 return [];
335 }
336
337 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
338 $accessController = new TypeAccessController(CCalendar::GetUserId());
339 if (
340 !$accessController->check(ActionDictionary::ACTION_TYPE_EDIT, $typeModel, [])
342 )
343 {
344 $this->addError(new Error(Loc::getMessage('EC_ACCESS_DENIED')));
345 return [];
346 }
347
348 $builder = new \Bitrix\Calendar\Core\Builders\Rooms\Categories\CategoryBuilderFromRequest($this->getRequest());
349 $manager =
351 ->createCategory()
352 ->clearCache()
353 ->addPullEvent(PushCommand::CreateCategory)
354 ;
355
356 if ($manager->getError())
357 {
358 $this->addError(
359 $manager->getError()
360 );
361 }
362
364 }
365
366 public function updateCategoryAction(): array
367 {
368 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
369 {
370 return [];
371 }
372
373 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
374 $accessController = new TypeAccessController(CCalendar::GetUserId());
375 if (
376 !$accessController->check(ActionDictionary::ACTION_TYPE_EDIT, $typeModel, [])
378 )
379 {
380 $this->addError(new Error(Loc::getMessage('EC_ACCESS_DENIED')));
381 return [];
382 }
383
384 $builder = new \Bitrix\Calendar\Core\Builders\Rooms\Categories\CategoryBuilderFromRequest($this->getRequest());
385 $manager =
387 ->updateCategory()
388 ->clearCache()
389 ->addPullEvent(PushCommand::UpdateCategory)
390 ;
391
392 if ($manager->getError())
393 {
394 $this->addError(
395 $manager->getError()
396 );
397 }
398
400 }
401
402 public function deleteCategoryAction(): array
403 {
404 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
405 {
406 return [];
407 }
408
409 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
410 $accessController = new TypeAccessController(CCalendar::GetUserId());
411 if (
412 !$accessController->check(ActionDictionary::ACTION_TYPE_EDIT, $typeModel, [])
414 )
415 {
416 $this->addError(new Error(Loc::getMessage('EC_ACCESS_DENIED')));
417 return [];
418 }
419
420 $builder = new \Bitrix\Calendar\Core\Builders\Rooms\Categories\CategoryBuilderFromRequest($this->getRequest());
421 $manager =
423 ->deleteCategory()
424 ->clearCache()
425 ->addPullEvent(PushCommand::DeleteCategory)
426 ;
427
428 if ($manager->getError())
429 {
430 $this->addError(
431 $manager->getError()
432 );
433 }
434
436 }
437
438 public function getCategoryListAction(): array
439 {
440 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
441 {
442 return [];
443 }
444
445 $typeModel = TypeModel::createFromXmlId(Dictionary::CALENDAR_TYPE['location']);
446 $accessController = new TypeAccessController(CCalendar::GetUserId());
447 if (!$accessController->check(ActionDictionary::ACTION_TYPE_VIEW, $typeModel, []))
448 {
449 $this->addError(new Error(Loc::getMessage('EC_ACCESS_DENIED')));
450 return [];
451 }
452
453 $response = [];
455
456 return $response;
457 }
458
460 {
461 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser())
462 {
463 return [];
464 }
465
466 $categoryManagerData = [];
467 $categoryManagerData['permissions'] = Rooms\PermissionManager::getAvailableOperations() ?? [];
468 $categoryManagerData['categories'] = Rooms\Categories\Manager::getCategoryList() ?? [];
469
470 return $categoryManagerData;
471 }
472}
$accessController
Определения options.php:23
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static createInstance(Category $category)
Определения manager.php:28
static getRoomsList()
Определения manager.php:161
static createInstanceWithRoom(Room $room)
Определения manager.php:41
static prepareRoomManagerData()
Определения manager.php:532
addError(Error $error)
Определения controller.php:1070
Определения error.php:15
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$manager
Определения office365push.php:39
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$response
Определения result.php:21