You are here

public function BookingEvent::formatJson in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Returns event in a format amenable to FullCalendar display or generally sensible JSON.

Parameters

int $style: The visualization style.

string $unit_name: The bookable unit name.

Return value

array The processed event, in JSON ready format.

Overrides BookingEventInterface::formatJson

File

modules/rooms_availability/includes/rooms_availability.booking_event.inc, line 84
Class BookingEvent

Class

BookingEvent
@file Class BookingEvent

Code

public function formatJson($style = ROOMS_AVAILABILITY_ADMIN_STYLE, $unit_name = '') {
  $event = array(
    'id' => $this->id,
    'start' => $this
      ->startYear() . '-' . $this
      ->startMonth('m') . '-' . $this
      ->startDay('d') . 'T13:00:00',
    'end' => $this
      ->endYear() . '-' . $this
      ->endMonth('m') . '-' . $this
      ->endDay('d') . 'T13:00:00',
    'title' => $this->id,
  );

  // Check if we are dealing with a booking.
  if ($this->id > 10 || $this->id < -10) {

    // Get the actual booking id.
    $booking_id = rooms_availability_return_id($this->id);
    $booking = rooms_booking_load($booking_id);
    if ($style == ROOMS_AVAILABILITY_ADMIN_STYLE) {
      $name = isset($booking->name) && !empty($booking->name) ? $booking->name : t('Booking') . ': ' . $booking->booking_id;
      $interval = $this
        ->diff();
      if (strlen($name) > 7 && $interval->d < 1) {
        $event['title'] = substr($name, 0, 6) . '...';
      }
      else {
        $event['title'] = $name;
      }
    }
    elseif ($style == ROOMS_AVAILABILITY_GENERIC_STYLE) {
      $this->id = ROOMS_NOT_AVAILABLE;
      $event['id'] = ROOMS_NOT_AVAILABLE;
    }
  }
  $view_unit_name = array_filter(variable_get('rooms_view_unit_name', array(
    '',
  )));

  // Set the color.
  switch ($this->id) {
    case ROOMS_NOT_AVAILABLE:
      $event['color'] = variable_get('rooms_not_available_color', '#CC2727');
      $event['borderColor'] = variable_get('rooms_not_available_color', '#CC2727');
      $event['title'] = variable_get('rooms_not_available_text', 'N/A');
      break;
    case ROOMS_AVAILABLE:
      $event['color'] = variable_get('rooms_available_color', '#8BA175');
      $event['borderColor'] = '#8BA175';
      $event['title'] = variable_get('rooms_available_text', 'AV');
      break;
    case ROOMS_ON_REQUEST:
      $event['color'] = variable_get('rooms_on_request_color', '#C5C5C5');
      $event['title'] = variable_get('rooms_on_request_text', 'ON-REQ');
      break;
    case $this->id < 0:
      $event['color'] = variable_get('rooms_unconfirmed_booking_color', '#6D8C9C');
      $event['title'] = variable_get('rooms_unconfirmed_booking_text', 'UNCONF');
      break;
    case ROOMS_ANON_BOOKED:
      if ($style == ROOMS_AVAILABILITY_ADMIN_STYLE) {
        $event['color'] = variable_get('rooms_anon_booking_color', '#8C6A5A');
        $event['title'] = variable_get('rooms_anon_booking_text', 'A-B');
      }
      elseif ($style == ROOMS_AVAILABILITY_GENERIC_STYLE) {
        $event['color'] = variable_get('rooms_not_available_color', '#910a1c');
        $event['title'] = variable_get('rooms_not_available_text', 'N/A');
      }
      break;
    default:
      $event['color'] = '#017eba';
      break;
  }
  if (!empty($view_unit_name)) {
    $event['title'] = $unit_name;
  }
  return $event;
}