You are here

function rooms_booking_views_data_alter in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Implements hook_views_data_alter().

File

modules/rooms_booking/views/rooms_booking.views.inc, line 11
Providing extra functionality for the Room UI via views.

Code

function rooms_booking_views_data_alter(&$data) {
  $data['rooms_bookings']['link_booking'] = array(
    'field' => array(
      'title' => t('Link'),
      'help' => t('Provide a link to the booking.'),
      'handler' => 'rooms_booking_handler_link_field',
    ),
  );
  $data['rooms_bookings']['edit_booking'] = array(
    'field' => array(
      'title' => t('Edit Link'),
      'help' => t('Provide a link to the edit form for the booking.'),
      'handler' => 'rooms_booking_handler_edit_link_field',
    ),
  );
  $data['rooms_bookings']['delete_booking'] = array(
    'field' => array(
      'title' => t('Delete Link'),
      'help' => t('Provide a link to delete the booking.'),
      'handler' => 'rooms_booking_handler_delete_link_field',
    ),
  );

  // This content of this field are decided based on the menu structure that
  // follows rooms/booking/%booking_id/op.
  $data['rooms_bookings']['operations'] = array(
    'field' => array(
      'title' => t('Operations links'),
      'help' => t('Display all operations available for this booking.'),
      'handler' => 'rooms_booking_handler_booking_operations_field',
    ),
  );
  $data['rooms_bookings']['start_date'] = array(
    'title' => t('Start Date'),
    'help' => t("A booking's arrival date."),
    'field' => array(
      'float' => TRUE,
      'handler' => 'rooms_booking_handler_date_field',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'handler' => 'rooms_booking_handler_date_filter',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    ),
  );
  $data['rooms_bookings']['end_date'] = array(
    'title' => t('End Date'),
    'help' => t("A booking's departure date."),
    'field' => array(
      'float' => TRUE,
      'handler' => 'rooms_booking_handler_date_field',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'handler' => 'rooms_booking_handler_date_filter',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    ),
  );
  $data['rooms_bookings']['unit_id'] = array(
    'title' => t('Unit'),
    'help' => t('The unit for which this booking was made.'),
    'field' => array(
      'handler' => 'rooms_booking_handler_unit_field',
    ),
    'filter' => array(
      'title' => t('Unit'),
      'handler' => 'rooms_booking_handler_unit_filter',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'relationship' => array(
      'title' => t('Unit ID'),
      'help' => t("Relate this booking to its bookable unit"),
      'handler' => 'views_handler_relationship',
      'base' => 'rooms_units',
      'base field' => 'unit_id',
      'field' => 'unit_id',
      'label' => t('Booking unit'),
    ),
  );
  $data['rooms_bookings']['type']['field'] = array(
    'title' => t('Booking Type'),
    'help' => t('The booking type label.'),
    'handler' => 'rooms_booking_handler_booking_type_field',
  );

  // Expose the uid as a relationship to users.
  $data['rooms_bookings']['uid'] = array(
    'title' => t('Uid'),
    'help' => t("The owner's user ID."),
    'field' => array(
      'handler' => 'views_handler_field_user',
      'click sortable' => TRUE,
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_user_uid',
      'name field' => 'name',
    ),
    'filter' => array(
      'title' => t('Name'),
      'handler' => 'views_handler_filter_user_name',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'relationship' => array(
      'title' => t('Owner'),
      'help' => t("Relate this booking to its owner's user account"),
      'handler' => 'views_handler_relationship',
      'base' => 'users',
      'base field' => 'uid',
      'field' => 'uid',
      'label' => t('Booking owner'),
    ),
  );
  $data['rooms_bookings']['booking_status']['field']['handler'] = 'rooms_booking_handler_field_booking_status';
  $data['rooms_bookings']['booking_status']['filter']['handler'] = 'rooms_booking_handler_filter_booking_status';
  $data['rooms_bookings']['nights'] = array(
    'title' => t('Nights'),
    'help' => t("Booking's number of nights."),
    'field' => array(
      'float' => TRUE,
      'handler' => 'rooms_booking_handler_nights_field',
      'click sortable' => TRUE,
    ),
  );
}