You are here

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

Called to add the field to a query.

Overrides views_handler_field::query

File

modules/rooms_booking/views/rooms_booking_handler_nights_field.inc, line 17

Class

rooms_booking_handler_nights_field
@file

Code

function query() {
  $this
    ->ensure_my_table();
  $this->field_alias = $this->table_alias . '_nights';
  $alias = $this->field_alias;
  $counter = 0;
  while (!empty($this->query->fields[$this->field_alias])) {
    $this->field_alias = $alias . '_' . ++$counter;
  }

  // Add the field.
  $params = $this->options['group_type'] != 'group' ? array(
    'function' => $this->options['group_type'],
  ) : array();
  $this->query
    ->add_field(NULL, '(TO_DAYS(' . $this->table_alias . '.end_date) - TO_DAYS(' . $this->table_alias . '.start_date))', $this->field_alias, $params);
  $this
    ->add_additional_fields();
}