Util::setLocation

  1. Bitrix24 API (v. 23.675.0)
  2. calendar
  3. Util
  4. setLocation
  • Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/lib/rooms/util.php
  • Класс: BitrixCalendarRoomsUtil
  • Вызов: Util::setLocation
static function setLocation($old = '', $new = '', array $params = [])
{
	$params = [
		'bRecreateReserveMeetings' => $params['bRecreateReserveMeetings'] ?? null,
		'dateFrom' => $params['dateFrom'] ?? null,
		'dateTo' => $params['dateTo'] ?? null,
		'name' => $params['name'] ?? null,
		'persons' => $params['persons'] ?? null,
		'attendees' => $params['attendees'] ?? null,
		'parentParams' => $params['parentParams'] ?? null,
		'checkPermission' => $params['checkPermission'] ?? null,
	];

	$tzEnabled = CTimeZone::Enabled();
	if ($tzEnabled)
	{
		CTimeZone::Disable();
	}

	// *** ADD MEETING ROOM ***
	$locOld = self::parseLocation($old);
	$locNew = self::parseLocation($new);
	$res = $locNew['mrid'] ? $locNew['str'] : $new;
	$settings = CCalendar::GetSettings(['request' => false]);
	$RMiblockId = $settings['rm_iblock_id'] ?? null;
	// If not allowed
	if ($RMiblockId && $locOld['mrid'] !== false && $locOld['mrevid'] !== false) // Release MR
	{
		Util::releaseLocation($locOld);
	}

	if ($locNew['mrid'] !== false) // Reserve MR
	{
		$mrevid = false;
		if ($params['bRecreateReserveMeetings'])
		{
			$mrevid = IBlockMeetingRoom::reserveMeetingRoom([
                'RMiblockId' => $RMiblockId,
                'mrid' => $locNew['mrid'],
                'dateFrom' => $params['dateFrom'],
                'dateTo' => $params['dateTo'],
                'name' => $params['name'],
                'description' => Loc::getMessage('EC_RESERVE_FOR_EVENT').': '.$params['name'],
                'persons' => $params['persons'],
                'members' => $params['attendees']
                ]);
		}

		else if($locNew['mrevid'] !== false)
		{
			$mrevid = $locNew['mrevid'];
		}

		$locNew =
			($mrevid && $mrevid !== 'reserved' && $mrevid !== 'expire' && $mrevid > 0)
				? 'ECMR_'.$locNew['mrid'].'_'.$mrevid
				: ''
		;
	}

	// Release room
	if (
		$locOld['room_id'] !== false
		&& $locOld['room_event_id'] !== false
		&& $locNew['room_id'] === false
	)
	{
		Util::releaseLocation($locOld);

		$locNew = $locNew['str'];
	}
	//Reserve room if it hasn't reserved before
	else if($locNew['room_id'] && $locOld['room_id'] === false)
	{
		$roomEventId = Manager::reserveRoom([
			'room_id' => $locNew['room_id'],
			'room_event_id' => false,
			'parentParams' => $params['parentParams']
		]);

		$locNew = $roomEventId ? 'calendar_'.$locNew['room_id'].'_'.$roomEventId : '';
	}
	//Update room event if it has been reserved before
	else if (
		$locNew['room_id']
		&& $locOld['room_id']
		&& $locOld['room_event_id']
	)
	{
		$roomEventId = Manager::reserveRoom([
			'room_id' => $locNew['room_id'],
			'room_event_id' => $locOld['room_event_id'],
			'parentParams' => $params['parentParams'],
			'checkPermission' => $params['checkPermission'],
		]);

		$locNew = $roomEventId ? 'calendar_' . $locNew['room_id'] . '_' . $roomEventId : '';
	}
	//String value for location field
	else
	{
		$locNew = $locNew['str'];
	}

	if ($locNew)
	{
		$res = $locNew;
	}

	if ($tzEnabled)
	{
		CTimeZone::Enable();
	}

	return $res;
}

Добавить комментарий