3namespace Bitrix\Calendar\Rooms;
5use Bitrix\Calendar\Integration\Pull\PushCommand;
6use Bitrix\Main\ArgumentException;
8use Bitrix\Calendar\Internals\AccessTable;
9use Bitrix\Calendar\Internals\EventTable;
10use Bitrix\Calendar\Internals\LocationTable;
11use Bitrix\Calendar\Internals\SectionTable;
12use Bitrix\Main\Localization\Loc;
13use Bitrix\Calendar\UserSettings;
14use Bitrix\Main\Entity\ReferenceField;
15use Bitrix\Main\EventManager;
16use Bitrix\Main\ObjectPropertyException;
17use Bitrix\Main\ORM\Query;
18use Bitrix\Main\SystemException;
19use Bitrix\Main\Text\Emoji;
21Loc::loadMessages(__FILE__);
25 public const TYPE =
'location';
28 private ?
Room $room =
null;
30 private ?
Error $error =
null;
43 return (
new self())->setRoom($room);
94 $this->room->create();
96 if ($this->room->getError())
98 $this->addError($this->room->getError());
117 $this->room->update();
119 if ($this->room->getError())
121 $this->addError($this->room->getError());
140 if (!$this->room->getName())
142 $this->room->setName($this->getRoomName($this->room->getId()));
145 $this->room->delete();
147 if ($this->room->getError())
149 $this->addError($this->room->getError());
163 $roomQuery = LocationTable::query()
165 'LOCATION_ID' =>
'ID',
170 'NAME' =>
'SECTION.NAME',
171 'COLOR' =>
'SECTION.COLOR',
172 'OWNER_ID' =>
'SECTION.OWNER_ID',
173 'CAL_TYPE' =>
'SECTION.CAL_TYPE',
175 ->registerRuntimeField(
'SECTION',
178 SectionTable::getEntity(),
179 Query\Join::on(
'ref.ID',
'this.SECTION_ID'),
180 [
'join_type' =>
Query\Join::TYPE_INNER]
183 ->setOrder([
'ID' =>
'ASC'])
189 [$roomsId,
$result] = self::prepareRoomsQueryData($roomQuery);
193 \CCalendarSect::CreateDefault([
194 'type' => self::TYPE,
197 LocationTable::cleanCache();
206 \CCalendarSect::HandlePermission($room);
209 return \CCalendarSect::GetSectionPermission(
$result);
222 $roomQuery = LocationTable::query()
224 'LOCATION_ID' =>
'ID',
229 'NAME' =>
'SECTION.NAME',
230 'COLOR' =>
'SECTION.COLOR',
231 'OWNER_ID' =>
'SECTION.OWNER_ID',
232 'CAL_TYPE' =>
'SECTION.CAL_TYPE',
234 ->where(
'SECTION.ID', $id)
235 ->registerRuntimeField(
'SECTION',
238 SectionTable::getEntity(),
239 Query\Join::on(
'ref.ID',
'this.SECTION_ID'),
240 [
'join_type' =>
Query\Join::TYPE_INNER]
248 [$roomsId,
$result] = self::prepareRoomsQueryData($roomQuery);
253 \CCalendarSect::HandlePermission($room);
256 $applyPermission =
$params[
'checkPermission'] ??
true;
257 if ($applyPermission !==
false)
259 return \CCalendarSect::GetSectionPermission(
$result);
281 !$roomList || empty($roomList[0])
282 || empty($roomList[0][
'NAME'])
284 empty($roomList[0][
'PERM'][
'view_full'])
285 &&
$params[
'checkPermission'] !==
false
292 $createdBy =
$params[
'parentParams'][
'arFields'][
'CREATED_BY']
293 ??
$params[
'parentParams'][
'arFields'][
'MEETING_HOST']
298 'ID' =>
$params[
'room_event_id'] ??
null,
299 'SECTIONS' =>
$params[
'room_id'] ??
null,
300 'DATE_FROM' =>
$params[
'parentParams'][
'arFields'][
'DATE_FROM'] ??
null,
301 'DATE_TO' =>
$params[
'parentParams'][
'arFields'][
'DATE_TO'] ??
null,
302 'TZ_FROM' =>
$params[
'parentParams'][
'arFields'][
'TZ_FROM'] ??
null,
303 'TZ_TO' =>
$params[
'parentParams'][
'arFields'][
'TZ_TO'] ??
null,
304 'SKIP_TIME' =>
$params[
'parentParams'][
'arFields'][
'SKIP_TIME'] ??
null,
305 'RRULE' =>
$params[
'parentParams'][
'arFields'][
'RRULE'] ??
null,
306 'EXDATE' =>
$params[
'parentParams'][
'arFields'][
'EXDATE'] ??
null,
312 $arFields[
'NAME'] = \CCalendar::GetUserName($createdBy);
316 return \CCalendarEvent::Edit([
332 'recursion_mode' =>
$params[
'recursion_mode'] ??
null,
333 'parent_event_id' =>
$params[
'parent_event_id'] ??
null,
334 'section_id' =>
$params[
'section_id'] ??
null,
335 'current_event_date_from' =>
$params[
'current_event_date_from'] ??
null,
336 'current_event_date_to' =>
$params[
'current_event_date_to'] ??
null,
337 'owner_id' =>
$params[
'owner_id'] ??
null,
345 if(
$params[
'recursion_mode'] ===
'all' ||
$params[
'recursion_mode'] ===
'next')
347 $event = \CCalendarEvent::GetById(
$params[
'parent_event_id']);
350 if(
$params[
'recursion_mode'] ===
'all')
352 $params[
'current_event_date_from'] =
$event[
'DATE_FROM'] ??
null;
353 $params[
'current_event_date_to'] =
$event[
'DATE_TO'] ??
null;
357 $result = \CCalendar::SaveEventEx([
358 'recursionEditMode' =>
$params[
'recursion_mode'],
359 'currentEventDateFrom' =>
$params[
'current_event_date_from'],
360 'checkPermission' =>
false,
361 'sendInvitations' =>
false,
362 'userId' =>
$params[
'owner_id'],
364 'ID' =>
$params[
'parent_event_id'],
365 'DATE_FROM' =>
$params[
'current_event_date_from'],
366 'DATE_TO' =>
$params[
'current_event_date_to'],
373 $this->sendCancelBookingNotification(
$params);
377 private function sendCancelBookingNotification(
array $params): void
380 'section_id' =>
$params[
'section_id'],
381 'event_id' =>
$params[
'event_id'],
382 'owner_id' =>
$params[
'owner_id'],
383 'current_event_date_from' =>
$params[
'current_event_date_from'],
384 'recursion_mode' =>
$params[
'recursion_mode'],
387 $section = \CCalendarSect::GetById(
$params[
'section_id']);
388 $userId = \CCalendar::GetCurUserId();
389 $event = \CCalendarEvent::GetById(
$params[
'event_id'],
false);
391 \CCalendarNotify::Send([
392 'eventId' =>
$params[
'event_id'],
393 'mode' =>
'cancel_booking',
394 'location' => $section[
'NAME'] ??
null,
395 'locationId' =>
$params[
'section_id'],
396 'guestId' =>
$params[
'owner_id'],
398 'from' =>
$params[
'current_event_date_from'],
399 'eventName' =>
$event[
'NAME'] ??
null,
400 'recursionMode' =>
$params[
'recursion_mode'],
414 return \CCalendar::DeleteEvent(
415 (
int)(
$params[
'room_event_id'] ??
null),
418 'checkPermissions' =>
false,
419 'markDeleted' =>
false
436 \CCalendarSect::SetClearOperationCache(
true);
437 \CCalendar::clearCache([
441 LocationTable::cleanCache();
456 \CCalendarSect::CleanAccessTable($this->room->getId());
476 $event = EventTable::query()
477 ->setSelect([
'LOCATION'])
487 $parsedLocation = Util::parseLocation(
$location);
488 if ($parsedLocation[
'room_id'] && $parsedLocation[
'room_event_id'])
490 EventTable::update($parsedLocation[
'room_event_id'], [
510 $sectionList = \CCalendar::GetSectionList([
511 'CAL_TYPE' => self::TYPE,
513 'checkPermissions' =>
true,
514 'getPermissions' =>
true,
517 $sectionList = array_merge(
519 \CCalendar::getSectionListAvailableForUser(\CCalendar::GetUserId())
521 $result[
'sections'] = $sectionList;
534 $userId = \CCalendar::GetUserId();
543 $sectionList = \CCalendar::GetSectionList([
544 'CAL_TYPE' => self::TYPE,
546 'ADDITIONAL_IDS' => $followedSectionList,
547 'getPermissions' =>
false,
549 $sectionList = array_merge($sectionList, \CCalendar::getSectionListAvailableForUser(
$userId));
551 $sectionAccessTasks = \CCalendar::GetAccessTasks(
'calendar_section',
'location');
555 'type' => self::TYPE,
559 $defaultSectionAccess = \CCalendarSect::GetDefaultAccess(
564 $result[
'sections'] = $sectionList;
566 'locationAccess' => Util::getLocationAccess(
$userId),
567 'hiddenSections' => $hiddenSections,
568 'type' => self::TYPE,
571 'defaultSectionAccess' => $defaultSectionAccess,
572 'sectionAccessTasks' => $sectionAccessTasks,
573 'showTasks' =>
false,
574 'accessNames' => \CCalendar::GetAccessNames(),
595 $this->room->getId(),
611 $this->room->getCreatedBy(),
613 'ID' => $this->room->getId()
628 private function getRoomName(
int $id): ?string
630 $section = SectionTable::query()
631 ->setSelect([
'NAME'])
636 return $section ? $section[
'NAME'] :
null;
676 $id = $this->room->getId();
678 $locationId =
'calendar_' . $id;
680 $events = EventTable::query()
681 ->setSelect([
'ID',
'PARENT_ID',
'OWNER_ID',
'CREATED_BY',
'LOCATION'])
682 ->whereLike(
'LOCATION', $locationId.
'%')
686 while (
$event = $events->fetch())
690 $guestsId[] =
$event[
'OWNER_ID'];
693 $eventsId[] =
$event[
'ID'];
696 if (!empty($eventsId))
698 EventTable::updateMulti($eventsId, [
'LOCATION' =>
'']);
700 $guestsId = array_unique($guestsId);
701 $userId = \CCalendar::GetCurUserId();
703 foreach ($guestsId as $guestId)
705 \CCalendarNotify::Send([
706 'mode' =>
'delete_location',
709 'guestId' => (
int)$guestId,
731 $events = self::getLocationEventsId($this->room->getId());
733 foreach ($events as
$event)
735 if ($this->room->getCreatedBy())
738 PushCommand::DeleteEvent,
739 $this->room->getCreatedBy(),
758 \CCalendarEvent::DeleteEmpty($this->room->getId());
771 private static function getLocationEventsId(
int $roomId):
array
773 return EventTable::query()
779 ->where(
'SECTION_ID', $roomId)
780 ->where(
'DELETED',
'N')
795 $access = $this->room->getAccess();
796 $id = $this->room->getId();
800 \CCalendarSect::SavePermissions(
807 \CCalendarSect::SavePermissions(
809 \CCalendarSect::GetDefaultAccess(
810 $this->room->getType(),
811 $this->room->getCreatedBy()
829 while ($room =
$query->fetch())
831 $room[
'ID'] = $room[
'SECTION_ID'];
832 unset($room[
'SECTION_ID']);
834 if (!empty($room[
'NAME']))
836 $room[
'NAME'] = Emoji::decode($room[
'NAME']);
838 $roomId = (int)$room[
'ID'];
839 $roomsId[] = $roomId;
855 private static function getRoomsAccess(
array $roomsId,
array $rooms):
array
868 ->whereIn(
'SECT_ID', $roomsId)
872 while (
$access = $accessQuery->fetch())
874 if (!isset($rooms[
$access[
'SECT_ID']][
'ACCESS']))
876 $rooms[
$access[
'SECT_ID']][
'ACCESS'] = [];
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
addPullEvent(PushCommand $event)
static createInstanceWithRoom(Room $room)
deleteLocationFromEvents()
cancelBooking(array $params=[])
static checkRoomName(?string $name)
static getRoomById(int $id, array $params=[])
static prepareRoomManagerData()
static setEventIdForLocation(int $id, ?string $location=null)
static releaseRoom(array $params=[])
static reserveRoom(array $params=[])
static getFollowedSectionIdList($userId=false)
static getHiddenSections($userId=false, $options=[])
static addPullEvent(PushCommand $command, int $userId, array $params=[])
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(!is_array($deviceNotifyCodes)) $access
ExecuteModuleEventEx($arEvent, $arParams=[])
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']